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.
Arguments
- designmat
The design matrix of the fixed effects.
- outcome
The response variable. Must be numeric.
- group
Character vector containing the group variable.
- subjid
Character vector containing the subjects IDs.
- visit
Character vector containing the visit variable.
- method
A
method
object as generated bymethod_bayes()
.- quiet
Specify whether the stan sampling log should be printed to the console.
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
: astanfit
object.
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 inverse-Wishart priors for the covariance matrices. 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 and using as starting values the REML parameter estimates estimated at point 1.
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.