
Obtain samples from the posterior distribution of reported quantities
Source:R/get-posterior.R
get_posterior.RdWhen 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.
Arguments
- object
A
listobject. The AD (automatic differentiation) object created usingTMB::MakeADFun, containing the model structure and report function.- posterior
An
rstanobject created using thetmbstanfunction, containing MCMC samples from the posterior distribution.- pars
A
charactervector. 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. IfNULL(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
characterstring. The output format: "df" for data frame (default) or "array" for array format.
Value
Depends on type argument:
- type = "df"
A
data.framewith columns: parameter (character), index (integer), chain (integer), iteration (integer), and value (numeric).- type = "array"
A named
listof arrays, one per parameter, with dimensions \[chain, iteration, parameter dimensions\].- type = other
A nested
liststructure: chains > parameters > iterations.