Tutorials › Generalized Linear Mixed Models (GLMM) › Monte Carlo Error in Posterior Variance Estimates

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

Monte Carlo Error in Posterior Variance Estimates

Learn to quantify simulation error in posterior variance estimates using the autocorrelation of squared deviations, not just the autocorrelation of the original draws.

Advanced 10 min read

What You'll Learn

  • Express a posterior variance estimate as an MCMC average of squared deviations.
  • Derive its asymptotic Monte Carlo standard error from a Markov-chain central limit theorem.
  • Estimate the long-run variance using batch means or autocovariances.
  • Explain why effective sample size must be specific to the squared-deviation summary.
  • Recognize when tail behavior, chain dependence, or unstable estimates make reported precision unreliable.

Why Posterior Variance Estimates Need Their Own Error Measure

An MCMC run produces a finite sequence of draws, so a posterior variance calculated from those draws has simulation error. That error is not the posterior uncertainty being summarized: it is the uncertainty in the numerical estimate caused by using a finite simulation. Because MCMC draws are generally autocorrelated, the usual independent-draw standard error can substantially misstate this error.

For a variance component, the relevant serial dependence is especially important. Estimating a posterior variance involves squared deviations from a posterior mean, and those squared deviations can be more strongly autocorrelated than the original draws. The Monte Carlo standard error (MCSE) must therefore be based on the sequence of squared deviations, or an equivalent variance-estimating summary, rather than automatically reusing the dependence estimate for the raw parameter.

Definition: Let \(\psi\) be a scalar parameter or variance-component summary with posterior mean \(\mu=E(\psi\mid y)\) and posterior variance \(V=E[(\psi-\mu)^2\mid y]\). For stationary MCMC draws \(\psi_1,\ldots,\psi_N\), estimate \(V\) by \(\hat V_N=N^{-1}\sum_{t=1}^N(\psi_t-\bar\psi)^2\), where \(\bar\psi=N^{-1}\sum_{t=1}^N\psi_t\). The MCSE of \(\hat V_N\) estimates the repeated-simulation standard deviation of this estimator, under the specified chain and posterior.

The \(N\) draws used here are post-warmup draws intended to represent a stationary chain. Warmup draws used to initialize or adapt a sampler are not treated as stationary posterior draws. The variance estimator uses divisor \(N\), because the target is the posterior expectation defining \(V\). Using \(N-1\) gives the familiar finite-sample correction for an independent sample; for a consistent MCMC estimate, the difference between these divisors is asymptotically negligible.

Deriving the Monte Carlo Standard Error

Set \(Y_t=(\psi_t-\mu)^2\). Then \(E(Y_t\mid y)=V\), and estimating the posterior variance is, to first order, estimating the posterior mean of the sequence \(Y_t\). The key distinction from an independent sample is that the variance of an average of dependent draws depends on autocovariances at all lags.

Assumptions for the standard MCSE: The retained chain is stationary with the intended posterior as its marginal distribution; a central limit theorem applies to the summary being averaged; and the long-run variance is finite. For the variance summary, this typically requires adequate tail control, including a finite fourth posterior moment of \(\psi\), together with sufficiently weak dependence for the autocovariances of squared deviations to be summable. A finite fourth moment alone does not guarantee a reliable finite-run estimate.

Write \(\gamma_k=\operatorname{Cov}(Y_t,Y_{t+k}\mid y)\). If these autocovariances are summable, the long-run variance of the mean of \(Y_t\) is \(\Omega_Y=\gamma_0+2\sum_{k=1}^{\infty}\gamma_k\). The asymptotic variance of its sample mean is \(\Omega_Y/N\). The estimated center \(\bar\psi\) does not change this first-order result:

$$ \hat V_N = \frac{1}{N}\sum_{t=1}^N(\psi_t-\mu)^2-(\bar\psi-\mu)^2 $$

Under a central limit theorem for \(\bar\psi\), \(\bar\psi-\mu=O_p(N^{-1/2})\), so \((\bar\psi-\mu)^2=O_p(N^{-1})\). Multiplication by \(\sqrt{N}\) makes this centering correction \(o_p(1)\). Thus the asymptotic fluctuation of \(\hat V_N\) is the same as that of the average of \(Y_t\).

$$ \sqrt{N}(\hat V_N-V)\ \xrightarrow{d}\ N(0,\Omega_Y), \qquad \operatorname{MCSE}(\hat V_N)\ \approx\ \sqrt{\frac{\Omega_Y}{N}}. $$

In practice, \(\mu\) is unknown, so calculate \(h_t=(\psi_t-\bar\psi)^2\) and estimate the long-run variance of the \(h_t\) sequence. Centering \(h_t\) by its sample mean gives the same autocovariance calculation. This is a plug-in estimate: it replaces unknown posterior quantities with their MCMC estimates.

Estimating Long-Run Variance

Two common approaches are batch means and a lag-window estimate of the autocovariance sum. Both target the long-run variance of the variance-summary sequence, not that of the raw parameter sequence.

Batch-means estimate: Divide \(N=Kb\) consecutive summary values \(h_t\) into \(K\) nonoverlapping batches of length \(b\). Let \(\bar h_j\) be the mean in batch \(j\), and let \(\bar h\) be the mean of all \(h_t\). Estimate the long-run variance by \(\hat\Omega_{\mathrm{BM}}=\frac{b}{K-1}\sum_{j=1}^K(\bar h_j-\bar h)^2\), then estimate the MCSE by \(\sqrt{\hat\Omega_{\mathrm{BM}}/N}\).

The factor \(b\) is essential: the sample variance of the batch means estimates the variance of a batch average, which is approximately \(\Omega_Y/b\). Multiplying by \(b\) puts the estimate on the long-run-variance scale. The batch length should be long enough that dependence across batch means is limited, while leaving enough batches to estimate their variability. Too few batches make the estimate noisy; very short batches may fail to capture dependence.

Alternatively, estimate autocovariances \(\hat\gamma_k\) of the \(h_t\) sequence and calculate a windowed sum such as \(\hat\Omega=\hat\gamma_0+2\sum_{k=1}^{L}w_k\hat\gamma_k\), where \(w_k\) decreases toward zero as lag \(k\) approaches the chosen truncation \(L\). Truncation and weighting matter because the empirical autocovariances at large lags are noisy. Batch means and spectral or lag-window estimates are alternative numerical estimators of the same long-run variance; neither removes the need for adequate chain length and stationarity.

Worked Example: Autocorrelation Inflates the MCSE

Suppose a hypothetical stationary chain estimates a posterior variance \(V\) for a variance component \(\psi\), and \(N=600\) post-warmup draws are retained. In this example, the empirical variance of the squared-deviation summary is \(12\) in the appropriate fourth-power units, and its autocorrelation is approximately \(\rho_k=0.5^k\). Assume this geometric pattern is a reasonable approximation over the lags that matter.

The long-run variance is the variance of the summary multiplied by its integrated autocorrelation factor:

$$ \hat\Omega \approx 12\left(1+2\sum_{k=1}^{\infty}0.5^k\right) = 12\left(1+2\frac{0.5}{1-0.5}\right) = 12(3)=36. $$

Therefore, the estimated MCSE of the posterior variance estimate is \(\sqrt{36/600}=\sqrt{0.06}=0.2449\), in the units of \(V\). If the draws were incorrectly treated as independent, the calculation would instead be \(\sqrt{12/600}=\sqrt{0.02}=0.1414\). That smaller value ignores positive autocorrelation in the squared deviations and understates the simulation error under the stated approximation.

Worked Example: Batch Means From Hypothetical Variance-Component Draws

Consider eight hypothetical post-warmup draws of a nonnegative variance component, in squared latent-scale units: \(1, 2, 3, 2, 0.5, 2, 3.5, 2\). This short sequence is for illustrating the arithmetic only; it is not long enough to support a dependable real-world MCSE.

The sample mean is \(\bar\psi=16/8=2\). The squared deviations are \(1,0,1,0,2.25,0,2.25,0\), so the estimated posterior variance is \(\hat V_8=(1+0+1+0+2.25+0+2.25+0)/8=6.5/8=0.8125\), in fourth-power latent-scale units.

Now form the summary values \(h_t=(\psi_t-\bar\psi)^2\) and subtract their mean, \(0.8125\). The centered sequence is \(0.1875,-0.8125,0.1875,-0.8125,1.4375,-0.8125,1.4375,-0.8125\). With batch length \(b=2\), there are \(K=4\) batch means: \(-0.3125,-0.3125,0.3125,0.3125\). Their grand mean is zero.

The batch-means long-run-variance estimate is \(\hat\Omega_{\mathrm{BM}}=\frac{2}{3}[4(0.3125^2)]=0.2604\). Hence the estimated MCSE is \(\sqrt{0.2604/8}=\sqrt{0.03255}=0.1804\), in the same units as \(\hat V_8\). This value is only an illustration of the formula: four batches cannot provide a stable estimate of long-run variance.

Use the Dependence of the Summary Being Estimated

The effective sample size for a posterior mean of \(\psi\) is based on the serial dependence of \(\psi_t\). The MCSE for a posterior variance instead depends on the serial dependence of \((\psi_t-\mu)^2\). These can differ substantially. In particular, a chain can move smoothly through the center of a distribution while taking much longer to explore its tails; squared deviations then persist, making the variance summary mix slowly.

Worked Example: A Summary-Specific Effective Sample Size

Suppose \(N=1000\) hypothetical draws estimate a posterior variance of a variance component. Let the empirical variance of the squared-deviation summary be \(50\) in units that make the target variance estimate’s MCSE expressible in the same units. Suppose the summary’s autocorrelation is approximately geometric with first-lag correlation \(0.25\). For this approximation, its integrated autocorrelation factor is \((1+0.25)/(1-0.25)=1.6667\).

The estimated effective sample size for this summary is \(1000/1.6667\approx600\). Equivalently, \(\hat\Omega\approx50(1.6667)=83.33\), giving \(\operatorname{MCSE}\approx\sqrt{83.33/1000}=\sqrt{0.08333}=0.2887\). The independent-draw calculation would be \(\sqrt{50/1000}=0.2236\), which is too small under the assumed positive dependence.

This calculation uses the effective sample size of the squared-deviation summary, not an effective sample size previously calculated for the raw draws. Its value is only as credible as the autocorrelation approximation and the chain’s stationarity.

Diagnostics, Alternatives, and Limitations

A reported MCSE should be treated as an estimate, not as a guarantee that the simulation has explored the posterior adequately. Compare estimates from reasonable batch lengths or lag windows, and check whether the variance estimate and its MCSE are stable as more stationary draws are added. Strong changes across these choices indicate that the run may be too short to estimate long-run dependence reliably. Unstable tail exploration is particularly consequential because squared deviations give large weight to distant draws.

An MCSE calculation also cannot repair a chain that has not reached its stationary target. Nor does a small estimated MCSE by itself establish that the model, prior, or sampler is appropriate. Check chain behavior and mixing using the diagnostics introduced in earlier material on MCMC mixing and effective sample size before relying on variance-summary precision. Heavy-tailed posteriors or poorly explored tails can make the fourth-moment condition doubtful and the variance-summary MCSE unstable.

ApproachWhat it estimatesMain caution
Independent-draw formulaUses only the variance of the squared-deviation summaryUnderstates error when positive serial dependence is ignored
Batch meansLong-run variance from variation across batchesDepends on batch length and having enough batches
Lag-window autocovarianceLong-run variance from weighted autocovariancesDepends on lag truncation and noisy large-lag estimates
More stationary drawsReduces MCSE at approximately the inverse square-root rate when conditions holdDoes not fix nonstationarity or inadequate tail exploration
Common mistake: “The raw variance-component draws have an effective sample size of 800, so I can use 800 to calculate the MCSE of their posterior variance.” This is not generally valid. The variance estimator averages squared deviations, whose autocorrelation can differ from that of the raw draws. Calculate dependence or effective sample size for the squared-deviation sequence itself, or estimate its long-run variance directly.

When the long-run variance is estimated adequately, the MCSE describes numerical precision, not posterior spread. A large posterior variance can be estimated precisely, and a modest posterior variance can have a large MCSE if the chain explores its squared deviations slowly. Under the central limit theorem conditions, increasing the number of stationary draws by a factor of four approximately halves the MCSE, since it scales as \(N^{-1/2}\). This improvement does not apply if the additional draws do not represent the target posterior or if the relevant long-run variance is not finite.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. Why is the MCSE for a posterior variance based on squared deviations rather than automatically on the raw parameter draws?
  2. A squared-deviation summary has variance \(9\), integrated autocorrelation factor \(2\), and \(N=450\) draws. Calculate the approximate MCSE.
  3. For batch means with batch length \(b=5\), \(K=6\), and \(\sum_{j=1}^K(\bar h_j-\bar h)^2=0.30\), calculate the long-run-variance estimate and the MCSE.
  4. Does a small MCSE prove that an MCMC chain has reached stationarity? Explain briefly.

Solutions. (1) The posterior variance estimator averages squared deviations, so its sampling variability depends on the serial dependence of those deviations; raw-draw dependence need not match it. (2) The long-run variance is \(9(2)=18\), so the MCSE is \(\sqrt{18/450}=\sqrt{0.04}=0.200\). (3) \(\hat\Omega_{\mathrm{BM}}=[5/(6-1)](0.30)=0.300\). Since \(N=Kb=30\), the MCSE is \(\sqrt{0.300/30}=\sqrt{0.01}=0.100\). (4) No. An MCSE estimates finite-simulation error under assumptions including stationarity; it cannot establish that those assumptions hold.

Clinical Biostats