MCMC fit object
MCMC fit object
Super class
BayesRTMB::RTMB_Fit_Base -> mcmc_fit
Public fields
modelAn `RTMB_Model` object used for estimation.
fitPosterior draws for model parameters.
random_fitPosterior draws for random effects.
transform_fitPosterior draws for transformed parameters.
transform_dimsDimension information for transformed parameters.
generate_fitPosterior draws for generated quantities.
generate_dimsDimension information for generated quantities.
epsStep size used by the sampler.
acceptAcceptance statistics from sampling.
treedepthTree depth used in HMC/NUTS sampling.
laplaceLogical; whether Laplace approximation was used.
posterior_meanPosterior mean estimates.
log_mlNumeric value storing the calculated log marginal likelihood from bridge sampling.
null_fitAn
MCMC_Fitobject containing the fitted null model. This is automatically cached when calculating a Bayes factor using a target string.
Methods
Method new()
Create a new `MCMC_Fit` object.
Usage
MCMC_Fit$new(
model,
fit,
random_fit,
eps,
accept,
treedepth,
laplace,
posterior_mean
)Arguments
modelAn `RTMB_Model` object used for estimation.
fitPosterior draws for model parameters.
random_fitPosterior draws for random effects, if available.
epsStep size used by the sampler.
acceptAcceptance statistics from sampling.
treedepthTree depth used in HMC/NUTS sampling.
laplaceLogical; whether Laplace approximation was used.
posterior_meanPosterior mean estimates.
Method print()
Print a brief summary of the fitted object.
Method draws()
Extract posterior draws for selected parameters.
Usage
MCMC_Fit$draws(
pars = NULL,
chains = NULL,
best_chains = NULL,
inc_random = FALSE,
inc_transform = TRUE,
inc_generate = TRUE
)Arguments
parsCharacter or numeric vector specifying the names or indices of parameters to extract. If NULL, all available parameters are extracted.
chainsNumeric vector specifying the chains to extract. If NULL, draws from all chains are returned.
best_chainsInteger; number of best chains to retain based on mean log-posterior (lp).
inc_randomLogical; whether to include random effects in the output. Default is FALSE.
inc_transformLogical; whether to include transformed parameters in the output. Default is TRUE.
inc_generateLogical; whether to include generated quantities in the output. Default is TRUE.
Method summary()
Summarize posterior draws.
Usage
MCMC_Fit$summary(
pars = NULL,
chains = NULL,
best_chains = NULL,
max_rows = 10,
digits = 2,
inc_random = FALSE,
inc_transform = TRUE,
inc_generate = TRUE
)Arguments
parsCharacter or numeric vector specifying the names or indices of parameters to summarize. If NULL, all available parameters are summarized.
chainsNumeric vector specifying the chains to extract. If NULL, draws from all chains are used.
best_chainsInteger; number of best chains to retain based on mean log-posterior (lp).
max_rowsInteger; maximum number of rows to print in the summary table. Default is 10.
digitsInteger; number of decimal places to print. Default is 2.
inc_randomLogical; whether to include random effects in the summary. Default is FALSE.
inc_transformLogical; whether to include transformed parameters in the summary. Default is TRUE.
inc_generateLogical; whether to include generated quantities in the summary. Default is TRUE.
Method log_prob()
Evaluate log-probability values.
Method bridgesampling()
Estimate the marginal likelihood by bridge sampling.
Arguments
methodCharacter; the method to use for bridge sampling (e.g., "warp3", "normal"). Default is "warp3".
use_neffLogical; whether to use the effective sample size (ESS) to adjust for autocorrelation. Default is TRUE.
seedInteger; random seed for reproducibility. Default is NULL.
max_iterInteger; maximum number of iterations for the estimation algorithm. Default is 100.
Method bayes_factor()
Calculate the Bayes Factor against a null model or another fit object.
Arguments
null_modelEither a character string specifying the null target (e.g., "rho ~ uniform(-1, 1)") or another MCMC_Fit object.
bs_methodCharacter; the method to use for bridge sampling ("normal" or "warp3"). Default is "normal".
error_thresholdNumeric; threshold for the approximate error warning. Default is 0.2.
...Additional arguments passed to the sample() method when fitting a null model (e.g.,
chains = 4,sampling = 4000).
Method generated_quantities()
Compute generated quantities from posterior draws.
Method resolve_switching()
Resolve label switching in posterior draws.
Usage
MCMC_Fit$resolve_switching(
target,
linked = NULL,
overwrite = TRUE,
scalar_fns = list()
)Arguments
targetCharacter string specifying the target variable to base the relabeling on.
linkedCharacter vector of variable names to be relabeled in the same order as the target. Default is NULL.
overwriteLogical; whether to overwrite the stored draws in the current object. Default is TRUE.
scalar_fnsA named list of functions to apply to scalar variables for relabeling. Default is an empty list.