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:

  1. Draw .
  2. Draw .
  3. 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

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