Mixture model MCMC hyperparameters
Source:R/hb_mcmc_mixture_hyperparameters.R
hb_mcmc_mixture_hyperparameters.Rd
Run a simple model separately on each historical study
control group and compute hyperparameters for hb_mcmc_mixture()
.
Usage
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
)
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
m_omega
ands_omega
for the mixture model.- response
Character of length 1, name of the column in
data
with the response/outcome variable.data[[response]]
must be a continuous variable, and it should be the change from baseline of a clinical endpoint of interest, as opposed to just the raw response. Treatment differences are computed directly from this scale, please supply change from baseline unless you are absolutely certain that treatment differences computed directly from this quantity are clinically meaningful.- study
Character of length 1, name of the column in
data
with the study ID.- study_reference
Atomic of length 1, element of the
study
column that indicates the current study. (The other studies are historical studies.)- group
Character of length 1, name of the column in
data
with the group ID.- group_reference
Atomic of length 1, element of the
group
column that indicates the control group. (The other groups may be treatment groups.)- patient
Character of length 1, name of the column in
data
with the patient ID.- m_mu
Numeric of length 1, prior mean of the mean
mu
in the simple model.- s_mu
Numeric of length 1, prior standard deviation of the mean
mu
in the simple model.- s_sigma
Numeric of length 1, uniform prior upper bound of the residual standard deviation
sigma
in the simple model.- m_omega_current
Numeric with length 1,
m_omega
value of the current study. Inserted as the final component of them_omega
column in the output.- s_omega_current
Numeric with length 1,
s_omega
value of the current study. Inserted as the final component of thes_omega
column in the output.- 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,
TRUE
to suppress R console output.
Value
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()
.
Details
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.
See also
Other mcmc:
hb_convergence()
,
hb_mcmc_hierarchical()
,
hb_mcmc_independent()
,
hb_mcmc_mixture()
,
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)
#> # A tibble: 5 × 4
#> study study_index m_omega s_omega
#> <chr> <int> <dbl> <dbl>
#> 1 study1 1 -0.395 0.114
#> 2 study2 2 1.26 0.181
#> 3 study3 3 0.692 0.180
#> 4 study4 4 0.875 0.0958
#> 5 study5 5 0 30
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
)
#> # A tibble: 50 × 19
#> alpha `beta[1]` `beta[2]` `delta[1]` `delta[2]` `omega[1]` `omega[2]`
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 -1.09 0.0248 0.837 0.274 0.0111 -1.09 1.06
#> 2 -1.08 0.0336 0.830 0.282 0.0145 -1.08 1.12
#> 3 -1.06 0.0179 0.836 0.288 0.0257 -1.06 1.31
#> 4 -1.07 0.0319 0.828 0.288 0.0165 -1.07 1.37
#> 5 -1.06 0.0228 0.831 0.257 0.0155 -1.06 1.30
#> 6 -1.08 0.0339 0.824 0.268 0.00188 -1.08 1.31
#> 7 -1.06 0.0345 0.834 0.283 -0.000123 -1.06 1.17
#> 8 -1.06 0.0344 0.832 0.291 0.00559 -1.06 1.55
#> 9 -1.10 0.0379 0.837 0.284 0.0101 -1.10 1.13
#> 10 -1.07 0.0271 0.837 0.271 0.00946 -1.07 1.27
#> # ℹ 40 more rows
#> # ℹ 12 more variables: `omega[3]` <dbl>, `omega[4]` <dbl>, `omega[5]` <dbl>,
#> # `post_p[1]` <dbl>, `post_p[2]` <dbl>, `post_p[3]` <dbl>, `post_p[4]` <dbl>,
#> # `post_p[5]` <dbl>, sigma <dbl>, .chain <int>, .iteration <int>, .draw <int>