post_summ: Obtain posterior summaries and diagnostics of specific nodes

View source: R/post_summ.R

post_summR Documentation

Obtain posterior summaries and diagnostics of specific nodes

Description

Allows rapid calculation of summaries and diagnostics from specific nodes stored in mcmc.list objects.

Usage

post_summ(
  post,
  params,
  digits = NULL,
  probs = c(0.5, 0.025, 0.975),
  Rhat = FALSE,
  neff = FALSE,
  mcse = FALSE,
  by_chain = FALSE,
  auto_escape = TRUE
)

Arguments

post

A mcmc.list object.

params

A vector of regular expressions specifying the nodes to match for summarization. Accepts multi-element vectors to match more than one node at a time. See match_params() and vignette("pattern-matching") for more details.

digits

Control rounding of summaries. Passed to base::round() and defaults to NULL, which produces no rounding.

probs

Posterior quantiles to calculate. Passed to stats::quantile(). Defaults to probs = c(0.5, 0.025, 0.975) (i.e., median and equal-tailed 95 percent credible interval).

Rhat

Calculate the Rhat convergence diagnostic using coda::gelman.diag()? Fair warning: this can take a bit of time to run on many nodes/samples.

neff

Calculate the number of effective MCMC samples using coda::effectiveSize()? Fair warning: this can take a bit of time to run on many nodes/samples.

mcse

Calculate the Monte Carlo standard error for the posterior mean and reported quantiles using the mcmcse::mcse() and mcmcse::mcse.q() functions (batch means method with batch size automatically calculated)? Fair warning: this can take a bit of time to run on many nodes/samples.

by_chain

Calculate posterior summaries for each chain rather than for the aggregate across chains? Defaults to FALSE. The arguments Rhat, neff, and mcse are ignored if by_chain = TRUE and a warning will be returned.

auto_escape

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

Value

A matrix object with summary statistics as rows and nodes as columns. If by_chain = TRUE, an array with chain-specific summaries as the third dimension is returned instead.

See Also

match_params(), coda::gelman.diag(), coda::effectiveSize(), mcmcse::mcse(), mcmcse::mcse.q()

Examples

# load example mcmc.list
data(cjs)

# calculate posterior summaries for the "p" nodes
# ("p[1]" doesn't exist in model)
post_summ(cjs, "p")

# do this by chain
post_summ(cjs, "p", by_chain = TRUE)

# calculate Rhat and Neff diagnostic summaries as well
# multiple node names too
post_summ(cjs, c("b0", "p"), Rhat = TRUE, neff = TRUE)

# calculate Monte Carlo SE for mean and quantiles, with rounding
post_summ(cjs, "p", mcse = TRUE, digits = 3)

# summarize different quantiles: median and central 80%
post_summ(cjs, "p", probs = c(0.5, 0.1, 0.9))

bstaton1/codaTools documentation built on Jan. 1, 2023, 12:17 p.m.