Markov chain Monte Carlo (MCMC) is a family of methods for drawing samples from a probability distribution that is too complex to sample directly. It builds a Markov chain whose long-run behavior matches the target distribution, then uses the chain’s samples to estimate quantities such as means, credible intervals and model parameters. It is widely used in Bayesian statistics.

The Metropolis-Hastings algorithm

Metropolis-Hastings is the best-known MCMC algorithm:

  1. Start from a point in the parameter space.
  2. Propose a new point from a proposal distribution, such as a small random step.
  3. Compute the acceptance ratio: how likely the new point is under the target distribution relative to the current one, corrected for any asymmetry in the proposal.
  4. Accept the new point with probability equal to the smaller of 1 and that ratio; otherwise stay at the current point.
  5. Repeat many times. The sequence of points is the chain.

Gibbs sampling, which updates one parameter at a time from its conditional distribution, and Hamiltonian Monte Carlo, which uses gradients to take longer steps, are other common variants.

Burn-in and convergence

Early samples depend on the starting point and are discarded as burn-in. Convergence is checked before results are used, for example by running several chains from different starts and comparing them. Successive samples are correlated, so the effective sample size is smaller than the chain length.

Where it fits with simulation

MCMC is one way to estimate uncertain inputs, such as failure rates or demand parameters, from limited data. Those estimates, with their uncertainty, can then feed a simulation or risk model.

Common mistakes

These are the mistakes we see most often:

  • Using results before the chain has converged.
  • Treating successive samples as independent.
  • Tuning the proposal so poorly that almost every step is accepted or almost none is.

MCMC FAQ

Plain Monte Carlo draws independent samples from known distributions. MCMC draws correlated samples from a distribution that cannot be sampled directly, using a Markov chain.

Metropolis-Hastings is one MCMC algorithm, and the most widely known.