Skip to contents

Stored MCMC draws contain the fitted model parameters. Derived report quantities such as B0, spawning_biomass_y, or M_a are evaluated for each draw by this function.

Usage

get_posterior(
  object,
  posterior,
  pars = "B0",
  iters = NULL,
  option = 2L,
  type = "df"
)

Arguments

object

An optimized RTMB objective with a callable report() function.

posterior

A posterior object supported by SparseNUTS::extract_samples(), including the object returned by as_tmbfit for an sbt_fit with stored MCMC draws.

pars

A character vector. The names of derived quantities to extract from the model report (e.g., "B0", "M_a"). Default is "B0".

iters

An integer. The number of posterior iterations to extract. If NULL (default), all available iterations are extracted.

option

Integer parallelization mode: 1 evaluates sequentially and 2 uses a PSOCK cluster across chains.

type

Character output format. "df" returns a long data frame, "array" returns one array per report quantity, and any other value returns the underlying nested chain list.

Value

Depends on type argument:

type = "df"

A data.frame with columns: parameter (character), index (integer), chain (integer), iteration (integer), and value (numeric).

type = "array"

A named list of arrays, one per parameter, with dimensions \[chain, iteration, parameter dimensions\].

type = other

A nested list structure: chains > parameters > iterations.

Details

Parallel mode registers a doParallel backend for its PSOCK cluster. The cluster is stopped on exit, but any backend that was registered before the call is not restored.