Quant Memo
Advanced

MCMC Convergence Diagnostics

A set of checks for whether an MCMC sampler has actually explored the whole posterior distribution or is quietly stuck — because a sampler that hasn't converged produces numbers that look exactly like real output, with nothing obviously wrong about them at a glance.

Prerequisites: MCMC and Metropolis–Hastings, Hamiltonian Monte Carlo and NUTS

An MCMC sampler run for 5,000 iterations produces 5,000 numbers, a clean-looking histogram, and a tidy posterior mean and interval. Nothing about that output looks wrong on its face — but if the sampler got stuck exploring only one corner of the posterior, or never fully escaped its arbitrary starting point, those 5,000 numbers describe the wrong distribution, and nothing in the raw output announces the failure. MCMC convergence diagnostics are the checks that catch this before a wrong posterior gets reported as a real one.

An analogy: touring a museum but only seeing one wing

Imagine sending someone to describe a large museum's entire collection, but they only ever wander through one wing near the entrance, never realizing there are three more wings behind locked-looking (but actually open) doors. Their report of "what's in this museum" will be fluent, detailed, and completely confident — and wrong, because it describes one wing as if it were the whole building. The report itself gives no internal sign of the mistake; you'd only catch it by comparing several independent visitors' reports and noticing they don't agree, or by checking whether any visitor ever actually reached the far wings. MCMC convergence diagnostics are exactly this cross-checking: run several independent "tours" (chains) and see whether they agree with each other and whether each one shows signs of having actually covered the space.

The maths, one symbol at a time

Two of the standard diagnostics:

R^\hat{R} (R-hat, the Gelman-Rubin statistic) compares the variance of a parameter between several independent MCMC chains to the variance within each chain:

R^=between-chain variance+within-chain variancewithin-chain variance\hat{R} = \sqrt{\frac{\text{between-chain variance} + \text{within-chain variance}}{\text{within-chain variance}}}

In words: if all chains have converged to the same true posterior, they should agree with each other about as much as each chain agrees with itself — between-chain and within-chain variance should be similar, giving R^1\hat R \approx 1. If chains are still stuck in different regions (haven't converged), between-chain variance is inflated relative to within-chain variance, pushing R^\hat R noticeably above 1. A common rule of thumb is to distrust results with R^>1.01\hat R > 1.01.

Effective sample size (ESS) accounts for the fact that consecutive MCMC draws are autocorrelated, not independent — 5,000 correlated draws carry less information than 5,000 truly independent draws would. ESS estimates how many independent draws your correlated chain is worth, and a low ESS (say, 50 out of 5,000 raw draws) means your posterior summary is far less precise than the raw iteration count suggests.

Worked example 1: catching a stuck sampler with R-hat

Run 4 independent chains of 2,000 iterations each to estimate a posterior mean. Chain means come out as 1.2,1.3,3.8,3.91.2, 1.3, 3.8, 3.9 — two chains clustered near 1.25, two clustered near 3.85, clearly stuck in different regions and never mixing. Computing R^\hat R for this parameter gives a value well above 1.01, perhaps R^1.8\hat R \approx 1.8, flagging the problem immediately. A single chain run alone (say, just the first one, hovering near 1.25) would have looked perfectly clean in isolation — smooth trace plot, stable running mean — with nothing to reveal that an entirely different, equally plausible region near 3.85 was never explored. Only the multi-chain comparison exposes the failure.

Worked example 2: low effective sample size despite many iterations

A chain of 10,000 raw MCMC draws has high autocorrelation — draw tt and draw t+1t+1 are nearly identical, and it takes roughly 100 iterations before the chain has moved to a genuinely different, uncorrelated part of the posterior. The effective sample size comes out to roughly 10,000/100=10010{,}000 / 100 = 100. A posterior mean and standard error computed naively from the raw 10,000 draws will understate the true Monte Carlo error by roughly 100/10,0000.1\sqrt{100/10{,}000} \approx 0.1-fold — a tenfold overstatement of precision, because the calculation implicitly assumed 10,000 independent pieces of information when there were really only about 100.

Path explorer
13055time →
end (bold path) 100.38spread of ends 58.966 independent paths, same settings

Picture several of the simulated paths in the explorer above as independent MCMC chains: if their long-run behavior looks systematically different from each other rather than settling into the same pattern, that's the same signature R-hat is built to detect.

iteration 2 chains here 2 chains stuck here
Two pairs of chains that never mix — each pair looks perfectly stable on its own, but comparing across pairs reveals neither has actually converged to the full posterior.

What this means in practice

Convergence diagnostics are non-optional in any workflow that uses HMC/NUTS or Metropolis-Hastings for a real quant model — running R^\hat R checks and eyeballing effective sample size across multiple chains before trusting a posterior interval used for risk sizing or model comparison. Most modern Bayesian software reports R^\hat R and ESS automatically alongside posterior summaries specifically because skipping this check is a common and consequential mistake.

MCMC convergence diagnostics — chiefly R-hat across multiple independent chains and effective sample size within each chain — exist because a sampler that hasn't actually explored the full posterior produces output that looks completely normal on its own; only comparing multiple chains, or explicitly measuring autocorrelation, reveals whether the reported posterior can be trusted.

A single, smooth-looking chain with a stable trace plot is not evidence of convergence — it's exactly what a badly stuck chain also looks like, since a chain stuck in one region of the posterior will look perfectly well-behaved from the inside, the way the museum visitor's confident, detailed report of "the whole museum" looked perfectly coherent despite covering only one wing. Never assess convergence from a single chain; always run multiple chains from different, deliberately dispersed starting points and check that they agree.

Related concepts

Practice in interviews

Further reading

  • Gelman and Rubin, 'Inference from Iterative Simulation Using Multiple Sequences' (1992)
  • Vehtari et al., 'Rank-Normalization, Folding, and Localization: An Improved R-hat' (2021)
ShareTwitterLinkedIn