Tutorials › Generalized Linear Mixed Models (GLMM) › Warmup, Adaptation, and Stationary MCMC Draws

Bayesian GLMM and Prior Specification for Variance Components · Tutorial 280 of 698

Warmup, Adaptation, and Stationary MCMC Draws

Distinguish discarded warmup from retained posterior draws, and learn how to adapt computation during warmup without confusing adaptation with stationarity.

Advanced 12 min read

What You'll Learn

  • Define warmup, adaptation, stationarity, and retained posterior draws in Bayesian GLMM computation.
  • Explain why discarding initial iterations does not by itself guarantee stationarity.
  • Apply a random-walk proposal adaptation example on a log variance-component scale.
  • Describe how HMC step-size and metric adaptation fit into warmup.
  • Distinguish fixed-kernel sampling from adaptive MCMC and identify the conditions needed for adaptive validity.
  • Recognize practical signs that an adaptation schedule or warmup length may be inadequate.

Why Warmup and Retained Sampling Are Different

Bayesian computation for a GLMM produces a sequence of parameter values, not a collection of independent draws. For a hierarchical model, let \(\theta\) denote all unknown quantities of interest, including fixed effects and variance components, and let \(\pi(\theta\mid y)\) denote their posterior density given the observed data \(y\). MCMC constructs a sequence whose long-run distribution is intended to be \(\pi(\theta\mid y)\). The initial part of a run is commonly used to move away from initial values and tune computational settings; that part is called warmup or, in some contexts, burn-in.

Warmup and posterior sampling have different purposes. During warmup, an algorithm may adapt its proposal scale, estimate a useful proposal covariance, or tune an HMC step size and mass matrix. After warmup, these settings are ordinarily frozen, and the algorithm generates draws using a fixed transition rule. The retained draws are then used to approximate posterior summaries. This separation matters because changing the transition rule based on the chain's recent history can affect the distribution of the draws.

Definition: A Markov transition kernel \(P\) is posterior-invariant for \(\pi(\theta\mid y)\) if applying one transition to a state distributed as \(\pi(\theta\mid y)\) leaves that distribution unchanged: $$ \int \pi(\theta\mid y)P(\theta,A)\,d\theta=\int_A \pi(\theta'\mid y)\,d\theta' $$ for every measurable set \(A\). The chain is stationary when its state has the posterior distribution at every iteration. Warmup is the initial phase used to move the chain toward its target and, where applicable, adapt computational settings. Retained draws are the subsequent draws used for posterior inference.

Posterior invariance is not the same as stationarity from the first iteration. If a fixed kernel \(P\) is posterior-invariant and \(X_0\) is already drawn from \(\pi(\theta\mid y)\), then every \(X_t\) has that posterior distribution. In practice, a chain starts from a chosen value, not a posterior draw. Under suitable convergence conditions, the distribution of \(X_t\) approaches the posterior as \(t\) grows. Discarding warmup is a practical way to avoid using the most initialization-dependent part of a run, but it does not prove that later draws are stationary.

What Adaptation Changes

In a fixed-kernel Metropolis-Hastings sampler, a proposal \(\theta'\) is generated from \(q(\theta'\mid\theta)\), and the move is accepted with probability

$$ \alpha(\theta,\theta')= \min\left\{1,\frac{\pi(\theta'\mid y)q(\theta\mid\theta')} {\pi(\theta\mid y)q(\theta'\mid\theta)}\right\}. $$

The proposal and acceptance probability together define a transition kernel that preserves the posterior, assuming the target density is evaluated correctly and the proposal allows the chain to reach the relevant parts of the target. The formula accounts for asymmetry in a fixed proposal rule. It does not, by itself, justify changing proposal settings in response to the full history of the chain.

An adaptive algorithm may choose a proposal covariance or scale using previous states or acceptance outcomes. Its transition at iteration \(t\) then depends on an evolving setting \(\gamma_t\), as well as the current state. The resulting process is generally not a homogeneous Markov chain on \(\theta\) alone. Although each frozen-setting kernel may preserve the posterior, switching among kernels based on the chain's history does not automatically imply that the adaptive sequence has the posterior as its distribution.

The safest standard workflow is to adapt during warmup and then freeze the settings. More advanced adaptive MCMC can retain adaptation during sampling, but validity requires formal conditions, commonly including diminishing adaptation (successive changes in the transition rule become negligible) and a suitable containment condition preventing convergence times from becoming arbitrarily poor. These conditions are technical and should not be assumed merely because the adaptation is gradual or the acceptance rate looks reasonable. In ordinary applied GLMM computation, freezing adaptation is a clear way to obtain a fixed post-warmup kernel.

Worked Example: Adapting a Random-Walk Scale for a Variance Component

Suppose a Bayesian GLMM has a positive random-intercept variance component \(\tau^2\). A sampler updates \(\eta=\log(\tau^2)\) with a random-walk proposal \(\eta'=\eta+\epsilon\), where \(\epsilon\sim N(0,s^2)\). A hypothetical warmup run records an acceptance fraction of \(0.70\) over a recent block, while the tuning target for this particular proposal is \(0.30\). For illustration, suppose the scale is updated by multiplying it by \(1.2\) when the observed fraction exceeds the target.

If the current proposal standard deviation is \(s=0.50\), the warmup adjustment is \(s_{\mathrm{new}}=1.2(0.50)=0.60\). The variance of the proposal changes from \(0.50^2=0.25\) to \(0.60^2=0.36\). A larger proposal may produce moves farther across the log-variance scale and may lower the acceptance fraction. This adjustment is a tuning decision, not a posterior update for \(\tau^2\).

Because \(\eta=\log(\tau^2)\), the proposal is symmetric in \(\eta\), but the implied proposal on \(\tau^2\) is not symmetric. The Metropolis-Hastings ratio must be formed consistently on the scale used to define the target density. If the target density is expressed for \(\eta\), it must include the transformation Jacobian: \(\pi_\eta(\eta\mid y)=\pi_{\tau^2}(e^\eta\mid y)e^\eta\). During warmup the scale can be tuned using the observed behavior; after tuning, set \(s=0.60\) (or another selected value) and use the resulting fixed proposal rule for retained sampling.

The numerical target of \(0.30\) is only the stated tuning choice for this example; no universal acceptance fraction guarantees good sampling. An acceptance rate alone does not establish that a chain explores the posterior adequately.

Warmup for Random-Walk Metropolis and HMC

For random-walk Metropolis updates, adaptation commonly targets proposal scale or covariance. A scale that is too small can produce many accepted but highly local moves; a scale that is too large can produce frequent rejections. In a multivariate GLMM posterior, a covariance estimate can also help align proposals with correlated parameter directions. Variance components are positive and may have skewed or concentrated posterior distributions, so tuning on a transformed scale, such as \(\log(\tau^2)\), can be more convenient than proposing directly on the constrained scale.

For Hamiltonian Monte Carlo, warmup can tune the step size and the mass matrix (or metric). A step size that is too large can make numerical integration inaccurate, while one that is too small can require many integration steps. A metric can rescale or decorrelate parameter directions. These settings are chosen to support efficient transitions, not to change the posterior target. Once adaptation ends, the retained HMC transitions use fixed settings. If the model uses constrained parameters, the target and transformations must still be handled consistently in the HMC implementation.

Worked Example: Separating HMC Warmup From Sampling

Consider a hypothetical HMC run for a random-intercept logistic GLMM with 1,000 warmup iterations followed by 2,000 retained iterations. During warmup, the software adjusts the step size and estimates a mass matrix. At the end of iteration 1,000, suppose the final step size is \(0.08\), in the software's specified parameterization, and the estimated mass matrix is \(M\).

For iterations 1,001 through 3,000, the sampler uses step size \(0.08\) and mass matrix \(M\), without further tuning. The 1,000 warmup states are excluded from posterior summaries; the 2,000 subsequent states are retained. The posterior mean of a coefficient \(\beta_1\), for example, is estimated by \(\bar{\beta}_1=(1/2000)\sum_{t=1001}^{3000}\beta_{1,t}\). This calculation treats the retained values as draws from the posterior distribution, not as 2,000 independent observations.

The setup is appropriate only if the final fixed HMC transition preserves the specified posterior and the chain has had adequate time to approach its stationary behavior. Ending adaptation is necessary for this straightforward fixed-kernel interpretation, but the chosen warmup length does not guarantee adequate exploration. The subsequent evaluation of mixing and other diagnostics is a separate task.

A warmup schedule often has stages: initial movement from the starting point, one or more adaptation windows, and a final period in which tuning settings are stabilized. The precise schedule depends on the sampler. What matters conceptually is that tuning information is used to set the transition rule, while the retained phase is generated under the rule that will be used for inference. Tuning based on retained draws and then treating those same draws as if generated by an unchanged kernel blurs this distinction.

Why a Fixed Post-Warmup Kernel Supports Posterior Inference

The justification for freezing settings is short but important. Suppose the post-warmup sampler has a fixed kernel \(P\) that preserves \(\pi(\theta\mid y)\). If \(X_0\) has distribution \(\pi(\theta\mid y)\), then after one transition,

$$ P(X_1\in A) =\int \pi(\theta\mid y)P(\theta,A)\,d\theta =\int_A \pi(\theta'\mid y)\,d\theta'. $$

Thus \(X_1\) also has the posterior distribution. Repeating the same argument shows that every subsequent state has that distribution. If the chain starts away from the posterior, this calculation does not apply at the first retained iteration; convergence properties of the fixed kernel are what justify treating sufficiently late draws as approximately posterior draws. The draws remain dependent because each state is generated from the previous state.

By contrast, if the kernel at iteration \(t\) is \(P_{\gamma_t}\), where \(\gamma_t\) is selected from the run's history, then the displayed invariance calculation cannot simply be applied with one fixed \(P\). Adaptive MCMC theory supplies conditions under which such procedures can still converge, but the ordinary fixed-kernel argument alone is insufficient.

Worked Example: Why Discarding Adaptation Does Not Prove Stationarity

Suppose a sampler for \(\tau^2\) starts at \(\tau^2=0.01\), while the posterior in a hypothetical analysis places most of its mass between \(0.3\) and \(1.2\). The algorithm adapts its proposal for the first 500 iterations, then freezes the proposal and runs 1,500 more iterations. A researcher discards the first 500 states and retains the next 1,500.

The retained segment is generated by a fixed kernel, which allows the fixed-kernel invariance and convergence reasoning to apply. However, the fact that 500 iterations were discarded is not a mathematical guarantee that the first retained state is distributed as the posterior. If the chain has not moved away from its initial region or has not explored relevant posterior regions, the retained summaries may still depend on initialization.

The correct conclusion is therefore conditional: the 1,500 states are candidates for posterior estimation if the fixed kernel targets the posterior and the chain has adequately approached its stationary regime. One cannot conclude stationarity solely from the count of discarded iterations. Convergence and mixing need to be assessed using appropriate diagnostics and, where needed, longer runs or improved parameterization.

Choosing and Evaluating an Adaptation Policy

A practical policy should specify what is adapted, when adaptation ends, and which draws are used for inference. It should also preserve the intended target density: tuning a numerical proposal does not excuse an incorrect likelihood, prior, Jacobian, or Metropolis-Hastings correction. For chains run in parallel, each chain may have its own warmup adaptation; settings should not be changed during retained sampling unless the algorithm and its validity conditions explicitly support continued adaptation.

PolicyWhat happensMain implication
Fixed settings from the startThe same transition rule is used throughout the run.Simple invariance argument; performance may be poor if settings are unsuitable.
Adapt during warmup, then freezeTuning uses initial iterations; all retained draws use fixed settings.Clear separation between tuning and posterior estimation; adequate warmup is still needed.
Continue adapting during retained samplingSettings change using the evolving history.May be valid under formal adaptive-MCMC conditions, but fixed-kernel reasoning is not enough.

Warning signs include proposal settings that keep changing near the end of warmup, repeated rejection or nearly unchanged states, and highly different retained behavior across chains. These observations do not by themselves identify the cause, but they suggest that tuning, parameterization, or the model computation may need attention. The remedy is not automatically to discard more iterations: a poor transition rule can remain poor indefinitely. Diagnostics should guide decisions about whether to extend warmup, revise tuning, or reparameterize.

A common mistake is to say, “I removed the first 1,000 iterations, so the remaining draws are stationary.” The correction is that discarding is a practical attempt to reduce initialization effects, not a proof of stationarity. Another mistake is to interpret a high acceptance rate as evidence of good posterior exploration. Acceptance describes how often proposed moves are accepted; it does not measure how much of the posterior has been explored. Conversely, continued adaptation is not automatically invalid, but it requires conditions beyond the ordinary fixed-kernel argument.

The central limitation is that no universal warmup length or proposal setting works for every GLMM. Difficult posterior geometry, weakly identified variance components, and strong dependence among parameters can require substantial tuning and careful assessment. Warmup is part of computation, not posterior data; freezing settings gives a transparent sampling phase, but it cannot compensate for an incorrect model or a chain that fails to explore its target.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. What is the difference between posterior invariance of a kernel and stationarity of a chain?
  2. A random-walk proposal's scale is updated throughout a run, including the iterations used to estimate a posterior mean. What issue does this raise?
  3. Why does discarding 500 warmup iterations not establish that the first retained state is a posterior draw?
  4. In a hypothetical HMC analysis, step size and mass matrix are tuned during warmup and then frozen. What role do the retained draws play?
  5. Is continued adaptation always invalid? State the qualification.

Solutions. (1) Invariance means that one transition preserves the posterior distribution if the current state already has that distribution. Stationarity means the chain's state has the posterior distribution at every iteration. Invariance alone does not put a chain initialized elsewhere into stationarity. (2) The retained transitions are history-dependent rather than generated by one fixed kernel. Ordinary fixed-kernel invariance is not sufficient to justify them; one must freeze adaptation or use a valid adaptive-MCMC method with appropriate conditions. (3) The number discarded does not prove convergence. The fixed-kernel chain may still retain substantial dependence on its starting point, so convergence and mixing must be assessed. (4) The retained states are used to approximate posterior quantities, such as means or intervals, provided the fixed kernel targets the posterior and the chain has adequately approached its stationary regime. They are dependent draws, not independent observations. (5) No. Continued adaptation can be theoretically valid under conditions such as diminishing adaptation and suitable containment, but it is not justified merely by using a slowly changing proposal or observing a plausible acceptance rate.

Clinical Biostats