Skip to contents

Discards 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.

Usage

get_model_rep_from_mcmc(rtmb_obj, mcmc_obj, what, n_cores)

Arguments

rtmb_obj

An RTMB ADFun object with a $report() method, as returned by RTMB::MakeADFun.

mcmc_obj

An adnuts or SparseNUTS posterior 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::REPORT inside SPoRC_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
)
} # }