Tutorials › Generalized Linear Mixed Models (GLMM) › Checking Random-Effects Variance Through Replication

Diagnostics and Predictive Checks for Sparse and Overdispersed Outcomes · Tutorial 638 of 698

Checking Random-Effects Variance Through Replication

Use replicated cluster-level outcomes to assess whether a fitted random-effects variance reproduces the observed heterogeneity, while accounting for within-cluster sampling variation.

Intermediate 11 min read

What You'll Learn

  • Define a cluster-level discrepancy for checking heterogeneity under a fitted GLMM.
  • Distinguish replication of random effects from replication conditional on estimated effects.
  • Explain why cluster size and outcome sampling variation affect observed spread.
  • Calculate upper- and lower-tail predictive proportions from replicated statistics.
  • Interpret checks as diagnostic evidence rather than formal proof of model adequacy.
  • Identify limitations of raw cluster-spread statistics and alternatives for further investigation.

Why Check Random-Effects Variance Through Replication?

A random-effects variance describes how much clusters differ in their latent effects, but those effects are not observed directly. Instead, each cluster supplies outcomes subject to within-cluster sampling variation. A cluster with a small sample can have an unusual observed rate even when its latent effect is ordinary; conversely, shrinkage can make estimated cluster effects look less dispersed than the underlying effects. A useful diagnostic therefore asks whether outcomes generated by the fitted model show cluster-to-cluster variation like the variation actually observed.

The check is a predictive comparison. Fit the GLMM, calculate a statistic describing cluster-level spread in the observed data, and calculate the same statistic for data replicated under the fitted model. If the observed statistic lies far into a tail of the replicated values, that is evidence that the fitted model does not reproduce this aspect of cluster heterogeneity. It is not, by itself, proof that the random-effects variance alone is wrong: fixed effects, the random-effects distribution, dependence assumptions, and the outcome sampling model can all affect the comparison.

Definition: A replicated cluster-variation check compares a statistic \(T_{\mathrm{obs}}\), calculated from the observed cluster outcomes, with statistics \(T^{(1)},\ldots,T^{(B)}\) calculated in \(B\) data sets generated under the fitted GLMM. For an unconditional replication, each replicate draws new random effects from the fitted random-effects distribution and then generates outcomes conditional on those effects. The observed and replicated statistics must use the same definition and the same cluster design.

A Cluster-Level Discrepancy

For a binary outcome, suppose cluster \(i\) has \(n_i\) observations and \(Y_i\) successes. Its observed proportion is \(\hat{p}_i=Y_i/n_i\). Let \(m_i\) be the fitted marginal mean for that cluster: the model-based expected proportion after averaging over the fitted random-effects distribution. For a random-intercept logistic model, for example, \(m_i\) is the expectation of the inverse-logit probability over a random intercept with the fitted variance. It can be calculated by numerical integration or simulation.

One simple discrepancy is the mean squared deviation of cluster proportions from their fitted marginal means:

$$ T_{\mathrm{obs}}=\frac{1}{K-1}\sum_{i=1}^{K}(\hat{p}_i-m_i)^2, $$

where \(K\) is the number of clusters. The denominator \(K-1\) provides a convenient scale; it does not make this statistic an unbiased estimator of the random-effects variance. In a replicate, use its simulated cluster proportions and the corresponding fitted means, with the design and model parameters handled consistently. With covariates, \(m_i\) can differ across clusters, so comparing raw proportions to one common average would confuse fitted mean differences with unexplained heterogeneity.

For counts, an analogous statistic can use cluster-specific rates, with exposure handled in the fitted means and the same exposure values retained in each replicate. The precise discrepancy should match the outcome and design. Whatever the choice, the replicated distribution is essential: it reflects both the latent cluster-to-cluster variation and the within-cluster noise expected under the fitted model.

Why Replication Includes Sampling Variation

The distinction between latent heterogeneity and observed spread follows from the law of total variance. For a binomial cluster with common size \(n\), let \(p_i(b_i)\) be its success probability conditional on random effect \(b_i\), and let \(\hat{p}_i=Y_i/n\). Conditional on \(b_i\), the variance of the proportion is \(p_i(b_i)\{1-p_i(b_i)\}/n\), and its conditional mean is \(p_i(b_i)\). Therefore:

$$ \operatorname{Var}(\hat{p}_i) = \operatorname{Var}_{b_i}\{p_i(b_i)\} + E_{b_i}\left[\frac{p_i(b_i)\{1-p_i(b_i)\}}{n}\right]. $$

The first term is variation among the cluster probabilities induced by the random effects. The second is binomial sampling variation within clusters. A statistic formed from observed proportions contains both contributions. Replicating outcomes under the fitted model naturally includes both; comparing observed spread directly with the fitted random-effects variance would not.

This identity also explains why unequal cluster sizes matter. The sampling component is generally larger for smaller \(n_i\). A check that ignores the actual cluster sizes can make a reasonable fitted variance look too small or too large. Replicates should retain the observed cluster sizes, covariate patterns, and exposures relevant to the model.

Worked Example: Calculating the Observed Spread

Suppose eight hypothetical clusters have the following residual proportions, \(\hat{p}_i-m_i\), after fitting a binary-outcome GLMM: \(-0.06,-0.04,-0.02,0,0.02,0.04,0.06,0\). These values are proportion differences, not percentage-point counts. Calculate the discrepancy.

Using the definition above, square each residual and add:

$$ \begin{aligned} \sum_{i=1}^{8}(\hat{p}_i-m_i)^2 &=(-0.06)^2+(-0.04)^2+(-0.02)^2+0^2\\ &\quad +(0.02)^2+(0.04)^2+(0.06)^2+0^2\\ &=2(0.0036)+2(0.0016)+2(0.0004)\\ &=0.0072+0.0032+0.0008\\ &=0.0112. \end{aligned} $$

There are \(K=8\) clusters, so:

$$ T_{\mathrm{obs}}=\frac{0.0112}{8-1}=0.001600. $$

This number alone does not tell us whether heterogeneity is unusually large. Its interpretation depends on the distribution of this same statistic under replicated data from the fitted model.

Constructing and Interpreting the Replicated Distribution

For a random-intercept model, an unconditional parametric replication draws a new intercept for every cluster from the fitted random-effects distribution, then draws outcomes from the fitted conditional outcome distribution. For a binary GLMM, this means drawing the random effects and then drawing binomial outcomes using the resulting probabilities. The same cluster sizes and covariates are used as in the observed data. This procedure asks whether the fitted population distribution of random effects, together with the rest of the model, can reproduce the observed cluster spread.

For each replicate \(b\), calculate \(T^{(b)}\) exactly as \(T_{\mathrm{obs}}\) was calculated. An estimated upper-tail predictive proportion is:

$$ \hat{q}_{\mathrm{upper}} = \frac{1+\sum_{b=1}^{B} I(T^{(b)}\geq T_{\mathrm{obs}})}{B+1}, $$

where \(I(\cdot)\) equals 1 when its statement is true and 0 otherwise. A small upper-tail proportion indicates that replicated data rarely have at least as much spread as observed. A correspondingly small lower-tail proportion indicates that the observed spread is unusually low under the fitted model. The added 1 in numerator and denominator avoids reporting a simulated tail proportion of exactly zero; it does not turn the check into a calibrated hypothesis test.

When model parameters are treated as fixed at their estimates, this is a plug-in predictive check. Parameter uncertainty can be incorporated by drawing parameters from a fitted posterior distribution or by using a parametric bootstrap that refits the model in each simulated data set. These approaches answer related but not identical questions. The replication scheme and whether the model is refitted should be reported because both affect the reference distribution.

Worked Example: An Upper-Tail Check

Use the observed statistic \(T_{\mathrm{obs}}=0.001600\) from the first example. In 999 hypothetical replications from the fitted model, 74 statistics are at least as large as \(T_{\mathrm{obs}}\). The plus-one estimate is:

$$ \hat{q}_{\mathrm{upper}}=\frac{1+74}{999+1}=\frac{75}{1000}=0.0750. $$

The observed spread is not especially extreme in this upper-tail comparison: about 7.5% of the simulated reference outcomes have a statistic at least this large under the stated procedure. This does not establish that the variance is correct. It indicates that this particular check has not produced strong evidence of excess spread relative to the fitted model. Other discrepancies or model assumptions may still be problematic.

Worked Example: Correctly Recomputing a Lower-Tail Check

In a second hypothetical check with seven clusters, the residual proportions are \(0.02,0.01,0,0,0.01,0.01,0.01\). Calculate the observed discrepancy using the same squared-residual definition, then compare it with 2,000 replicated statistics.

The sum of squared residuals is:

$$ 0.02^2+0.01^2+0^2+0^2+0.01^2+0.01^2+0.01^2 =0.0004+4(0.0001)=0.0008. $$

With \(K=7\), the statistic is:

$$ T_{\mathrm{obs}}=\frac{0.0008}{7-1}=0.0001333. $$

Suppose 41 of the 2,000 replicated statistics are less than or equal to this value. The lower-tail estimate is:

$$ \hat{q}_{\mathrm{lower}}=\frac{1+41}{2000+1}=\frac{42}{2001}\approx 0.0210. $$

Thus, the observed discrepancy is unusually small relative to these replications: about 2.1% of the replicated statistics are no larger. This may indicate that the fitted model tends to generate more cluster spread than observed. It is not a probability that the model or its variance parameter is correct or incorrect.

Worked Model-Based Check

Worked Example: Interpreting Heterogeneity in a Binary GLMM

Consider hypothetical data from eight clusters, each with 20 individuals. The observed numbers of successes are \(2,2,4,4,6,8,10,12\), giving proportions \(0.10,0.10,0.20,0.20,0.30,0.40,0.50,0.60\). The fitted model is a random-intercept logistic GLMM with estimated fixed intercept \(\hat{\beta}_0=-0.90\) and random-intercept standard deviation \(\hat{\tau}=0.55\). For illustration, numerical integration gives a fitted marginal mean close to \(0.30\) for each cluster.

The observed proportions average \(0.30\). Using \(m_i=0.30\), the deviations are \(-0.20,-0.20,-0.10,-0.10,0,0.10,0.20,0.30\). Their squared sum is:

$$ 0.04+0.04+0.01+0.01+0+0.01+0.04+0.09=0.24. $$

Therefore, \(T_{\mathrm{obs}}=0.24/7=0.03429\). Now generate 1,000 unconditional replications, drawing eight random intercepts from \(N(0,0.55^2)\), generating 20 binary outcomes per cluster conditional on each draw, and calculating the same discrepancy. Suppose the replicated median is \(0.025\), the 95th percentile is \(0.065\), and 180 replicated statistics are at least \(0.03429\). Then:

$$ \hat{q}_{\mathrm{upper}}=\frac{1+180}{1000+1}\approx 0.1808. $$

The observed statistic falls below the simulated 95th percentile, and its upper-tail proportion is about 18.1%. This check does not suggest unusually large spread for this fitted model. The clusters differ substantially in their observed proportions, but the simulations show that similar variation can arise from the fitted random intercepts together with binomial sampling at the stated cluster size. The conclusion is limited to this discrepancy and this replication design.

Choosing Among Diagnostic Comparisons

The replication check is most informative when the statistic isolates the feature of interest and the simulation reproduces the fitted design. Several alternatives can be useful, but they answer different questions.

ApproachWhat it comparesMain caution
Replicated cluster-outcome spreadObserved cluster-level variation with variation in outcomes generated under the fitted modelIncludes both random-effect variation and outcome sampling noise
Variance of estimated cluster effectsSpread of estimated or empirical Bayes effects with a reference valueShrinkage and estimation uncertainty affect the apparent spread
Conditional replicationNew outcomes while retaining estimated cluster effectsDoes not directly test whether the population random-effects distribution reproduces cluster heterogeneity
Unconditional replicationNew random effects and new outcomes under the fitted population modelCan be sensitive to fitted parameters and to the chosen discrepancy

A variance of estimated cluster effects may appear to be a direct check of the random-effects variance, but the two quantities are not interchangeable. Estimated effects are informed by finite, noisy cluster data and are commonly shrunk toward the population mean. The replicated-outcome approach instead asks whether the full fitted model reproduces an observable implication of the variance component. It does not remove the need to examine the random-effects distribution shape, outcome fit, and influential clusters.

Diagnostics, Failure Modes, and Limits

A very large upper-tail discrepancy suggests that observed clusters are more separated than the fitted model typically produces. A very small lower-tail discrepancy suggests the model tends to produce more separation than observed. Either finding calls for investigation, not an automatic change to the variance estimate. Check whether the statistic was computed consistently, whether cluster sizes and covariates were retained, and whether a few clusters dominate the statistic. Cluster-level influence diagnostics can help determine whether the pattern is driven by one or two clusters.

A common mistake is to compare the observed variance of cluster proportions directly with \(\hat{\tau}^2\), then declare the random-effects variance too small if the former is larger. These quantities are on different scales: proportions include binomial sampling variation, while \(\hat{\tau}^2\) is variance on the latent random-effect scale. The correction is to compare an observed-data discrepancy with the same discrepancy from data simulated under the fitted model, which carries sampling variation and the link function through the calculation.

  • Unequal cluster sizes: Small clusters have noisier proportions. Preserve their sizes in every replicate.
  • Inadequate statistic: A single overall spread measure can miss specific patterns, such as a few extreme clusters. Use a complementary discrepancy when the scientific concern calls for it.
  • Parameters estimated from the data: A plug-in reference distribution may not fully reflect parameter uncertainty. State whether parameters were fixed, drawn, or re-estimated.
  • Small numbers of clusters: Replication cannot create information about the random-effects distribution that the data do not contain. Tail proportions may be imprecise, and the fitted variance itself may be weakly determined.
  • Model misspecification beyond the variance: A tail result can reflect an incorrect mean structure, random-effects distribution, or conditional outcome model, not only a misestimated variance.

Predictive tail proportions are diagnostic summaries, not conventional p-values with a guaranteed reference distribution under a null hypothesis. A moderate tail proportion is not evidence that every model assumption holds, and a small one does not identify a unique correction. The result should be interpreted alongside the model specification and other checks of outcome fit.

Key takeaway: To assess whether a fitted random-effects variance reproduces cluster heterogeneity, compare an observed cluster-level discrepancy with the same statistic from data replicated under the fitted model. Retain the observed design and include new random effects when the diagnostic target is population-level cluster variation.

Check Your Understanding

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

  1. Why is the variance of observed cluster proportions generally not equal to the random-intercept variance?
  2. For five clusters with squared residuals summing to \(0.008\), calculate \(T_{\mathrm{obs}}\) using the defined discrepancy.
  3. In 499 replications, 9 statistics are at least as large as the observed statistic. Calculate the plus-one upper-tail estimate and interpret it.
  4. Why should an unconditional replication draw new random effects rather than retain the estimated cluster effects when checking population heterogeneity?
  5. What design information should be retained when replicating a GLMM with unequal cluster sizes and covariates?

Solutions. (1) Observed proportions contain both between-cluster variation in probabilities induced by random effects and within-cluster sampling variation; the two also lie on different scales. (2) \(T_{\mathrm{obs}}=0.008/(5-1)=0.002\). (3) The estimate is \((1+9)/(499+1)=10/500=0.0200\); about 2% of replicated statistics are at least as large, which is evidence of unusually large observed spread for this check, not the probability that the model is true. (4) Retaining estimated effects conditions on the observed clusters and does not check whether draws from the fitted population random-effects distribution reproduce their heterogeneity. (5) Retain cluster sizes, covariate patterns, and relevant exposures so outcome noise and fitted means are comparable between observed and replicated data.

Clinical Biostats