fit_mcmc() fits the base imputation model using a Bayesian approach.
This is done through a MCMC method that is implemented in Stan
and is run by using the function rstan::sampling().
The function returns the draws from the posterior distribution of the model parameters
and the stanfit object. Additionally it performs multiple diagnostics checks of the chain
and returns warnings in case of any detected issues.
Usage
fit_mcmc(
outcome_type = c("continuous", "count"),
designmat,
outcome,
outcome_unscaled = NULL,
group,
subjid,
visit,
duration,
method,
scaler = NULL,
quiet = FALSE,
term_names = NULL
)Arguments
- outcome_type
A character string indicating the type of outcome variable.
- designmat
The design matrix of the fixed effects.
- outcome
The response variable. Must be numeric.
- outcome_unscaled
The unscaled response variable. Must be numeric. If omitted,
outcomeis treated as unscaled.- group
Character vector containing the group variable.
- subjid
Character vector containing the subjects IDs.
- visit
Character vector containing the visit variable.
NULLifperiodis used instead.- duration
Numeric vector containing the duration variable.
NULLifperiodis not used.- method
A
methodobject as generated bymethod_bayes().- scaler
A
scalerobject as generated byscalerConstructor(). If omitted, one is created fromoutcomeanddesignmat.- quiet
Specify whether the Stan sampling log should be printed to the console.
- term_names
NULLor the model-matrix column names ofdesignmat, used to name unidentified terms in model error messages.
Value
A named list composed by the following:
samples: a named list containing the draws for each parameter. It corresponds to the output ofextract_draws().fit: astanfitobject.
Details
The Bayesian model assumes a multivariate normal likelihood function and weakly-informative
priors for the model parameters: in particular, uniform priors are assumed for the regression
coefficients and, by default, inverse-Wishart priors for unstructured covariance matrices.
Structured covariances and the LKJ prior use scaled inverse chi-squared priors for the
variances and uniform or LKJ priors for the correlations, see vignette("stat_specs", package = "rbmi").
With init = "mmrm" (the default for a single chain, see control_bayes()) the chain is
initialized using the REML parameter estimates from MMRM as starting values.
The function performs the following steps:
Fit MMRM using a REML approach.
Prepare the input data for the MCMC fit as described in the
data{}block of the Stan file. Seeprepare_stan_data()for details.Run the MCMC according the input arguments, using as starting values the REML parameter estimates estimated at point 1 if
init = "mmrm".Performs diagnostics checks of the MCMC. See
check_mcmc()for details.Extract the draws from the model fit.
The chains perform method$n_samples draws by keeping one every method$burn_between iterations. Additionally
the first method$burn_in iterations are discarded. The total number of iterations will
then be method$burn_in + method$burn_between*method$n_samples.
The purpose of method$burn_in is to ensure that the samples are drawn from the stationary
distribution of the Markov Chain.
The method$burn_between aims to keep the draws uncorrelated each from other.
