hb_mcmc_mixture {historicalborrow} | R Documentation |
Mixture model MCMC
Description
Run the mixture model with MCMC.
Usage
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
)
Arguments
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, |
Details
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.
Value
A tidy data frame of parameter samples from the
posterior distribution. Columns .chain
, .iteration
,
and .draw
have the meanings documented in the
posterior
package.
See Also
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture_hyperparameters()
,
hb_mcmc_pool()
Examples
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
)