Gibbs Sampling
Gibbs sampling is an MCMC algorithm for a joint target in which each coordinate is updated by drawing from its full conditional , where denotes all coordinates other than . It applies whenever the full conditionals are available in closed form (or at least easy to sample from) even though the joint posterior is not. The canonical systematic-scan sweep is:
Given the current state , produce by:
- Draw .
- Draw .
- Draw .
Each coordinate update uses the most recently drawn values of every other coordinate.
Gibbs is the special case of Metropolis-Hastings in which the proposal for coordinate is its own full conditional and every proposal is accepted. The MH acceptance ratio reduces to identically:
since and the factors cancel. Each coordinate update therefore satisfies detailed balance with respect to , and a full sweep preserves as the stationary distribution. Under irreducibility and aperiodicity, the ergodic theorem gives
Random-scan Gibbs picks a coordinate uniformly at random at each step and updates only that coordinate; systematic-scan (above) cycles through all coordinates in a fixed order. Random-scan is reversible with respect to ; systematic-scan is not, but still admits as its stationary distribution.
Data augmentation (Tanner-Wong, 1987) extends Gibbs to models whose raw full conditionals are intractable by introducing latent variables such that has tractable conditionals and . Running Gibbs on and discarding the component yields samples from the marginal . This is the standard route for probit regression (with Gaussian latent variables) and mixture models (with categorical class indicators).
Metropolis-within-Gibbs handles partial conjugacy: coordinates with closed-form conditionals are updated by Gibbs draws; coordinates without are updated by a Metropolis-Hastings step against the full conditional as target. The combined sweep still preserves .
Intuition
The joint target is often intractable, but “condition on everything except ” frequently leaves a distribution whose kernel is a familiar family (normal, gamma, beta). Each Gibbs step exploits conditional tractability — the full conditional is a univariate problem, and univariate problems are tractable far more often than their joint counterpart. Cycling through the coordinates traces a path through the joint that keeps at least one axis moving at any given step; over many sweeps the path fills out the joint in proportion to .
The central tension is coordinate correlation. If two coordinates are nearly collinear under , conditioning on one pins the other in a narrow band and each update moves the state only along a thin ridge, producing strong autocorrelation and slow mixing. Reparameterizing to less-correlated coordinates, updating blocks of correlated coordinates jointly, or switching to a gradient-aware sampler (MALA, HMC) are the standard remedies. Gibbs excels at conditionally-conjugate hierarchies and at problems where latent-variable augmentation collapses a hard joint into easy conditionals.
Properties
(Always Accept) The Gibbs coordinate update is an MH step with acceptance probability identically .
Full-conditional proposals match the conditional density of the target, so the Hastings ratio reduces via to exactly. This is the algebraic identity that makes Gibbs tune-free: there is no step size to pick, no acceptance rate to chase, and no proposal-scale trade-off. The cost is that the full conditional must be sampleable; when it is not, one falls back to MH.
(Coordinate Update Preserves ) Each single-coordinate update satisfies detailed balance; composing updates preserves the invariant distribution.
For a single-coordinate update at index , the transition kernel is . Detailed balance follows because
using . A full systematic-scan sweep is the composition ; composition of -invariant kernels is -invariant, so the sweep preserves . Each individual is reversible; the composition is reversible if the scan order is randomized (random-scan Gibbs) but not in general for systematic scan.
(Data Augmentation) Introducing a latent variable can turn an intractable joint into a tractable pair of conditionals.
When the direct posterior has no closed-form conditional, one can often introduce a latent such that the augmented posterior satisfies
Running Gibbs on and discarding produces samples from by marginalization. Canonical instances are probit regression ( with and , due to Albert-Chib, 1993) and mixture models ( indicating the component of observation , due to Diebolt-Robert, 1994). The same pattern covers missing data, censored data, and hierarchical models.
(Metropolis-within-Gibbs) A coordinate without a closed-form conditional can be updated by a Metropolis step against the conditional as target.
If is known up to a normalizing constant but not sampleable, a single MH step with proposal and acceptance probability
preserves as the stationary distribution. Because only the coordinate- slice of matters, the factor cancels and only the unnormalized conditional is needed. Hybrid sweeps — Gibbs for conjugate coordinates, MH (or slice sampling) for non-conjugate coordinates — are the standard way to handle partially conjugate models.
(Mixing Failure Under High Coordinate Correlation) Strong correlation between coordinates produces thin conditional ridges and slow exploration.
If is approximately bivariate normal with correlation close to , the conditional has variance , narrow when is large. A Gibbs sweep moves within this narrow band, then within a symmetrically narrow band, producing a sequence of small orthogonal steps up a diagonal ridge. The chain eventually fills the joint but at an autocorrelation timescale that grows as . Standard remedies: block Gibbs (update correlated coordinates jointly from the multivariate conditional), reparameterize to uncorrelated coordinates (e.g., center-scale a hierarchical model to reduce prior-likelihood confounding), or switch to HMC which uses gradient information to step along ridge directions rather than axis-aligned.
(Systematic vs. Random Scan) Random-scan Gibbs is reversible; systematic-scan is generally not, but both have stationary.
Systematic scan cycles through coordinates in a fixed order ; random scan picks a coordinate uniformly at each step and updates only that one. Systematic scan typically mixes faster because it guarantees every coordinate is updated each sweep, but its composite transition is not symmetric under reversal. Random scan is reversible (the coordinate index and update are symmetric in time), which simplifies some theoretical arguments but wastes effort by revisiting the same coordinate before updating others. In practice, systematic scan is the default.
(Irreducibility Requirement) Gibbs can fail catastrophically when the support of is disconnected relative to coordinate-aligned moves.
The chain is irreducible only if coordinate-aligned moves can reach every region of positive -mass. A target supported on two disjoint islands aligned diagonally (e.g., concentrated on with a gap between them) has no Gibbs path between the islands because changing one coordinate at a time cannot cross the gap. The chain gets stuck on the initial island forever, yielding samples that look like draws from a conditional restriction rather than . Multi-modal posteriors (especially in mixture models with label-switching behavior) are the practical version of this trap; running multiple chains from overdispersed starting points is the standard diagnostic.
Examples
Bivariate normal
Let have a mean-zero bivariate normal target with variances and correlation :
The full conditionals are
read off by completing the square in each coordinate. One Gibbs sweep: draw , then draw .With the coordinates are independent and a single sweep produces an exact sample. With the conditional variance is tiny and each update nudges the state along the main diagonal by ; traversing the full support requires sweeps. A trace plot of in the high- case shows slow sinusoidal drift, the classic signature of coordinate-correlation-induced slow mixing.
Bayesian linear regression with a conditionally conjugate prior
Consider with , and priors and . The joint posterior is not a recognizable distribution, but each full conditional is conjugate:
For , given :
For , given :
Both conditionals are standard and easy to sample. A Gibbs sweep alternates the two updates. Initializing at and places the chain near the posterior mode and minimizes burn-in. This is the prototypical “conditionally conjugate hierarchy” Gibbs target — every hyperparameter in the vault’s hierarchical-models note (3.6 Hierarchical Models) is updated the same way.
Probit regression via data augmentation (Albert-Chib)
Let and model with a flat prior on . The direct likelihood is log-concave in but has no conjugate conditional. Introduce latent with and ; marginalizing gives back the probit likelihood, so the augmented posterior has the same -marginal as the original.
The augmented conditionals are tractable:
, which under the flat prior gives
a standard Gaussian conjugate update with playing the role of the “response.”, a truncated normal:
A full Gibbs sweep draws every from its truncated normal and then updates from the resulting Gaussian. The -marginal of the chain is the probit posterior . No tuning, no acceptance rate — the same data-augmentation trick generalizes to ordinal probit (multiple cutoffs) and multinomial probit (Gaussian latent vector).
Gaussian mixture via latent class indicators
Let be drawn from a -component Gaussian mixture
with priors , , . The likelihood is a sum over assignments of data points to components — intractable directly. Introduce latent class indicators such that means came from component .The augmented full conditionals are all conjugate:
- : categorical with probabilities .
- : , where .
- : Gaussian with mean and variance computed from the observations assigned to component .
- : inverse-gamma with shape and scale updated by the sum of squared residuals in component .
A Gibbs sweep updates , , , in turn. This is the standard finite mixture Gibbs sampler; extending to infinitely many components replaces the Dirichlet prior with a Dirichlet process and adds a Chinese-restaurant-process step for . The deterministic analog of this sampler — which maximizes the augmented posterior rather than sampling from it — is the EM algorithm, with the -update replaced by its expectation (E-step) and the parameter updates replaced by their MAP (M-step).
Derivation
Goal. Show that each Gibbs coordinate update is an MH step with acceptance probability , and that the update kernel preserves as its stationary distribution.
Fix coordinate and write . Propose with ; the proposal kernel is . The MH acceptance probability is
Since , the indicator factors in are both when the proposal is made, and
So and every proposal is accepted.
The resulting transition kernel satisfies detailed balance with :
because and multiplication is commutative. Detailed balance implies is stationary for . The composition of -stationary kernels is -stationary, so a full systematic-scan sweep preserves . Under irreducibility (every region of positive -mass can be reached by coordinate-aligned moves) and aperiodicity, the ergodic theorem delivers a.s. convergence of time averages to posterior expectations.
See Also
- 3.11.1 Metropolis-Hastings — Gibbs is the special case with full-conditional proposals; MH handles cases where the conditional is unavailable.
- 3.11 MCMC — parent index: chain theory, ergodic theorem, diagnostics, tuning.
- 3.11.5 EM Algorithm — deterministic analog that maximizes the augmented posterior instead of sampling from it.
- 3.6 Hierarchical Models — conditionally conjugate hierarchies are the natural application.
- 3.8.3 Bayesian Logistic Regression — non-conjugate sibling that requires Metropolis-within-Gibbs or Laplace-adjusted proposals.
- 5.4 Reversibility — detailed-balance condition that single-coordinate updates satisfy.
- 5.3 Distribution of Markov Chains — stationary distributions and the ergodic theorem.