Markov Chain Monte Carlo (MCMC) — Metropolis-Hastings and Gibbs Sampling
Markov Chain Monte Carlo (MCMC — Metropolis-Hastings, Gibbs Sampling) · Also known as: MCMC, Metropolis-Hastings, Gibbs sampling, Markov Zinciri Monte Carlo (MCMC — Metropolis-Hastings, Gibbs)
Markov Chain Monte Carlo (MCMC) is a family of simulation algorithms that constructs a Markov chain whose stationary distribution is the target posterior, enabling Bayesian inference and high-dimensional integral computation that would otherwise be analytically intractable. Pioneered by Metropolis and colleagues in 1953 and extended by Hastings in 1970, MCMC underpins modern Bayesian statistics. The two most widely used variants are Metropolis-Hastings, which proposes moves from a general proposal distribution, and Gibbs sampling, which draws each parameter in turn from its full conditional distribution.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
+9 more
When to use it
MCMC is the appropriate tool when a Bayesian model has been specified and the posterior distribution cannot be computed analytically — which is the common case for models with more than a handful of parameters or with non-conjugate priors. It is also the standard approach for latent-variable models, hierarchical models, and any setting where uncertainty must be propagated fully through a complex pipeline. No distributional assumptions about the data are needed beyond the likelihood specification. The main practical requirement is a sufficient number of iterations for the chain to converge: fewer than roughly 1 000 post-burn-in samples will typically not give a reliable characterisation of the posterior, and in high-dimensional settings many more are needed. When the parameter space is very high-dimensional, Hamiltonian Monte Carlo (HMC) or the No-U-Turn Sampler (NUTS) — automatic extensions of the MCMC idea — are substantially more efficient than basic Metropolis-Hastings.
Strengths & limitations
- Enables exact (asymptotically) Bayesian inference for models where the posterior has no closed form, covering hierarchical models, missing-data problems, and complex likelihoods.
- Produces a full joint posterior sample, so any derived quantity, prediction, or decision can be computed with properly propagated uncertainty.
- Applies to continuous, binary, and count outcomes and imposes no distributional assumptions on the data beyond the modeller-specified likelihood.
- Running multiple parallel chains makes convergence verification systematic through the Gelman-Rubin R̂ diagnostic.
- Convergence is not guaranteed in finite time; a chain that appears to have converged may still be stuck in a local region of the posterior.
- Autocorrelation between successive samples means the effective sample size is smaller than the raw number of iterations, requiring longer runs than an equivalent independent sample would need.
- In high-dimensional parameter spaces, random-walk Metropolis-Hastings mixes poorly; Hamiltonian Monte Carlo or NUTS is needed for efficient exploration.
- Model specification requires the analyst to choose priors thoughtfully, and poorly chosen priors or misspecified likelihoods can bias the posterior in ways that are hard to detect.
Frequently asked
How do I know whether my MCMC chain has converged?
The primary diagnostic is the Gelman-Rubin R̂ statistic, computed by running at least four independent chains from different starting points and comparing within-chain to between-chain variance. R̂ values below 1.05 for all parameters are the conventional threshold. Trace plots should show chains that overlap and explore the same region; funnel-shaped or drifting traces indicate poor mixing. Effective sample size should also be checked — a very small effective sample size relative to the raw count signals high autocorrelation and the need for more iterations or a better sampler.
What is the difference between Metropolis-Hastings and Gibbs sampling?
Metropolis-Hastings proposes a move for all parameters simultaneously (or in blocks) from a user-specified proposal distribution and accepts or rejects the proposal with a probability that preserves the target posterior as the stationary distribution. Gibbs sampling instead updates each parameter one at a time by drawing directly from its full conditional distribution — the distribution of that parameter given all others and the data. Gibbs sampling requires that these full conditionals be available in closed form, which is the case for many conjugate models; when they are available, Gibbs is highly efficient because every proposal is accepted. Metropolis-Hastings is more broadly applicable but requires tuning the proposal to achieve acceptable acceptance rates.
When should I use Hamiltonian Monte Carlo instead of Metropolis-Hastings?
Hamiltonian Monte Carlo (HMC) and its automatic variant NUTS use gradient information from the log-posterior to propose large, informed moves that are nonetheless accepted with high probability. This makes them far more efficient than random-walk Metropolis-Hastings in high-dimensional parameter spaces, where random proposals are almost always rejected. As a practical rule, if your model has more than about ten parameters or if Metropolis-Hastings chains show poor mixing and very low effective sample sizes, switching to HMC or NUTS is advisable.
How many iterations do I need?
There is no universal answer, but a common starting point is 1 000 warm-up (burn-in) iterations plus 2 000 sampling iterations per chain, across four chains, giving 8 000 post-burn-in draws. The adequacy of this depends on the autocorrelation of the chain and the complexity of the posterior. The chain is sufficient when R̂ < 1.05 for all parameters and the effective sample size is large enough to characterise the posterior features of interest — typically at least a few hundred effective samples for means and a few thousand for tail quantiles.
Sources
- Gelman, A., Carlin, J.B., Stern, H.S., Dunson, D.B., Vehtari, A. & Rubin, D.B. (2013). Bayesian Data Analysis (3rd ed.). Chapman & Hall/CRC. DOI: 10.1201/b16018 ↗
- Brooks, S., Gelman, A., Jones, G.L. & Meng, X.-L. (Eds.) (2011). Handbook of Markov Chain Monte Carlo. Chapman & Hall/CRC. DOI: 10.1201/b10905 ↗
How to cite this page
ScholarGate. (2026, June 1). Markov Chain Monte Carlo (MCMC — Metropolis-Hastings, Gibbs Sampling). ScholarGate. https://scholargate.app/en/simulation/markov-chain-monte-carlo
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- Approximate Bayesian ComputationSimulation↔ compare
- Bayesian RegressionBayesian↔ compare
- Bootstrap SimulationSimulation↔ compare
- Latin Hypercube SamplingSimulation↔ compare
- MONTE-CARLO-SIMULATIONDecision-making↔ compare