MCMCpstr: Summarize and extract posterior chains from MCMC output while...

View source: R/MCMCpstr.R

MCMCpstrR Documentation

Summarize and extract posterior chains from MCMC output while preserving parameter structure

Description

Extract summary information and posterior chains from MCMC output (specific function specified) for specific parameters of interest while preserving original parameter structure (i.e., scalar, vector, matrix, array). Function outputs a list with calculated values or posterior chains for each specified parameter.

Usage

MCMCpstr(
  object,
  params = "all",
  excl = NULL,
  ISB = TRUE,
  exact = TRUE,
  func = mean,
  type = "summary"
)

Arguments

object

Object containing MCMC output. See DETAILS below.

params

Character string (or vector of character strings) denoting parameters to be returned in output.

Default 'all' returns all parameters in output.

excl

Character string (or vector of character strings) denoting parameters to exclude. Used in conjunction with params argument to select parameters of interest.

ISB

Ignore Square Brackets (ISB). Logical specifying whether square brackets should be ignored in the params and excl arguments. If TRUE, square brackets are ignored. If FALSE, square brackets are not ignored. This allows partial names to be used when specifying parameters of interest. Use exact argument to specify whether input from params and excl arguments should be matched exactly.

exact

Logical specifying whether input from params and excl arguments should be matched exactly (after ignoring square brackets if ISB = FALSE). If TRUE, input from params and excl are matched exactly (after taking ISB argument into account). If FALSE, input from params and excl are matched using regular expression format (after taking ISB argument into account).

func

Function to be performed on MCMC output. When output of specified function is greater than length 1, an extra dimension is added. For instance, output of length 3 for a parameter with dimensions 2x2 results in a 2x2x3 output. Functions that produce output with dimensionality greater than 1 are not permitted. func is ignored when type = 'chains'.

type

Character string specifying whether to return summary information (calculated based on func argument) or posterior chains. Valid options are 'summary' and 'chains'. When type = 'chains', the 'func' argument is ignored. When type = 'chains', posterior chains are concatenated and stored in the last dimension in the array for each element (parameter) of the list.

Details

object argument can be a stanfit object (rstan package), a CmdStanMCMC object (cmdstanr package), a stanreg object (rstanarm package), a brmsfit object (brms package), an mcmc.list object (coda and rjags packages), mcmc object (coda and nimble packages), list object (nimble package), an R2jags model object (R2jags package), a jagsUI model object (jagsUI package), or a matrix containing MCMC chains (each column representing MCMC output for a single parameter, rows representing iterations in the chain). The function automatically detects the object type and proceeds accordingly.

Examples

#Load data
data(MCMC_data)

MCMCpstr(MCMC_data, func = function(x) quantile(x, probs = c(0.01, 0.99)))


MCMCvis documentation built on Oct. 18, 2023, 1:10 a.m.