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_posterior3(object, posterior, pars = "par_B0", iters = NULL, option = 1)

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 string or 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, 2, or 3). Controls parallelization: 1 = non-parallel, 2 = parallel across chains, 3 = parallel across chains and iterations. Default is 1.

Value

A data.frame with columns: chain (integer), iter (integer), id (integer index of parameter element), output (character parameter name), and value (numeric).