hbl_mcmc_hierarchical {historicalborrowlong} | R Documentation |
Longitudinal hierarchical MCMC
Description
Run the longitudinal hierarchical model with MCMC.
Usage
hbl_mcmc_hierarchical(
data,
response = "response",
study = "study",
study_reference = max(data[[study]]),
group = "group",
group_reference = min(data[[group]]),
patient = "patient",
rep = "rep",
rep_reference = min(data[[rep]]),
covariates = grep("^covariate", colnames(data), value = TRUE),
constraint = FALSE,
s_delta = 30,
s_beta = 30,
s_sigma = 30,
s_lambda = 1,
s_mu = 30,
s_tau = 30,
covariance_current = "unstructured",
covariance_historical = "unstructured",
control = list(max_treedepth = 17, adapt_delta = 0.99),
...
)
Arguments
data |
Tidy data frame with one row per patient per rep, indicator columns for the response variable, study, group, patient, rep, and covariates. All columns must be atomic vectors (e.g. not lists). |
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 |
rep |
Character of length 1,
name of the column in |
rep_reference |
Atomic of length 1,
element of the |
covariates |
Character vector of column names
in Each baseline covariate column must truly be a baseline covariate: elements must be equal for all time points within each patient (after the steps in the "Data processing" section). In other words, covariates must not be time-varying. A large number of covariates, or a large number of levels in a categorical covariate, can severely slow down the computation. Please consider carefully if you really need to include such complicated baseline covariates. |
constraint |
Logical of length 1, whether to pool all study arms at baseline (first rep). Appropriate when the response is the raw response (as opposed to change from baseline) and the first rep (i.e. time point) is prior to treatment. |
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_lambda |
shape parameter of the LKJ priors on the unstructured correlation matrices. |
s_mu |
Numeric of length 1,
prior standard deviation of |
s_tau |
Numeric of length 1,
Upper bound on |
covariance_current |
Character of length 1,
covariance structure of the current study.
Possible values are |
covariance_historical |
Same as |
control |
A named
In addition, algorithm HMC (called 'static HMC' in Stan) and NUTS share the following parameters:
For algorithm NUTS, we can also set:
For algorithm HMC, we can also set:
For
|
... |
Other optional parameters:
Deprecated:
|
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.
Data processing
Before running the MCMC, dataset is pre-processed. This includes expanding the rows of the data so every rep of every patient gets an explicit row. So if your original data has irregular rep IDs, e.g. unscheduled visits in a clinical trial that few patients attend, please remove them before the analysis. Only the most common rep IDs should be added.
After expanding the rows, the function fills in missing values for every column except the response. That includes covariates. Missing covariate values are filled in, first with last observation carried forward, then with last observation carried backward. If there are still missing values after this process, the program throws an informative error.
See Also
Other mcmc:
hbl_convergence()
,
hbl_mcmc_independent()
,
hbl_mcmc_pool()
,
hbl_mcmc_sge()
Examples
if (!identical(Sys.getenv("HBL_TEST", unset = ""), "")) {
set.seed(0)
data <- hbl_sim_hierarchical(
n_study = 2,
n_group = 2,
n_patient = 5,
n_rep = 3
)$data
tmp <- utils::capture.output(
suppressWarnings(
mcmc <- hbl_mcmc_hierarchical(
data,
chains = 1,
warmup = 10,
iter = 20,
seed = 0
)
)
)
mcmc
}