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.
MCMCpstr(object, params = "all", excl = NULL, ISB = TRUE,
func = mean, type = "summary")Object containing MCMC output. See DETAILS below.
Character string (or vector of character strings) denoting parameters to be returned in output.
Default 'all' returns all parameters in output.
Character string (or vector of character strings) denoting parameters to exclude. Used in conjunction with params argument to select parameters of interest.
Ignore Square Brackets (ISB). Logical specifying whether square brackets should be ignored in the params and excl arguments. If TRUE, square brackets are ignored - input from params and excl are otherwise matched exactly. If FALSE, square brackets are not ignored - input from params and excl are matched using grep, which can take arguments in regular expression format. This allows partial names to be used when specifying parameters of interest.
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'.
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.
object argument can be a stanfit object (rstan package), a stanreg object (rstanarm package), a brmsfit object (brms package), an mcmc.list object (coda 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.
# NOT RUN {
#Load data
data(MCMC_data)
MCMCpstr(MCMC_data, func = function(x) quantile(x, probs = c(0.01, 0.99)))
# }
Run the code above in your browser using DataLab