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.