Markov Chain
Monte Carlo
Explore the foundations of MCMC sampling: how random walks through state space let us approximate complex probability distributions that are analytically intractable.
Why Do We Need MCMC?
In Bayesian inference, we want the posterior distribution \( p(\theta \mid \mathbf{y}) \). By Bayes' theorem:
The normalizing constant \( p(\mathbf{y}) = \int p(\mathbf{y} \mid \theta)\, p(\theta)\, d\theta \) is often a high-dimensional integral that cannot be computed in closed form. MCMC sidesteps this by drawing correlated samples from the posterior without evaluating the integral.
Two Key Ingredients
Convergence to the Stationary Distribution
The Detailed Balance Condition
For a Markov chain to have stationary distribution \( \pi \), a sufficient (not necessary) condition is detailed balance:
where \( T(\theta' \mid \theta) \) is the transition kernel. This means the "probability flow" from \( \theta \) to \( \theta' \) equals the reverse flow. A chain satisfying this is called reversible.
The Metropolis-Hastings Algorithm
Metropolis-Hastings: Accept/Reject
Metropolis-Hastings vs. Gibbs Sampling
| Metropolis-Hastings | Gibbs Sampling | |
|---|---|---|
| Proposal | User-chosen \( q(\theta^* \mid \theta^{(t)}) \) | Full conditionals \( p(\theta_j \mid \theta_{-j}) \) |
| Acceptance step | Yes, with ratio \( \alpha \) | No: every draw is always accepted |
| Tuning needed | Proposal variance tuning required | None if conditionals are known |
| Dimensionality | Updates all components at once | Updates one component at a time |
| Best when | Conditionals are unavailable | Conditionals are tractable (e.g., conjugate models) |
How Gibbs Sampling Works
For a parameter vector \( \boldsymbol{\theta} = (\theta_1, \theta_2, \ldots, \theta_d) \), Gibbs cycles through each component:
Gibbs Sampling: Staircase Pattern
Tuning the Proposal Distribution
Convergence Diagnostics
Example: MH for a Normal Mean
Suppose we observe \( y_1, \ldots, y_n \sim \mathcal{N}(\mu, 1) \) and use a flat prior \( p(\mu) \propto 1 \). The posterior is \( \mu \mid \mathbf{y} \sim \mathcal{N}(\bar{y}, 1/n) \). Let us use MH with proposal \( q(\mu^* \mid \mu) = \mathcal{N}(\mu, \sigma_q^2) \).
Example: Gibbs for a Bivariate Normal
Target: \( (\theta_1, \theta_2) \sim \mathcal{N}\!\left(\mathbf{0}, \begin{pmatrix} 1 & \rho \\ \rho & 1 \end{pmatrix}\right) \). The full conditionals are:
Each Gibbs iteration: sample \( \theta_1^{(t+1)} \) from the first conditional using the current \( \theta_2^{(t)} \), then sample \( \theta_2^{(t+1)} \) from the second using the fresh \( \theta_1^{(t+1)} \).
Reading a Trace Plot
Common Mistakes
MCMC Methods: Summary
| Metropolis-Hastings | Gibbs Sampling | HMC | |
|---|---|---|---|
| Proposal | Any user-chosen \(q\) | Full conditionals | Hamiltonian dynamics |
| Acceptance | \(\alpha \le 1\) | Always 1 | \(\alpha \approx 1\) (leapfrog) |
| Tuning | Proposal variance | None (if conjugate) | Step size, path length |
| High \(d\) | Degrades quickly | Works if conditionals tractable | Scales well |
| Requires | \(\pi(\theta)\) up to constant | All full conditionals | \(\nabla \log \pi(\theta)\) |
Step-by-Step: Running MCMC
Question 1 of 5
What is the primary purpose of the burn-in period in MCMC?
Question 2 of 5
In the Metropolis-Hastings algorithm with a symmetric proposal \( q(\theta^* \mid \theta) = q(\theta \mid \theta^*) \), the acceptance ratio simplifies to:
Question 3 of 5
Why is Gibbs sampling considered a special case of Metropolis-Hastings?
Question 4 of 5
A Metropolis-Hastings chain has an acceptance rate of 2%. What is the most likely problem?
Question 5 of 5
The Gelman-Rubin statistic \( \hat{R} \) compares: