MCMC Convergence
Diagnostics
Learn how to determine when your Markov chain Monte Carlo sampler has converged, compute effective sample size, and avoid unreliable posterior estimates.
What is MCMC?
Markov chain Monte Carlo constructs a Markov chain whose stationary distribution equals the target posterior \( \pi(\theta \mid y) \). By drawing correlated samples from this chain, we approximate integrals like \( E_\pi[g(\theta)] \) without closed-form solutions.
Why Convergence Matters
The Trace Plot: Your First Check
The Gelman-Rubin Statistic \(\hat{R}\)
Run \( m \geq 2 \) chains of length \( n \) each. Define the between-chain variance \( B \) and within-chain variance \( W \):
Intuition: Between vs. Within
Convergence vs. Mixing
| Convergence | Mixing | |
|---|---|---|
| Definition | Chain has reached the stationary distribution | Chain explores the full support efficiently |
| Diagnostic | \(\hat{R}\), Geweke test | Autocorrelation, ESS |
| Failure looks like | Chains at different levels | Sticky, slow-moving trace |
| Fix | More burn-in, better initial values | Reparameterize, tune proposal |
Effective Sample Size \(n_{\text{eff}}\)
Correlated MCMC draws contain less information than the same number of independent draws. The effective sample size adjusts for autocorrelation:
Autocorrelation Plot
Monte Carlo Standard Error
The Monte Carlo standard error (MCSE) quantifies the precision of your posterior estimate. For the posterior mean:
Diagnostic Checklist
Example: Computing \(\hat{R}\)
Suppose we run \(m = 2\) chains of \(n = 1000\) draws each for parameter \(\mu\). After burn-in:
Example: Computing \(n_{\text{eff}}\)
From the same 2 chains (\(mn = 2000\) total draws), we estimate the autocorrelation for \(\mu\):
| Lag \(k\) | 1 | 2 | 3 | 4 | 5+ |
|---|---|---|---|---|---|
| \(\hat{\rho}_k\) | 0.42 | 0.18 | 0.06 | 0.01 | \(\approx 0\) |
Example: A Problematic Chain
Common Mistakes
Diagnostics Summary
| Diagnostic | What It Checks | Threshold |
|---|---|---|
| Trace Plot | Visual: mixing and stationarity | Chains overlap, "caterpillar" |
| \(\hat{R}\) | Between vs. within chain variance | \(< 1.01\) |
| \(n_{\text{eff}}\) | Information content of draws | \(> 400\) per parameter |
| MCSE | Simulation precision of estimate | \(< 5\%\) of posterior SD |
| ACF Plot | Autocorrelation decay rate | Drops to \(0\) within \(\sim 10-20\) lags |
Question 1 of 5
The Gelman-Rubin statistic \(\hat{R}\) compares which two quantities?
Question 2 of 5
A researcher runs 4 chains of 2000 draws each. The effective sample size for parameter \(\sigma\) is reported as \(n_{\text{eff}} = 120\). What should she conclude?
Question 3 of 5
Which of the following best describes what the Monte Carlo standard error (MCSE) measures?
Question 4 of 5
Two chains are run for a parameter \(\theta\). Chain 1 stabilizes around \(\bar{\theta}_1 = 5.2\) and Chain 2 around \(\bar{\theta}_2 = 12.8\), each with low within-chain variance. What does this indicate?
Question 5 of 5
If the autocorrelation at lag 1 is \(\hat{\rho}_1 = 0.95\) and decays slowly, which of the following is most likely true?