vcov_decomp: Decompose the posterior of a variance-covariance node

View source: R/vcov_decomp.R

vcov_decompR Documentation

Decompose the posterior of a variance-covariance node

Description

For each posterior sample, extract the standard deviation and correlation components of a monitored node representing a variance-covariance matrix.

Usage

vcov_decomp(
  post,
  param,
  sigma_base_name = "sigma",
  rho_base_name = "rho",
  invert = FALSE,
  check = TRUE,
  auto_escape = TRUE
)

Arguments

post

A mcmc.list object.

param

A vector of regular expressions specifying the nodes to match for plotting. Must match only one base node name in post, and that node must store samples from a matrix within the model. See match_params() and vignette("pattern-matching") for more details.

sigma_base_name

Base node name to assign to the standard deviation vector component? Defaults to "sigma", which becomes "sigma[1]", "sigma[2]", etc. in the output.

rho_base_name

Same as sigma_base_name, but for the correlation matrix component.

invert

Take the inverse of the matrix node matched by param prior to performing the calculations? This would be necessary if the matrix node was expressed as a precision matrix as used in the BUGS language. Triggers a call to base::solve().

check

Perform checks sequentially that the matrix node is (a) square, (b) symmetrical, and (c) positive definite before proceeding with the calculations? If set to FALSE, unexpected output may be returned or other errors related to items a, b, and c may be triggered - this is not advised, though may be required if wishing to set invert = TRUE.

auto_escape

Automatically escape "[" and "]" characters for pattern matching? See match_params() for details.

Value

A mcmc.list object.

Examples

# load example mcmc.list
data(cjs)

# "SIG" is a covariance matrix node
SIG_decomp = vcov_decomp(cjs, "SIG")

# extract the posterior mean correlation matrix, and reformat
array_format(post_summ(SIG_decomp, "rho")["mean",])

postpack documentation built on Dec. 28, 2022, 1:23 a.m.