Skip to contents

The quantities a trace plot is read for, computed rather than drawn. For each chain and each iteration \(t\) the cumulative statistics of the draws so far are reported: the running mean \(m_t = t^{-1}\sum_{s \le t} x_s\), and the running sample quantiles of \(x_1, \ldots, x_t\) at probs. A chain that has converged shows these settling to horizontal lines; a chain that has not shows them still drifting. Comparing the lines across chains is the visual form of the between-chain comparison Gelman–Rubin makes numerically.

Usage

Baytrace(chains, probs = c(0.025, 0.5, 0.975))

Arguments

chains

Numeric vector (a single chain) or matrix whose columns are chains and whose rows are iterations.

probs

Numeric vector of probabilities in [0, 1] at which the running bands are reported.

Value

Named list with running_mean (one numeric vector per chain), bands (per chain, a list of one numeric vector per probability), probs, n_chains, n_iter, final_mean, method.

Details

The running quantiles are the cumulative quantiles coda::cumuplot draws, computed with the type-7 definition that is the default of quantile, so that both arms and coda agree.

The statistics are cumulative and unsmoothed: nothing is thinned, no burn-in is discarded, and the first few iterations are reported as they are even though a quantile of one or two draws is nearly meaningless.

Mirrors morie.fn.baytrace on the Python side.

References

Plummer M, Best N, Cowles K & Vines K (2006). CODA: convergence diagnosis and output analysis for MCMC. R News 6(1), 7–11.

Examples

set.seed(2)
Baytrace(matrix(rnorm(200), ncol = 2))$final_mean
#> [1] -0.03069816  0.02921465