Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Bayesian MCMC methods let students approximate posterior distributions when direct calculation is difficult or impossible. This cheat sheet summarizes the main ideas behind Markov chains, posterior sampling, Metropolis-Hastings, Gibbs sampling, and convergence checks. It is useful because Bayesian models often produce integrals that cannot be solved by hand, so simulation becomes the practical tool for inference.

Key Facts

  • Bayes’ theorem updates prior beliefs using data: p(θy)=p(yθ)p(θ)p(y)p(\theta \mid y) = \frac{p(y \mid \theta)p(\theta)}{p(y)}.
  • The posterior normalizing constant is the marginal likelihood p(y)=p(yθ)p(θ)dθp(y) = \int p(y \mid \theta)p(\theta)\,d\theta.
  • MCMC estimates posterior expectations with sample averages: E[g(θ)y]1Ss=1Sg(θ(s))E[g(\theta) \mid y] \approx \frac{1}{S}\sum_{s=1}^{S} g(\theta^{(s)}).
  • A Markov chain has transition rule p(θ(s+1)θ(s),θ(s1),)=p(θ(s+1)θ(s))p(\theta^{(s+1)} \mid \theta^{(s)}, \theta^{(s-1)}, \ldots) = p(\theta^{(s+1)} \mid \theta^{(s)}).
  • In Metropolis-Hastings, a proposal θq(θθ)\theta^{*} \sim q(\theta^{*} \mid \theta) is accepted with probability α=min(1,p(θy)q(θθ)p(θy)q(θθ))\alpha = \min\left(1, \frac{p(\theta^{*} \mid y)q(\theta \mid \theta^{*})}{p(\theta \mid y)q(\theta^{*} \mid \theta)}\right).
  • For a symmetric proposal q(θθ)=q(θθ)q(\theta^{*} \mid \theta) = q(\theta \mid \theta^{*}), the Metropolis-Hastings acceptance probability reduces to α=min(1,p(θy)p(θy))\alpha = \min\left(1, \frac{p(\theta^{*} \mid y)}{p(\theta \mid y)}\right).
  • Gibbs sampling updates each parameter from its full conditional distribution, such as θj(s+1)p(θjθj(s),y)\theta_j^{(s+1)} \sim p(\theta_j \mid \theta_{-j}^{(s)}, y).
  • Effective sample size adjusts for autocorrelation: ESSS1+2k=1ρkESS \approx \frac{S}{1 + 2\sum_{k=1}^{\infty}\rho_k}.

Vocabulary

Posterior distribution
The distribution p(θy)p(\theta \mid y) describing uncertainty about parameters θ\theta after observing data yy.
Prior distribution
The distribution p(θ)p(\theta) representing beliefs about parameters before observing the current data.
Likelihood
The function p(yθ)p(y \mid \theta) that measures how plausible the observed data are for different parameter values.
Markov chain
A sequence of random states where the next state depends only on the current state, not the full past history.
Burn-in
The early part of an MCMC run often discarded because the chain may not yet represent the target posterior distribution.
Autocorrelation
Dependence between MCMC draws at different lags, often measured by correlations such as ρk\rho_k.

Common Mistakes to Avoid

  • Treating MCMC draws as fully independent is wrong because consecutive samples are usually autocorrelated. Use diagnostics and ESSESS rather than only the raw number of iterations.
  • Ignoring burn-in can be wrong because early draws may reflect the starting value more than the posterior. Check trace plots and convergence before summarizing samples.
  • Using the wrong Metropolis-Hastings ratio is wrong because proposal densities may not cancel unless the proposal is symmetric. Include q(θθ)q(\theta \mid \theta^{*}) and q(θθ)q(\theta^{*} \mid \theta) when needed.
  • Assuming a high acceptance rate is always good is wrong because tiny proposal steps can accept often but explore slowly. Tune proposals to balance movement and acceptance.
  • Relying on one diagnostic alone is wrong because no single statistic proves convergence. Compare trace plots, multiple chains, R^\hat{R}, autocorrelation, and effective sample size.

Practice Questions

  1. 1 A Bayesian model has p(yθ)=0.20p(y \mid \theta) = 0.20, p(θ)=0.30p(\theta) = 0.30, and p(y)=0.05p(y) = 0.05. Compute p(θy)p(\theta \mid y) using Bayes’ theorem.
  2. 2 In a symmetric Metropolis proposal, the current unnormalized posterior value is 0.400.40 and the proposed value is 0.700.70. Find the acceptance probability α\alpha.
  3. 3 An MCMC run has S=5000S = 5000 draws and autocorrelation sum k=1ρk=4.5\sum_{k=1}^{\infty}\rho_k = 4.5. Estimate ESSS1+2k=1ρkESS \approx \frac{S}{1 + 2\sum_{k=1}^{\infty}\rho_k}.
  4. 4 Explain why two chains with similar posterior means may still require trace plots and convergence diagnostics before their results are trusted.

Understanding Bayesian MCMC Reference

A sampler usually works with an unnormalised posterior. This means it evaluates how plausible one parameter value is relative to another, without needing the total area under the posterior curve. That total area is often the hard part of a Bayesian calculation.

In a comparison between two candidate values, the unknown constant cancels out. This is why simulation can still produce useful estimates.

After enough representative draws, students can estimate a posterior mean, a median, an interval, or the chance that a parameter lies above a meaningful threshold. For example, a medical study might estimate the probability that a treatment effect is positive, rather than report only one best estimate.

Metropolis-Hastings explores the posterior by making local suggestions. A proposed move toward a more plausible region is accepted readily. A move toward a less plausible region may still be accepted sometimes.

Those occasional downhill moves are important because they stop the chain from getting trapped near one local peak. Proposal size matters a great deal. Very small steps are accepted often, but the chain moves slowly through the distribution.

Very large steps are rejected often, so the chain stays in place. A useful sampler balances movement with acceptance.

There is no single acceptance rate that proves a run is good, especially in many dimensions. Students should focus on whether the chain explores all important regions efficiently.

Gibbs sampling can be simpler when each parameter has a known conditional distribution. It updates one parameter while temporarily holding the others fixed, then repeats for the next parameter. This works well in models with convenient conditional forms, such as some normal models and hierarchical models.

Its weakness appears when parameters are strongly related. Imagine two parameters that must rise or fall together to fit the data. Updating one at a time can make the chain creep along a narrow diagonal region.

Rewriting the model, rescaling variables, or using a sampler that updates several parameters together can improve this. Centered and noncentered versions of a hierarchical model can behave very differently even though they describe the same underlying situation.

A chain that produces many rows of output does not automatically provide much information. Nearby draws tend to resemble each other, which is called autocorrelation. Effective sample size estimates how many independent draws would contain a similar amount of information.

Trace plots help reveal whether a chain wanders around one stable region or shows long trends and stuck periods. Running several chains from dispersed starting values gives another check. If chains settle into similar ranges and have similar variation, that supports convergence, though it does not prove it.

Students should inspect posterior summaries, trace plots, autocorrelation, and effective sample size together. They should also check the model itself through posterior predictive simulations, where data generated from fitted parameters are compared with the real observations. A sampler can converge perfectly to a model that fits the world poorly.