Title: | Non-Longitudinal Bayesian Historical Borrowing Models |
---|---|
Description: | Historical borrowing in clinical trials can improve precision and operating characteristics. This package supports a hierarchical model and a mixture model to borrow historical control data from other studies to better characterize the control response of the current study. It also quantifies the amount of borrowing through benchmark models (independent and pooled). Some of the methods are discussed by Viele et al. (2013) <doi:10.1002/pst.1589>. |
Authors: | William Michael Landau [aut, cre] , Albert Man [rev], Eli Lilly and Company [cph] |
Maintainer: | William Michael Landau <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-11-10 06:19:01 UTC |
Source: | CRAN |
Bayesian historical borrowing models for clinical studies.
Check the convergence diagnostics on a model.
hb_convergence(mcmc)
hb_convergence(mcmc)
mcmc |
A wide data frame of posterior samples returned by
|
A data frame of summarized convergence diagnostics.
max_rhat
is the maximum univariate Gelman/Rubin potential scale
reduction factor over all the parameters of the model,
min_ess_bulk
is the minimum bulk effective sample size over the
parameters, and min_ess_tail
is the minimum tail effective
sample size. max_rhat
should be below 1.01, and the ESS metrics
should both be above 100 times the number of MCMC chains. If
any of these conditions are not true, the MCMC did not converge,
and it is recommended to try running the model for more saved
iterations (and if max_rhat
is high, possibly more warmup
iterations).
Other mcmc:
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture()
,
hb_mcmc_mixture_hyperparameters()
,
hb_mcmc_pool()
data <- hb_sim_pool(n_continuous = 2)$data mcmc <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) hb_convergence(mcmc)
data <- hb_sim_pool(n_continuous = 2)$data mcmc <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) hb_convergence(mcmc)
Standardize a tidy input dataset.
hb_data( data, response, study, study_reference, group, group_reference, patient, covariates )
hb_data( data, response, study, study_reference, group, group_reference, patient, covariates )
data |
A tidy data frame or |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
Users do not normally need to call this function. It mainly serves exposes the indexing behavior of studies and group levels to aid in interpreting summary tables.
A standardized tidy data frame with one row per patient and the following columns:
response
: continuous response/outcome variable. (Should be
change from baseline of an outcome of interest.)
study_label
: human-readable label of the study.
study
: integer study index with the max index equal to the
current study (at study_reference
).
group_label
: human-readable group label (e.g. treatment arm name).
group
: integer group index with an index of 1 equal to the control
group (at group_reference
).
patient_label
: original patient ID.
patient
: integer patient index.
covariate_*
: baseline covariate columns.
data <- hb_sim_independent(n_continuous = 1, n_study = 2)$data data <- dplyr::select( data, study, group, patient, response, tidyselect::everything() ) colnames(data) <- c("trial", "arm", "subject", "change", "cov1", "cov2") data$trial <- paste0("trial", data$trial) data$arm <- paste0("arm", data$arm) hb_data( data = data, response = "change", study = "trial", study_reference = "trial1", group = "arm", group_reference = "arm1", patient = "subject", covariates = c("cov1", "cov2") )
data <- hb_sim_independent(n_continuous = 1, n_study = 2)$data data <- dplyr::select( data, study, group, patient, response, tidyselect::everything() ) colnames(data) <- c("trial", "arm", "subject", "change", "cov1", "cov2") data$trial <- paste0("trial", data$trial) data$arm <- paste0("arm", data$arm) hb_data( data = data, response = "change", study = "trial", study_reference = "trial1", group = "arm", group_reference = "arm1", patient = "subject", covariates = c("cov1", "cov2") )
Quantify borrowing with effective sample size (ESS) as cited and explained in the methods vignette at https://wlandau.github.io/historicalborrow/articles/methods.html.
hb_ess( mcmc_pool, mcmc_hierarchical, data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient" )
hb_ess( mcmc_pool, mcmc_hierarchical, data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient" )
mcmc_pool |
A fitted model from |
mcmc_hierarchical |
A fitted model from |
data |
A tidy data frame or |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
A data frame with one row and the following columns:
v0
: posterior predictive variance of the control group mean of a
hypothetical new study given the pooled model.
Calculated as the mean over MCMC samples of 1 / sum(sigma_i ^ 2)
,
where each sigma_i
is the residual standard deviation of
study i
estimated from the pooled model.
v_tau
: posterior predictive variance of a hypothetical
new control group mean under the hierarchical model.
Calculated by averaging over predictive draws,
where each predictive draw is from
rnorm(n = 1, mean = mu_, sd = tau_)
and mu_
and tau_
are the
mu
and tau
components of an MCMC sample.
n
: number of non-missing historical control patients.
weight
: strength of borrowing as a ratio of variances: v0 / v_tau
.
ess
: strength of borrowing as an effective sample size:
n v0 / v_tau
, where n
is the number of non-missing historical
control patients.
Other summary:
hb_summary()
data <- hb_sim_independent(n_continuous = 2)$data data$group <- sprintf("group%s", data$group) data$study <- sprintf("study%s", data$study) pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hierarchical <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hb_ess( mcmc_pool = pool, mcmc_hierarchical = hierarchical, data = data )
data <- hb_sim_independent(n_continuous = 2)$data data$group <- sprintf("group%s", data$group) data$study <- sprintf("study%s", data$study) pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hierarchical <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hb_ess( mcmc_pool = pool, mcmc_hierarchical = hierarchical, data = data )
Run the hierarchical model with MCMC.
hb_mcmc_hierarchical( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_delta = 30, s_beta = 30, s_sigma = 30, s_mu = 30, s_tau = sd(data[[response]], na.rm = TRUE), d_tau = 1, prior_tau = "half_t", n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
hb_mcmc_hierarchical( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_delta = 30, s_beta = 30, s_sigma = 30, s_mu = 30, s_tau = sd(data[[response]], na.rm = TRUE), d_tau = 1, prior_tau = "half_t", n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
s_mu |
Numeric of length 1,
prior standard deviation of |
s_tau |
Non-negative numeric of length 1.
If In the case of |
d_tau |
Positive numeric of length 1. Degrees of freedom of the
Student t prior of In the case of |
prior_tau |
Character string, family of the prior of |
n_chains |
Number of MCMC chains to run. |
n_adapt |
Number of adaptation iterations to run. |
n_warmup |
Number of warmup iterations per chain to run. |
n_iterations |
Number of saved MCMC iterations per chain to run. |
quiet |
Logical of length 1, |
A tidy data frame of parameter samples from the
posterior distribution. Columns .chain
, .iteration
,
and .draw
have the meanings documented in the
posterior
package.
Other mcmc:
hb_convergence()
,
hb_mcmc_independent()
,
hb_mcmc_mixture()
,
hb_mcmc_mixture_hyperparameters()
,
hb_mcmc_pool()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_hierarchical(n_continuous = 2)$data hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_hierarchical(n_continuous = 2)$data hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
Run the independent-study model with MCMC.
hb_mcmc_independent( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_alpha = 30, s_delta = 30, s_beta = 30, s_sigma = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
hb_mcmc_independent( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_alpha = 30, s_delta = 30, s_beta = 30, s_sigma = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
s_alpha |
Numeric of length 1, prior standard deviation
of the study-specific control group mean parameters |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
n_chains |
Number of MCMC chains to run. |
n_adapt |
Number of adaptation iterations to run. |
n_warmup |
Number of warmup iterations per chain to run. |
n_iterations |
Number of saved MCMC iterations per chain to run. |
quiet |
Logical of length 1, |
A tidy data frame of parameter samples from the
posterior distribution. Columns .chain
, .iteration
,
and .draw
have the meanings documented in the
posterior
package.
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_mixture()
,
hb_mcmc_mixture_hyperparameters()
,
hb_mcmc_pool()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
Run the mixture model with MCMC.
hb_mcmc_mixture( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_delta = 30, s_beta = 30, s_sigma = 30, m_omega = c(0, 0), s_omega = c(30, 30), p_omega = 1/length(m_omega), n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
hb_mcmc_mixture( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_delta = 30, s_beta = 30, s_sigma = 30, m_omega = c(0, 0), s_omega = c(30, 30), p_omega = 1/length(m_omega), n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
m_omega |
Numeric with length equal to the number of
supposed studies (but only the current study is in the data).
|
s_omega |
Numeric with length equal to the number of
supposed studies (but only the current study is in the data).
|
p_omega |
Numeric with length equal to the number of
supposed studies (but only the current study is in the data).
|
n_chains |
Number of MCMC chains to run. |
n_adapt |
Number of adaptation iterations to run. |
n_warmup |
Number of warmup iterations per chain to run. |
n_iterations |
Number of saved MCMC iterations per chain to run. |
quiet |
Logical of length 1, |
The study-specific components of the mixture prior are all fixed
in advance. Mixture components are normal distributions
with means in m_omega
and standard deviations in s_omega
.
These vectors are ordered with historical studies first
and the current study last.
These mixture components can be computed using
hb_mcmc_mixture_hyperparameters()
on a full set of data
(all the historical studies and the current study together).
Then the m_omega
and s_omega
columns of the output
can be plugged directly into hb_mcmc_mixture()
.
See the examples for a demonstration.
A tidy data frame of parameter samples from the
posterior distribution. Columns .chain
, .iteration
,
and .draw
have the meanings documented in the
posterior
package.
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture_hyperparameters()
,
hb_mcmc_pool()
data_all_studies <- hb_sim_independent(n_continuous = 2)$data data_all_studies$study <- paste0("study", data_all_studies$study) hyperparameters <- hb_mcmc_mixture_hyperparameters( data = data_all_studies, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) print(hyperparameters) data_current_study <- dplyr::filter(data_all_studies, study == max(study)) hb_mcmc_mixture( data = data_current_study, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", m_omega = hyperparameters$m_omega, # use hyperparams from historical data s_omega = hyperparameters$s_omega, # use hyperparams from historical data p_omega = rep(1 / nrow(hyperparameters), nrow(hyperparameters)), n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 )
data_all_studies <- hb_sim_independent(n_continuous = 2)$data data_all_studies$study <- paste0("study", data_all_studies$study) hyperparameters <- hb_mcmc_mixture_hyperparameters( data = data_all_studies, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) print(hyperparameters) data_current_study <- dplyr::filter(data_all_studies, study == max(study)) hb_mcmc_mixture( data = data_current_study, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", m_omega = hyperparameters$m_omega, # use hyperparams from historical data s_omega = hyperparameters$s_omega, # use hyperparams from historical data p_omega = rep(1 / nrow(hyperparameters), nrow(hyperparameters)), n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 )
Run a simple model separately on each historical study
control group and compute hyperparameters for hb_mcmc_mixture()
.
hb_mcmc_mixture_hyperparameters( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", m_mu = 0, s_mu = 30, s_sigma = 30, m_omega_current = 0, s_omega_current = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
hb_mcmc_mixture_hyperparameters( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", m_mu = 0, s_mu = 30, s_sigma = 30, m_omega_current = 0, s_omega_current = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
m_mu |
Numeric of length 1, prior mean of the mean |
s_mu |
Numeric of length 1, prior standard deviation of the
mean |
s_sigma |
Numeric of length 1, uniform prior upper bound
of the residual standard deviation |
m_omega_current |
Numeric with length 1,
|
s_omega_current |
Numeric with length 1,
|
n_chains |
Number of MCMC chains to run. |
n_adapt |
Number of adaptation iterations to run. |
n_warmup |
Number of warmup iterations per chain to run. |
n_iterations |
Number of saved MCMC iterations per chain to run. |
quiet |
Logical of length 1, |
The model is a simple Bayesian model with a normal likelihood,
an unknown mean mu
, and an unknown standard deviation sigma
.
For each historical study, the posterior mean of mu
becomes
the corresponding component of m_omega
in the output,
and the posterior standard deviation of mu
becomes the corresponding component of s_omega
in the output.
See the examples in this help file for a demonstration.
m_omega
and s_omega
define the components of the mixture prior
in hb_mcmc_mixture()
that act as the contribution of the
historical studies to the model.
A tidy data frame of hyperparameter values for hb_mcmc_mixture()
.
The first several rows are for historical studies, and the last row
is for the current study. Studies/rows are sorted in the order
hb_mcmc_mixture()
sorts them, so you can use columns m_omega
and s_omega
for the same dataset and same values of other arguments
directly in hb_mcmc_mixture()
.
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture()
,
hb_mcmc_pool()
data_all_studies <- hb_sim_independent(n_continuous = 2)$data data_all_studies$study <- paste0("study", data_all_studies$study) hyperparameters <- hb_mcmc_mixture_hyperparameters( data = data_all_studies, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) print(hyperparameters) data_current_study <- dplyr::filter(data_all_studies, study == max(study)) hb_mcmc_mixture( data = data_current_study, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", m_omega = hyperparameters$m_omega, # use hyperparams from historical data s_omega = hyperparameters$s_omega, # use hyperparams from historical data p_omega = rep(1 / nrow(hyperparameters), nrow(hyperparameters)), n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 )
data_all_studies <- hb_sim_independent(n_continuous = 2)$data data_all_studies$study <- paste0("study", data_all_studies$study) hyperparameters <- hb_mcmc_mixture_hyperparameters( data = data_all_studies, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) print(hyperparameters) data_current_study <- dplyr::filter(data_all_studies, study == max(study)) hb_mcmc_mixture( data = data_current_study, response = "response", study = "study", study_reference = "study5", group = "group", group_reference = 1, patient = "patient", m_omega = hyperparameters$m_omega, # use hyperparams from historical data s_omega = hyperparameters$s_omega, # use hyperparams from historical data p_omega = rep(1 / nrow(hyperparameters), nrow(hyperparameters)), n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 )
Run the non-longitudinal pooled model with MCMC.
hb_mcmc_pool( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_alpha = 30, s_delta = 30, s_beta = 30, s_sigma = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
hb_mcmc_pool( data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), s_alpha = 30, s_delta = 30, s_beta = 30, s_sigma = 30, n_chains = 4, n_adapt = 2000, n_warmup = 4000, n_iterations = 20000, quiet = TRUE )
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
s_alpha |
Numeric of length 1, prior standard deviation
of the study-specific control group mean parameters |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
n_chains |
Number of MCMC chains to run. |
n_adapt |
Number of adaptation iterations to run. |
n_warmup |
Number of warmup iterations per chain to run. |
n_iterations |
Number of saved MCMC iterations per chain to run. |
quiet |
Logical of length 1, |
A tidy data frame of parameter samples from the
posterior distribution. Columns .chain
, .iteration
,
and .draw
have the meanings documented in the
posterior
package.
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture()
,
hb_mcmc_mixture_hyperparameters()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_pool(n_continuous = 2)$data hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_pool(n_continuous = 2)$data hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) }
Plot the response from a borrowing model (hierarchical or mixture) against the independent and pooled benchmark models.
hb_plot_borrow(borrow, pool, independent, outcome = c("response", "diff"))
hb_plot_borrow(borrow, pool, independent, outcome = c("response", "diff"))
borrow |
A data frame returned by |
pool |
A data frame returned by |
independent |
A data frame returned by |
outcome |
Character of length 1, either |
A ggplot
object
Other plot:
hb_plot_group()
,
hb_plot_tau()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data mcmc_borrow <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) mcmc_pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) mcmc_independent <- hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) borrow <- hb_summary(mcmc_borrow, data) pool <- hb_summary(mcmc_pool, data) independent <- hb_summary(mcmc_independent, data) hb_plot_borrow( borrow = borrow, pool = pool, independent = independent ) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data mcmc_borrow <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) mcmc_pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) mcmc_independent <- hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) borrow <- hb_summary(mcmc_borrow, data) pool <- hb_summary(mcmc_pool, data) independent <- hb_summary(mcmc_independent, data) hb_plot_borrow( borrow = borrow, pool = pool, independent = independent ) }
Plot the groups against one another for a borrowing model (hierarchical or mixture) and the independent and pooled benchmark models.
hb_plot_group(borrow, pool, independent, outcome = c("response", "diff"))
hb_plot_group(borrow, pool, independent, outcome = c("response", "diff"))
borrow |
A data frame returned by |
pool |
A data frame returned by |
independent |
A data frame returned by |
outcome |
Character of length 1, either |
A ggplot
object
Other plot:
hb_plot_borrow()
,
hb_plot_tau()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data mcmc_borrow <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) mcmc_pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) mcmc_independent <- hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) borrow <- hb_summary(mcmc_borrow, data) pool <- hb_summary(mcmc_pool, data) independent <- hb_summary(mcmc_independent, data) hb_plot_group( borrow = borrow, pool = pool, independent = independent ) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_independent(n_continuous = 2)$data mcmc_borrow <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) mcmc_pool <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) mcmc_independent <- hb_mcmc_independent( data, n_chains = 1, n_adapt = 100, n_warmup = 200, n_iterations = 200 ) borrow <- hb_summary(mcmc_borrow, data) pool <- hb_summary(mcmc_pool, data) independent <- hb_summary(mcmc_independent, data) hb_plot_group( borrow = borrow, pool = pool, independent = independent ) }
Plot the tau parameter of a fitted hierarchical model.
hb_plot_tau(mcmc)
hb_plot_tau(mcmc)
mcmc |
Data frame of posterior samples generated by
|
A ggplot
object
Other plot:
hb_plot_borrow()
,
hb_plot_group()
data <- hb_sim_independent(n_continuous = 2)$data mcmc <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) hb_plot_tau(mcmc = mcmc)
data <- hb_sim_independent(n_continuous = 2)$data mcmc <- hb_mcmc_hierarchical( data, n_chains = 1, n_adapt = 100, n_warmup = 100, n_iterations = 200 ) hb_plot_tau(mcmc = mcmc)
Simulate from the non-longitudinal hierarchical model.
hb_sim_hierarchical( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_delta = 1, s_beta = 1, s_sigma = 1, s_mu = 1, s_tau = 1, d_tau = 4, prior_tau = "half_t", alpha = NULL, delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma), mu = stats::rnorm(n = 1, mean = 0, sd = s_mu), tau = NULL )
hb_sim_hierarchical( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_delta = 1, s_beta = 1, s_sigma = 1, s_mu = 1, s_tau = 1, d_tau = 4, prior_tau = "half_t", alpha = NULL, delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma), mu = stats::rnorm(n = 1, mean = 0, sd = s_mu), tau = NULL )
n_study |
Number of studies to simulate. |
n_group |
Number of groups (e.g. study arms) to simulate per study. |
n_patient |
Number of patients to simulate per study per group. |
n_continuous |
Number of continuous covariates to simulate (all from independent standard normal distributions). |
n_binary |
Number of binary covariates to simulate (all from independent Bernoulli distributions with p = 0.5). |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
s_mu |
Numeric of length 1,
prior standard deviation of |
s_tau |
Non-negative numeric of length 1.
If |
d_tau |
Positive numeric of length 1. Degrees of freedom of the
Student t prior of |
prior_tau |
Character string, family of the prior of |
alpha |
Numeric vector of length 1 for the pooled
and mixture models and length |
delta |
Numeric vector of length |
beta |
Numeric vector of |
sigma |
Numeric vector of |
mu |
Numeric of length 1,
mean of the control group means |
tau |
Numeric of length 1,
standard deviation of the control group means |
A list with the following elements:
data
: tidy long-form dataset with the patient-level data.
one row per patient and indicator columns for the study,
group (e.g. treatment arm), and patient ID. The response
columns is the patient response. The other columns are
baseline covariates. The control group is the one with
the group
column equal to 1, and the current study (non-historical)
is the one with the maximum value of the study
column.
Only the current study has any non-control-group patients,
the historical studies have only the control group.
parameters
: named list of model parameter values.
See the model specification vignette for details.
matrices
: A named list of model matrices.
See the model specification vignette for details.
Other simulate:
hb_sim_independent()
,
hb_sim_mixture()
,
hb_sim_pool()
hb_sim_hierarchical()$data
hb_sim_hierarchical()$data
Simulate from the non-longitudinal independent model.
hb_sim_independent( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_alpha = 1, s_delta = 1, s_beta = 1, s_sigma = 1, alpha = stats::rnorm(n = n_study, mean = 0, sd = s_alpha), delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma) )
hb_sim_independent( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_alpha = 1, s_delta = 1, s_beta = 1, s_sigma = 1, alpha = stats::rnorm(n = n_study, mean = 0, sd = s_alpha), delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma) )
n_study |
Number of studies to simulate. |
n_group |
Number of groups (e.g. study arms) to simulate per study. |
n_patient |
Number of patients to simulate per study per group. |
n_continuous |
Number of continuous covariates to simulate (all from independent standard normal distributions). |
n_binary |
Number of binary covariates to simulate (all from independent Bernoulli distributions with p = 0.5). |
s_alpha |
Numeric of length 1, prior standard deviation
of the study-specific control group mean parameters |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
alpha |
Numeric vector of length 1 for the pooled
and mixture models and length |
delta |
Numeric vector of length |
beta |
Numeric vector of |
sigma |
Numeric vector of |
A list with the following elements:
data
: tidy long-form dataset with the patient-level data.
one row per patient and indicator columns for the study,
group (e.g. treatment arm), and patient ID. The response
columns is the patient response. The other columns are
baseline covariates. The control group is the one with
the group
column equal to 1, and the current study (non-historical)
is the one with the maximum value of the study
column.
Only the current study has any non-control-group patients,
the historical studies have only the control group.
parameters
: named list of model parameter values.
See the model specification vignette for details.
matrices
: A named list of model matrices.
See the model specification vignette for details.
Other simulate:
hb_sim_hierarchical()
,
hb_sim_mixture()
,
hb_sim_pool()
hb_sim_independent()$data
hb_sim_independent()$data
Simulate from the non-longitudinal mixture model.
hb_sim_mixture( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_delta = 1, s_beta = 1, s_sigma = 1, m_omega = 0, s_omega = 1, p_omega = 1/n_study, alpha = omega[pi], delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_continuous + n_binary, mean = 0, sd = s_delta), sigma = stats::runif(n = 1, min = 0, max = s_sigma), pi = sample.int(n = n_study, size = 1, prob = p_omega), omega = stats::rnorm(n = n_study, mean = m_omega, sd = s_omega) )
hb_sim_mixture( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_delta = 1, s_beta = 1, s_sigma = 1, m_omega = 0, s_omega = 1, p_omega = 1/n_study, alpha = omega[pi], delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_continuous + n_binary, mean = 0, sd = s_delta), sigma = stats::runif(n = 1, min = 0, max = s_sigma), pi = sample.int(n = n_study, size = 1, prob = p_omega), omega = stats::rnorm(n = n_study, mean = m_omega, sd = s_omega) )
n_study |
Number of studies to simulate. |
n_group |
Number of groups (e.g. study arms) to simulate per study. |
n_patient |
Number of patients to simulate per study per group. |
n_continuous |
Number of continuous covariates to simulate (all from independent standard normal distributions). |
n_binary |
Number of binary covariates to simulate (all from independent Bernoulli distributions with p = 0.5). |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
m_omega |
Numeric of length 1 or |
s_omega |
Numeric of length 1 or |
p_omega |
Numeric of length |
alpha |
Numeric vector of length 1 for the pooled
and mixture models and length |
delta |
Numeric vector of length |
beta |
Numeric vector of |
sigma |
Numeric vector of |
pi |
Integer of length 1,
index of the mixture component randomly
chosen for |
omega |
Numeric of length |
A list with the following elements:
data
: tidy long-form dataset with the patient-level data.
one row per patient and indicator columns for the study,
group (e.g. treatment arm), and patient ID. The response
columns is the patient response. The other columns are
baseline covariates. The control group is the one with
the group
column equal to 1, and the current study (non-historical)
is the one with the maximum value of the study
column.
Only the current study has any non-control-group patients,
the historical studies have only the control group.
parameters
: named list of model parameter values.
See the model specification vignette for details.
matrices
: A named list of model matrices.
See the model specification vignette for details.
Other simulate:
hb_sim_hierarchical()
,
hb_sim_independent()
,
hb_sim_pool()
hb_sim_mixture()$data
hb_sim_mixture()$data
Simulate from the non-longitudinal pooled model.
hb_sim_pool( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_alpha = 1, s_delta = 1, s_beta = 1, s_sigma = 1, alpha = stats::rnorm(n = 1, mean = 0, sd = s_alpha), delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma) )
hb_sim_pool( n_study = 5, n_group = 3, n_patient = 100, n_continuous = 0, n_binary = 0, s_alpha = 1, s_delta = 1, s_beta = 1, s_sigma = 1, alpha = stats::rnorm(n = 1, mean = 0, sd = s_alpha), delta = stats::rnorm(n = n_group - 1, mean = 0, sd = s_delta), beta = stats::rnorm(n = n_study * (n_continuous + n_binary), mean = 0, sd = s_delta), sigma = stats::runif(n = n_study, min = 0, max = s_sigma) )
n_study |
Number of studies to simulate. |
n_group |
Number of groups (e.g. study arms) to simulate per study. |
n_patient |
Number of patients to simulate per study per group. |
n_continuous |
Number of continuous covariates to simulate (all from independent standard normal distributions). |
n_binary |
Number of binary covariates to simulate (all from independent Bernoulli distributions with p = 0.5). |
s_alpha |
Numeric of length 1, prior standard deviation
of the study-specific control group mean parameters |
s_delta |
Numeric of length 1, prior standard deviation
of the study-by-group effect parameters |
s_beta |
Numeric of length 1, prior standard deviation
of the fixed effects |
s_sigma |
Numeric of length 1, prior upper bound of the residual standard deviations. |
alpha |
Numeric vector of length 1 for the pooled
and mixture models and length |
delta |
Numeric vector of length |
beta |
Numeric vector of |
sigma |
Numeric vector of |
A list with the following elements:
data
: tidy long-form dataset with the patient-level data.
one row per patient and indicator columns for the study,
group (e.g. treatment arm), and patient ID. The response
columns is the patient response. The other columns are
baseline covariates. The control group is the one with
the group
column equal to 1, and the current study (non-historical)
is the one with the maximum value of the study
column.
Only the current study has any non-control-group patients,
the historical studies have only the control group.
parameters
: named list of model parameter values.
See the model specification vignette for details.
matrices
: A named list of model matrices.
See the model specification vignette for details.
Other simulate:
hb_sim_hierarchical()
,
hb_sim_independent()
,
hb_sim_mixture()
hb_sim_pool(n_continuous = 1)$data
hb_sim_pool(n_continuous = 1)$data
Summarize a fitted model in a table.
hb_summary( mcmc, data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), eoi = 0, direction = "<" )
hb_summary( mcmc, data, response = "response", study = "study", study_reference = max(data[[study]]), group = "group", group_reference = min(data[[group]]), patient = "patient", covariates = grep("^covariate", colnames(data), value = TRUE), eoi = 0, direction = "<" )
mcmc |
A wide data frame of posterior samples returned by
|
data |
Tidy data frame with one row per patient,
indicator columns for the response variable,
study, group, and patient,
and covariates. All columns must be atomic vectors
(e.g. not lists). The data for the mixture and simple models
should have just one study,
and the others should have
data from more than one study. The simple model can be used
to get the historical data components of |
response |
Character of length 1,
name of the column in |
study |
Character of length 1,
name of the column in |
study_reference |
Atomic of length 1,
element of the |
group |
Character of length 1,
name of the column in |
group_reference |
Atomic of length 1,
element of the |
patient |
Character of length 1,
name of the column in |
covariates |
Character vector of column names
in |
eoi |
Numeric of length at least 1, vector of effects of interest (EOIs) for critical success factors (CSFs). |
direction |
Character of length |
The hb_summary()
function post-processes the results from
the model. It estimates marginal means of the response,
treatment effect, and other quantities of interest.
A tidy data frame with one row per group (e.g. treatment arm)
and the columns in the following list. Unless otherwise specified,
the quantities are calculated at the group level.
Some are calculated for the current (non-historical) study only,
while others pertain to the combined dataset which includes
all historical studies.
The mixture model is an exception because the data
argument
only includes the current study, so other quantities that include
historical information will need to borrow from an hb_summary()
call on one of the other models.
group
: group label.
data_mean
: observed mean response specific to the current study.
data_sd
: observed standard deviation of the response
specific to the current study.
data_lower
: lower bound of a simple frequentist 95% confidence
interval of the observed mean specific to the current study.
data_upper
: upper bound of a simple frequentist 95% confidence
interval of the observed mean specific to the current study.
data_n
: number of non-missing observations in the combined dataset
with all studies.
data_N
: total number of observations (missing and non-missing)
in the combined dataset with all studies.
data_n_study_*
: number of non-missing observations separately
for each study.
The suffixes of these column names are integer study indexes.
Call dplyr::distinct(hb_data(your_data), study, study_label)
to see which study labels correspond to these integer indexes.
Note: the combined dataset for the mixture model
is just the current study. If all the data_n_study_*
results
across all studies
are desired, then call hb_summary()
on a different model (e.g. pooled).
data_N_study_*
: same as data_n_study_*
except both missing and
non-missing observations are counted (total number of observations).
response_mean
: Estimated posterior mean of the response
from the model specific to the current study.
Typically, the raw response is change from baseline,
in which case response_mean
is estimating change from baseline.
response_sd
: Estimated posterior standard deviation of the mean
response from the model specific to the current study.
response_variance
: Estimated posterior variance of the mean
response from the model specific to the current study.
response_lower
: Lower bound of a 95% posterior interval on the mean
response from the model specific to the current study.
response_upper
: Upper bound of a 95% posterior interval on the mean
response from the model specific to the current study.
response_mean_mcse
: Monte Carlo standard error of response_mean
.
response_sd_mcse
: Monte Carlo standard error of response_sd
.
response_lower_mcse
: Monte Carlo standard error of response_lower
.
response_upper_mcse
: Monte Carlo standard error of response_upper
.
diff_mean
: Estimated treatment effect from the model
specific to the current study.
diff_lower
: Lower bound of a 95% posterior interval on the treatment
effect from the model specific to the current study..
diff_upper
: Upper bound of a 95% posterior interval on the treatment
effect from the model specific to the current study..
diff_mean_mcse
: Monte Carlo standard error of diff_mean
.
diff_lower_mcse
: Monte Carlo standard error of diff_lower
.
diff_upper_mcse
: Monte Carlo standard error of diff_upper
.
P(diff > EOI)
, P(diff < EOI)
: CSF probabilities on the
treatment effect specified with the eoi
and direction
arguments. Specific to the current study.
effect_mean
: Estimated posterior mean of effect size
(treatment difference divided by residual standard deviation).
Specific to the current study.
effect_lower
: Lower bound of a 95% posterior interval of effect size
from the model. Specific to the current study.
effect_upper
: Upper bound of a 95% posterior interval of effect size
from the model. Specific to the current study.
precision_ratio
: For the hierarchical model only,
a model-based mean of the precision ratio. Specific to the current study.
precision_ratio_lower
: For the hierarchical model only, lower bound
of a model-based 95% posterior interval of the precision ratio.
Specific to the current study.
precision_ratio_upper
: For the hierarchical model only, upper bound
of a model-based 95% posterior interval of the precision ratio.
Specific to the current study.
mix_prop_*
: For the mixture model only, posterior mixture proportions
of each of the mixture components. The last one is for the current study
and the first ones are for the historical studies. The suffixes of these
column names are the integer study indexes.
Call dplyr::distinct(hb_data(your_data), study, study_label)
to see which study labels correspond to these integer indexes.
Other summary:
hb_ess()
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_pool(n_continuous = 2)$data data$group <- sprintf("group%s", data$group) mcmc <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hb_summary(mcmc, data) }
if (!identical(Sys.getenv("HB_TEST", unset = ""), "")) { data <- hb_sim_pool(n_continuous = 2)$data data$group <- sprintf("group%s", data$group) mcmc <- hb_mcmc_pool( data, n_chains = 1, n_adapt = 100, n_warmup = 50, n_iterations = 50 ) hb_summary(mcmc, data) }