Tutorials › Generalized Linear Mixed Models (GLMM) › Residual Dependence Within Clusters

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

Residual Dependence Within Clusters

Use ordered residual patterns and simulated within-cluster statistics to assess whether a fitted GLMM leaves dependence unexplained.

Intermediate 11 min read

What You'll Learn

  • Distinguish dependence represented by fitted random effects from residual dependence that remains after fitting.
  • Choose and order residuals for a within-cluster diagnostic.
  • Calculate an adjacent-residual product statistic and interpret its direction.
  • Calibrate a residual statistic against simulations from the specified GLMM.
  • Recognize when cluster boundaries, sparse outcomes, or the choice of statistic can mislead.
  • Compare residual-dependence checks with broader distributional and dispersion checks.

Why Check Dependence After Fitting Random Effects?

Repeated observations from the same cluster are often related. A GLMM can represent some of that relationship through its specified random effects. The diagnostic question here is narrower: after accounting for those random effects and the fixed effects, do the ordered residuals still show within-cluster structure? For example, residuals that stay positive for several visits and then stay negative may indicate a time pattern that the fitted model has not captured.

The distinction matters because observations can be correlated marginally even when the model is adequate. A shared random intercept, for instance, can make outcomes within a cluster resemble one another. That dependence is already part of the model. A residual-dependence check should ask whether the observed pattern is unusual under the fitted model, including its random-effects structure—not whether the outcomes are associated in the first place.

Definition: Residual dependence within clusters is systematic association among residuals from observations in the same cluster that remains after accounting for the fitted GLMM. An ordered residual display places each cluster’s residuals in their meaningful sequence, such as visit time or spatial order. A simulation-calibrated statistic summarizes a chosen pattern in that display and compares it with the same statistic calculated from data simulated under the fitted model.

Residuals, Ordering, and the Model Assumptions

Let \(Y_{ij}\) denote the response at ordered occasion \(j\) in cluster \(i\), and let \(b_i\) denote the cluster’s random effects. Under the fitted GLMM, the observations are assumed conditionally independent given \(b_i\) and the covariates, unless the model explicitly includes an additional dependence structure. The model also specifies the conditional mean and variance of each response. A residual diagnostic looks for a violation of that conditional-independence assumption, not for dependence that the random effects were included to represent.

A common residual for a count or binary observation is the conditional Pearson residual \(r_{ij}=(y_{ij}-\hat{\mu}_{ij})/\sqrt{\widehat{V}_{ij}}\), where \(\hat{\mu}_{ij}\) and \(\widehat{V}_{ij}\) are the fitted conditional mean and variance. The exact residual choice depends on the outcome and fitting procedure. For discrete outcomes, residuals can be coarse or tied; randomized quantile residuals are one alternative. Whichever definition is used, apply it consistently to the observed data and every simulated replicate.

An ordered display typically plots residual against occasion within each cluster, with clusters separated or clearly identified. Look for runs of the same sign, alternating signs, gradual drift, or a repeating pattern. Connect residuals only within their own cluster: the last observation of one cluster is not adjacent to the first observation of another. The order must have scientific meaning. Arbitrarily sorting residuals by size manufactures a pattern rather than diagnosing one.

A useful summary for lag-one dependence is the mean adjacent residual product. Let \(\mathcal{P}\) be the set of all pairs of consecutive observations within clusters, and let \(M\) be the number of such pairs. Define

$$ T_{\text{adj}}=\frac{1}{M}\sum_{(i,j)\in\mathcal{P}} r_{ij}r_{i,j+1}. $$

Large positive products tend to occur when neighboring residuals have the same sign; large negative products tend to occur when they have opposite signs. The statistic is not, by itself, a universal test with a fixed reference distribution. Its null behavior depends on the outcome distribution, fitted means, cluster sizes, random-effects structure, residual definition, and parameter estimation.

Why Simulation Is Needed

The rationale for \(T_{\text{adj}}\) follows from the model assumption. If residuals have conditional mean zero and are conditionally independent across consecutive observations, then, for fixed model quantities,

$$ E(r_{ij}r_{i,j+1}\mid b_i,\mathbf{x})= E(r_{ij}\mid b_i,\mathbf{x})E(r_{i,j+1}\mid b_i,\mathbf{x})=0. $$

Thus the adjacent product has expected value zero under idealized conditions. In an actual fitted GLMM, parameters and random effects are estimated, residuals need not have exactly zero mean or unit variance, and discrete residuals may have non-normal shapes. Consequently, zero is not a reliable universal cutoff, nor does a standard normal reference automatically apply. Simulation supplies a reference distribution that reflects the fitted model and the diagnostic procedure.

Generate replicated outcomes under the specified GLMM, calculate residuals for each replicate by the same method, and recompute \(T_{\text{adj}}\). To isolate dependence beyond the modeled random effects, the simulation must preserve the fitted random-effects structure. Whether to condition on fitted cluster effects or draw new effects depends on the diagnostic question; the earlier material on conditional versus unconditional replications gives that distinction. If parameter estimation materially affects the residuals, refitting each replicate in a parametric bootstrap can reflect that step as well.

For \(B\) simulated statistics \(T^{(1)},\ldots,T^{(B)}\), compare \(T_{\text{obs}}\) with their distribution. A standardized descriptive measure is \(Z_{\text{sim}}=(T_{\text{obs}}-\bar{T}_{\text{sim}})/s_{\text{sim}}\), where \(\bar{T}_{\text{sim}}\) and \(s_{\text{sim}}\) are the simulated mean and standard deviation. For a prespecified positive-dependence check, an upper-tail Monte Carlo probability is \(p=(1+\#\{T^{(b)}\geq T_{\text{obs}}\})/(B+1)\). For a two-sided check, define the extremeness rule in advance—for example, compare absolute deviations from the simulated mean. Such simulated probabilities are diagnostic evidence under the fitted model; they are not a probability that the model is true.

Worked Example: A Positive Adjacent-Residual Pattern

Suppose a hypothetical binary-outcome GLMM includes a cluster random intercept and the specified visit covariates. For illustration, conditional Pearson residuals from two clusters, in visit order, are \(1.5, 1.2, 0.8, -0.2\) and \(-0.8, -0.6, 0.9\). There are three adjacent pairs in the first cluster and two in the second, so \(M=5\).

The products in the first cluster are \(1.5(1.2)=1.80\), \(1.2(0.8)=0.96\), and \(0.8(-0.2)=-0.16\), with sum \(2.60\). In the second they are \((-0.8)(-0.6)=0.48\) and \((-0.6)(0.9)=-0.54\), with sum \(-0.06\). Therefore,

$$ T_{\text{obs}}=\frac{2.60-0.06}{5}=0.508. $$

Now suppose 999 simulations from the fitted model, with the same residual construction, give \(\bar{T}_{\text{sim}}=0.020\), \(s_{\text{sim}}=0.180\), and 8 simulated statistics at least \(0.508\). The standardized descriptive value is \((0.508-0.020)/0.180=2.71\). The upper-tail Monte Carlo probability is \((8+1)/(999+1)=0.00900\). If positive dependence was the prespecified direction, this is evidence that the observed adjacent products are unusually large under the fitted model. It does not establish a particular cause; the display and other model checks are needed to investigate the pattern.

Worked Checks and the Importance of Sequence

Worked Example: The Same Residuals in a Different Order

A hypothetical cluster has four residuals with values \(1.2,-1.0,1.1,-0.9\). In the recorded sequence, the adjacent products are \(-1.20\), \(-1.10\), and \(-0.99\), so \(T_{\text{adj}}=(-1.20-1.10-0.99)/3=-1.097\), to three decimal places. This sequence alternates signs, giving negative adjacent products.

If the same four values were instead ordered \(1.2,1.1,-0.9,-1.0\), their products would be \(1.32,-0.99,0.90\), and \(T_{\text{adj}}=(1.32-0.99+0.90)/3=0.410\). The residual values have not changed, but the diagnostic conclusion about local ordering has. Therefore, the sequence must be defined by the study design—such as time—and preserved in every simulation.

Worked Example: A Sign-Run Statistic

Adjacent products can be dominated by a few large residuals. As a complementary, magnitude-insensitive summary, consider the number of adjacent pairs with matching signs. In a hypothetical analysis with 12 within-cluster adjacent pairs, suppose 10 have matching signs. Simulations under the fitted model give a mean of 6.1 matching pairs and a standard deviation of 1.7; among 999 replicates, 17 have at least 10.

The standardized descriptive value is \((10-6.1)/1.7=2.29\). The upper-tail Monte Carlo probability is \((17+1)/(999+1)=0.0180\). This indicates more sign persistence than typical in the simulated data. The statistic ignores residual magnitudes, so it can detect a long run of modest same-sign residuals but will not distinguish that from a run involving very large residuals. It complements rather than replaces the ordered plot or product statistic.

Diagnostics, Alternatives, and Limitations

Interpret the statistic alongside the display. A large positive adjacent-product statistic accompanied by runs of same-sign residuals suggests persistence; a negative value and frequent sign changes suggest alternation. Either direction may be relevant, depending on the scientific setting and the diagnostic question. A single summary can conceal local behavior: positive dependence in some clusters may cancel negative dependence in others. Inspect cluster-specific displays and consider summaries suited to the suspected pattern, such as a sign-run count or a prespecified longer lag.

Compare this check with other diagnostics rather than substituting one for another. Global dispersion or tail-count checks ask whether variability or extremes are unusual overall; they do not locate a sequence pattern. A marginal correlation of the raw outcomes mixes dependence represented by random effects with any remaining dependence. A residual autocorrelation display can make lag patterns visible, while a simulation-based statistic gives a calibrated summary of a chosen feature. None identifies the correct replacement model automatically.

Several failures can invalidate the interpretation:

  • Ignoring the cluster boundaries. Pairing the final residual of one cluster with the first of another creates nonexistent adjacency. Construct pairs separately within each cluster.
  • Using the wrong order. An arbitrary order, or an order that does not represent time or another meaningful sequence, cannot support a within-cluster serial interpretation.
  • Comparing with zero or a textbook cutoff alone. The fitted model and estimation procedure affect the statistic’s distribution. Use simulations that reproduce the relevant fitting and residual steps.
  • Simulating from an incomplete model. Omitting the fitted random effects can make ordinary modeled dependence look like a residual failure. Include the specified structure in the simulation.
  • Relying on one statistic. A lag-one product is poorly suited to patterns at other lags, nonlinear cycles, or dependence limited to a few clusters. Inspect displays and choose additional summaries for specific concerns.

Simulation does not repair a misspecified mean, incorrect observation order, or inappropriate residual definition. Sparse outcomes can also yield tied or highly discrete residuals, making the simulated reference distribution coarse. Further, trying many statistics and reporting only the most extreme one exaggerates the apparent evidence; the chosen summaries and direction should be stated transparently. A diagnostic flags a mismatch with the fitted model, but does not by itself prove that a new dependence term is needed or that any proposed term is correct.

Key takeaway: Diagnose residual dependence by preserving the meaningful order within each cluster, using a consistent residual definition, and comparing an interpretable statistic with simulations that retain the specified random-effects structure. A plot, statistic, and model-based reference distribution answer complementary parts of the question.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. Why does within-cluster correlation in raw outcomes not by itself show residual dependence after fitting a random-intercept GLMM?
  2. Four ordered residuals are \(0.5, 1.0, -0.5, -1.0\). Calculate the mean adjacent product.
  3. In 499 simulations, 14 statistics are at least as large as the observed statistic. Calculate the upper-tail Monte Carlo probability using the plus-one formula.
  4. Why must residuals from different clusters not be paired when calculating an adjacent-product statistic?

Solutions: (1) The random intercept can induce within-cluster association, which is already represented by the model; the check concerns association remaining after that structure is accounted for. (2) The products are \(0.5\), \(-0.5\), and \(0.5\), so their mean is \((0.5-0.5+0.5)/3=0.167\). (3) The probability is \((14+1)/(499+1)=15/500=0.0300\). (4) Observations in different clusters are not consecutive within the same ordered sequence, so pairing them creates a dependence comparison that the data structure does not define.

Clinical Biostats