Skip to contents

When samples from the posterior distribution are obtained using tmbstan, only the model parameters can be accessed directly from the stanfit object (i.e., derived quantities such as par_B0 or M_a cannot be accessed directly). Accessing derived quantities must be done using this function.

Usage

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

Arguments

object

A list object. The AD (automatic differentiation) object created using TMB::MakeADFun, containing the model structure and report function.

posterior

An rstan object created using the tmbstan function, containing MCMC samples from the posterior distribution.

pars

A character vector. The name(s) of the derived parameter(s) to extract from the model report (e.g., "par_B0", "M_a"). Default is "par_B0".

iters

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

option

An integer (1 or 2). Controls parallelization: 1 = non-parallel processing, 2 = parallel processing across chains. Default is 2.

type

A character string. The output format: "df" for data frame (default) or "array" for array format.

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.