| MCMC_Fit | R Documentation |
MCMC fit object
MCMC fit object
An R6 class storing posterior samples and related information from MCMC estimation.
Bayes factors are computed as ratios of marginal likelihoods estimated by bridge sampling. The comparison model can be constructed by fixing parameters with 'fixed = list(...)', or supplied as an already fitted 'MCMC_Fit' object via 'comparison_fit'. Bayes factors are computed only by marginal-likelihood model comparison.
BayesRTMB::RTMB_Fit_Base -> mcmc_fit
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.
n_leapfrogNumber of leapfrog steps for retained draws.
divergentLogical matrix indicating divergent transitions.
energyHamiltonian energy for retained draws.
metricPer-chain inverse mass matrix used by NUTS.
metric_typeEffective mass matrix adaptation type used by NUTS.
metric_requestedMass matrix adaptation type requested by the user.
metric_effectiveEffective mass matrix adaptation type by chain.
metric_autoAutomatic metric selection details by chain, if used.
metric_initInitial metric source used by NUTS.
metric_adaptationMetric learning mode used during warmup.
nuts_variantNUTS proposal selection variant used for sampling.
warmup_diagnosticsPer-chain warmup diagnostics.
chain_stateFinal unconstrained sampler position for each chain.
sampler_configSampling settings required to continue the chains.
laplaceLogical; whether Laplace approximation was used.
posterior_meanPosterior mean estimates.
log_mlNumeric value storing the calculated log marginal likelihood from bridge sampling.
comparison_fitAn MCMC_Fit object containing the fitted comparison model.
max_treedepthMaximum tree depth requested for NUTS/HMC.
pd_error_countPositive-definite/singularity errors treated as lp = -Inf by chain.
get_point_estimate()Get point estimate for a target parameter.
MCMC_Fit$get_point_estimate(target, chains = NULL, best_chains = NULL)
targetTarget parameter name.
chainsNumeric vector of chains to include. If NULL, all chains are used.
best_chainsInteger; number of best chains to retain based on mean log-posterior.
Matrix, array, vector, or scalar point estimate.
new()Create a new 'MCMC_Fit' object.
MCMC_Fit$new( model, fit, random_fit, eps, accept, treedepth, laplace, posterior_mean, max_treedepth = NULL, pd_error_count = NULL, n_leapfrog = NULL, divergent = NULL, energy = NULL, metric = NULL, metric_type = NULL, metric_init = NULL, metric_requested = NULL, metric_effective = NULL, metric_auto = NULL, metric_adaptation = NULL, nuts_variant = NULL, warmup_diagnostics = NULL, chain_state = NULL, sampler_config = NULL )
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.
max_treedepthMaximum tree depth requested for NUTS/HMC.
pd_error_countPositive-definite/singularity errors treated as 'lp = -Inf' by chain.
n_leapfrogNumber of leapfrog steps for retained draws.
divergentLogical matrix indicating divergent transitions.
energyHamiltonian energy for retained draws.
metricPer-chain inverse mass matrix used by NUTS.
metric_typeEffective mass matrix adaptation type used by NUTS.
metric_initInitial metric source used by NUTS.
metric_requestedMass matrix adaptation type requested by the user.
metric_effectiveEffective mass matrix adaptation type by chain.
metric_autoAutomatic metric selection details by chain, if used.
metric_adaptationMetric learning mode used during warmup.
nuts_variantNUTS proposal selection variant used for sampling.
warmup_diagnosticsPer-chain warmup diagnostics.
chain_stateFinal unconstrained sampler position for each chain.
sampler_configSampling settings required to continue the chains.
print()Print a brief summary of the fitted object.
MCMC_Fit$print(...)
...Additional arguments.
The object itself, invisibly.
continue_sampling()Continue all NUTS chains from their saved final states.
The adapted mass matrix and step size from each chain are reused, so no additional warmup is performed. New posterior draws and diagnostics are appended along the iteration dimension.
MCMC_Fit$continue_sampling(
sampling = 1000,
thin = NULL,
seed = sample.int(1e+06, 1),
max_treedepth = NULL,
parallel = FALSE,
inplace = TRUE,
globals = FALSE,
progress = c("auto", "none", "bar", "message")
)samplingPositive integer; number of additional post-warmup NUTS transitions per chain before thinning. Default is 1000.
thinOptional positive integer thinning interval. 'NULL' reuses the interval from the original sampling run.
seedInteger random seed.
max_treedepthOptional positive integer maximum tree depth. 'NULL' reuses the value from the original sampling run.
parallelLogical; whether to continue chains in parallel.
inplaceLogical; if 'TRUE', append draws to this object. If 'FALSE', return an independently cloned and extended object.
globalsLogical; if 'TRUE', let 'future' discover globals when 'parallel = TRUE'.
progressProgress reporting style: '"auto"', '"none"', '"bar"', or '"message"'.
The extended 'MCMC_Fit' object, invisibly when 'inplace = TRUE'.
draws()Extract posterior draws for selected parameters.
MCMC_Fit$draws( pars = NULL, chains = NULL, best_chains = NULL, inc_random = FALSE, inc_transform = TRUE, inc_generate = TRUE )
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.
Posterior draws.
summary()Summarize posterior draws.
MCMC_Fit$summary( pars = NULL, chains = NULL, best_chains = NULL, max_rows = 10, digits = 2, inc_random = FALSE, inc_transform = TRUE, inc_generate = TRUE )
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.
A summary object.
rhat_summary()Summarize R-hat values.
MCMC_Fit$rhat_summary( pars = NULL, chains = NULL, best_chains = NULL, inc_random = FALSE, inc_transform = TRUE, inc_generate = FALSE, finite = TRUE, ... )
parsCharacter or numeric vector specifying parameters to include.
chainsNumeric vector specifying chains to include.
best_chainsInteger; number of best chains to retain based on mean log-posterior.
inc_randomLogical; whether to include random effects. Default is FALSE.
inc_transformLogical; whether to include transformed parameters. Default is TRUE.
inc_generateLogical; whether to include generated quantities. Default is FALSE.
finiteLogical; whether to drop non-finite or missing R-hat values. Default is TRUE.
...Additional arguments.
A numeric vector of R-hat values with class "rhat_summary".
unconstrain_draws()Transform posterior draws to the unconstrained scale.
MCMC_Fit$unconstrain_draws()
Posterior draws on the unconstrained scale.
log_prob()Evaluate log-probability values.
MCMC_Fit$log_prob(safe = FALSE)
safeLogical; whether to wrap the evaluation in a tryCatch block. Default is FALSE for speed.
Numeric vector of log-probability values.
bridgesampling()Estimate the marginal likelihood by bridge sampling.
MCMC_Fit$bridgesampling( method = "normal", use_neff = TRUE, seed = NULL, max_iter = 100 )
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.
Bridge sampling result.
WAIC()Compute WAIC from pointwise generated log likelihood.
MCMC_Fit$WAIC(...)
...Additional arguments passed to 'draws()', such as 'chains' or 'best_chains'.
A 'waic_BayesRTMB' object.
diagnose()Run basic diagnostics for the MCMC fit.
MCMC_Fit$diagnose(...)
...Additional arguments passed to 'diagnose_mcmc_fit()'.
A 'diagnose_BayesRTMB' object.
bayes_factor()Calculate the Bayes factor by marginal-likelihood model comparison.
MCMC_Fit$bayes_factor( fixed = NULL, comparison_fit = NULL, bs_method = "normal", error_threshold = 0.2, ... )
fixedNamed list of parameter values used to construct the comparison model.
For example, fixed = list(delta = 0) or
fixed = list("b[x]" = 0).
comparison_fitOptional 'MCMC_Fit' object for an already fitted comparison model.
bs_methodCharacter; the method to use for bridge sampling ("normal" or "warp3").
error_thresholdNumeric; threshold for the approximate error warning.
...Additional arguments passed to 'sample()' when fitting the comparison model (e.g., chains = 4, sampling = 4000).
A list of class bayes_factor_rtmb containing Bayes factor results.
transformed_draws()Compute transformed parameters from posterior draws.
MCMC_Fit$transformed_draws(
tran_fn = NULL,
progress = c("auto", "none", "bar", "message"),
tape = c("auto", "none", "force")
)tran_fnA function for transformed parameters.
progressProgress reporting style: '"auto"', '"none"', '"bar"', or '"message"'. '"auto"' and '"bar"' use line-based messages.
tapeDerived-quantity evaluation mode. '"auto"' tries RTMB tape evaluation and falls back to R evaluation on error; '"none"' always uses R evaluation; '"force"' requires tape evaluation and errors if it fails.
Transformed parameter draws.
generated_quantities()Compute generated quantities from posterior draws.
MCMC_Fit$generated_quantities(
code,
progress = c("auto", "none", "bar", "message"),
tape = c("auto", "none", "force")
)codeAn 'rtmb_code({ ... })' or '{ ... }' block containing the logic to be calculated using posterior samples.
progressProgress reporting style: '"auto"', '"none"', '"bar"', or '"message"'. '"auto"' and '"bar"' use line-based messages.
tapeDerived-quantity evaluation mode. '"auto"' tries RTMB tape evaluation and falls back to R evaluation on error; '"none"' always uses R evaluation; '"force"' requires tape evaluation and errors if it fails.
The 'MCMC_Fit' object itself (invisibly). Results are added to the 'generate_fit' field. Existing generated quantities with the same name are replaced.
resolve_switching()Resolve label switching in posterior draws.
MCMC_Fit$resolve_switching( target, linked = NULL, overwrite = TRUE, scalar_fns = list() )
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.
Relabeled draws or updated object.
clone()The objects of this class are cloneable with this method.
MCMC_Fit$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.