Extract model report quantities from MCMC posterior samples
get_model_rep_from_mcmc.RdDiscards warmup iterations, collapses all chains into a single matrix of
posterior draws, evaluates the RTMB report function at each draw in
parallel, and returns the requested report components as tidy
data.tables with a posterior_sample index column.
Arguments
- rtmb_obj
An RTMB
ADFunobject with a$report()method, as returned byRTMB::MakeADFun.- mcmc_obj
An
adnutsorSparseNUTSposterior object containing$samples(array[n_iter × n_chain × n_param]) and$warmup(number of warmup iterations to discard).- what
Character vector. Names of components in the model report (i.e., quantities passed to
RTMB::REPORTinsideSPoRC_rtmb) to extract from each posterior draw.- n_cores
Integer. Number of parallel workers to use via
future::multisession.
Value
Named list of data.tables, one per element of what.
Each table is the row-bound result of reshape2::melt applied to
the report component across all post-warmup draws, with an additional
integer column posterior_sample identifying the draw index
(1 to n_iter × n_chain).
Examples
if (FALSE) { # \dontrun{
model_reports <- get_model_rep_from_mcmc(
rtmb_obj, mcmc_obj,
what = c("SSB", "Rec"),
n_cores = 4
)
} # }