Tutorials › Generalized Linear Mixed Models (GLMM) › Residual Plots for Sparse Count GLMMs

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

Residual Plots for Sparse Count GLMMs

Build count-specific residual displays and interpret their patterns without mistaking discreteness or cluster dependence for model failure.

Intermediate 12 min read

What You'll Learn

  • Choose a residual scale that is informative for sparse counts.
  • Plot residuals against fitted means while accounting for the discreteness of the response.
  • Use covariate displays to find patterns hidden by an overall fit summary.
  • Distinguish descriptive residual patterns from formal evidence of model failure.
  • Use simulation envelopes that reproduce the fitted GLMM structure.
  • Recognize how zero-heavy counts and within-cluster dependence complicate interpretation.

Why plot residuals for sparse counts?

A count GLMM can summarize an outcome well on average and still miss important features of its distribution. It may systematically underpredict counts at high exposure, overpredict zeros for some covariate values, or fail to capture a changing relationship between a predictor and the count. A residual plot can make such patterns visible. In sparse data, however, many observations are zero and the response has only a few possible small values. A plot that would look reassuring for a continuous response can therefore be misleading for counts.

The key is to read the display against the model’s expected count distribution, not against a normal-error template. A cloud of points need not look smooth or symmetric. Instead, look for repeated directional patterns, such as residuals tending to be negative at low fitted means and positive at high fitted means. Interpret these patterns in light of the GLMM’s cluster structure and the definition of the residual being plotted.

Definition: For count observation \(i\), let \(Y_i\) be the observed count and let \(\hat{\mu}_i\) be a fitted mean on the same prediction scale as the residual. A residual display plots a chosen residual for each observation against \(\hat{\mu}_i\), a covariate, or another specified quantity. In a sparse count GLMM, the display is a diagnostic summary: it can suggest a mismatch, but a pattern alone does not identify its cause or establish a formal test result.

For example, under a conditionally Poisson model, \(Y_i\) given the random effects has mean and variance \(\mu_i\). A conditional Pearson residual is then \(r_{Pi}=(Y_i-\hat{\mu}_i)/\sqrt{\hat{\mu}_i}\), where the fitted conditional mean uses the estimated random effects. Other residuals, including deviance, randomized quantile, and simulation-based residuals, have different scales and distributions. The earlier material on conditional and marginal fitted values and count residual definitions supplies those distinctions; here the emphasis is on how the residual displays behave.

First decide what prediction target the plot should assess. A conditional fitted value describes the response conditional on estimated cluster effects; a marginal fitted value averages over the random-effects distribution. Pair the residual definition and fitted-value scale consistently. A conditional residual against a marginal mean mixes two targets, and a resulting trend may reflect that mismatch rather than the fixed-effect structure.

What a count residual plot should show

If the model is adequate for the feature being examined, residuals should not show a reproducible structure against the fitted mean or a covariate. This does not mean each residual is close to zero, nor that residuals must look normally distributed. With sparse counts, zeros can create a dense band, and positive counts can create separate bands. The diagnostic question is whether the positions and frequency of these values are plausible under the fitted count model.

A useful first display places residuals vertically against fitted means horizontally, with a horizontal reference at zero. A smooth curve or averages within fitted-mean bins can help reveal a trend, but should not conceal the raw points. Because small fitted means are common in sparse data, the horizontal axis may be shown on its original scale or on a log scale when all plotted fitted means are positive. State which scale is used; the vertical residual remains defined on its own scale.

A second display plots the residuals against a predictor whose functional form or effect is important to the model. For a continuous predictor, show the raw residuals and, where useful, a modest smoother. For a categorical predictor, compare residual distributions or means across its levels. If counts have a known exposure or offset, a plot against fitted means may reveal whether the model misses a trend in the expected rate; the fitted mean already incorporates that offset.

A short justification explains the zero reference line. If the model is correct and its parameters and random effects are known, then for the conditional Pearson residual,

$$ E\left(\frac{Y_i-\mu_i}{\sqrt{\mu_i}} \,\middle|\, b\right)=0, \qquad \operatorname{Var}\left(\frac{Y_i-\mu_i}{\sqrt{\mu_i}} \,\middle|\, b\right)=1 $$

under a conditional Poisson model, where \(b\) denotes the random effects. The first equality follows because \(E(Y_i\mid b)=\mu_i\); the second follows because \(\operatorname{Var}(Y_i\mid b)=\mu_i\). This motivates a zero reference and a common scale, but it does not make fitted residuals independent standard normal observations. In practice, parameters and random effects are estimated, observations may share clusters, and small fitted means produce discrete, asymmetric residual distributions.

Worked Example: Reading Residuals Against Fitted Means

Suppose a hypothetical fitted conditional Poisson GLMM gives these observed counts and fitted means for six visits. For illustration, calculate conditional Pearson residuals using \(r_{Pi}=(Y_i-\hat{\mu}_i)/\sqrt{\hat{\mu}_i}\).

Visit\(Y_i\)\(\hat{\mu}_i\)Pearson residual
100.25-0.500
200.50-0.707
310.400.949
401.00-1.000
520.701.554
631.201.643

For visit 5, \(r_{P5}=(2-0.70)/\sqrt{0.70}=1.30/0.837=1.554\). For visit 2, \(r_{P2}=(0-0.50)/\sqrt{0.50}=-0.50/0.707=-0.707\). The calculations show the direction and scaled size of each discrepancy.

In the plot, the observations at fitted means 0.40 and 0.70 have positive residuals, while those at 0.25, 0.50, and 1.00 have negative residuals. Six points do not establish a systematic trend: each is one discrete count, and the visits may belong to the same cluster. The appropriate conclusion is that these residuals show individual departures, not persuasive evidence of a fitted-mean pattern. A larger display, with cluster membership retained in interpretation, would be needed to assess a repeated structure.

Look for structure against covariates

A residual-versus-covariate plot asks whether the model’s errors change systematically over the predictor’s values. This is especially useful when the fitted mean is a function of several covariates: an overall residual-versus-fitted plot may conceal opposite patterns in different covariate regions. The display should correspond to a specific concern, such as a nonlinear predictor effect or a missed rate trend, rather than serving as an undirected search for a convenient pattern.

Worked Example: A Possible Missed Trend in Exposure

Consider hypothetical counts from 12 observation periods, grouped into three ranges of a continuous predictor \(x\). The fitted GLMM is a Poisson model with a linear effect of \(x\), and the table gives the observed and summed fitted counts in each range.

Range of \(x\)Observed totalFitted totalObserved minus fitted
Low58-3
Middle990
High20128

The low-range discrepancy is \(5-8=-3\), and the high-range discrepancy is \(20-12=8\). As a descriptive scale only, divide each difference by the square root of the fitted total: \(-3/\sqrt{8}=-1.061\), \(0/\sqrt{9}=0\), and \(8/\sqrt{12}=2.309\). The increasing sequence suggests that the model may underpredict at high \(x\) and overpredict at low \(x\).

This calculation is not a test statistic with a guaranteed standard normal distribution. The observations may share random effects, and the grouped totals may not have the variances assumed by a simple independent Poisson calculation. The useful next step is to inspect the observation-level residual plot against \(x\) and compare its pattern with simulations from the fitted GLMM. The plot motivates checking the modeled functional form; it does not by itself justify changing the model.

Zero-heavy patterns and simulation reference displays

When counts are very sparse, the most visible feature may be an excess or deficit of zeros. A residual plot against fitted means can reveal that many observations at similar fitted means lie below zero, but the residual scatter alone can make the degree of surprise hard to judge. A count-specific reference display can help: simulate replicated data from the fitted GLMM, preserving its fixed effects, random-effects structure, offsets, and relevant cluster design, then compare the observed display with displays from those simulations.

For a fair comparison, the simulation procedure should reflect how the plotted residuals were obtained. If the observed residuals use estimated parameters or estimated random effects, reproduce the fitting and residual-calculation steps for simulated data when feasible. Simulation envelopes are reference summaries under the fitted model, not universal cutoffs. A point outside an envelope is a reason to investigate; it is not proof of a particular alternative model.

Worked Example: Investigating Many Zeros

Suppose a hypothetical data set contains 40 counts from several clusters. A Poisson random-intercept GLMM is fitted, and the observed number of zeros is 31. In 1,000 simulations from the fitted model, with the cluster structure preserved and the fitting procedure repeated, the median number of zeros is 23 and the central 95% simulation interval is 18 to 29.

The observed count of zeros, 31, is above the simulated interval’s upper endpoint, 29. This indicates that the observed zero count is unusual relative to these simulations of the fitted model. A residual-versus-fitted display should then be examined to see whether negative residuals are concentrated in a particular fitted-mean range or covariate subgroup, rather than distributed throughout the data.

The comparison does not establish why the fitted model misses the zeros. Possible explanations include an incorrect mean structure, an inadequate random-effects distribution, or a feature of the count distribution not represented by the model. Nor should the simulation be simplified by plugging a marginal fitted mean into a conditional Poisson zero probability: with random effects, the marginal zero probability is an average over the random-effects distribution, not generally the zero probability evaluated at the marginal mean. The stated simulation result is diagnostic evidence about this fitted model, not a causal conclusion or a selection rule for a particular alternative.

Choosing and interpreting a display

Different residuals emphasize different departures. Pearson residuals scale differences by a model-based standard deviation and are convenient for locating unusually large discrepancies, but their sparse-count distribution is not generally normal. Deviance residuals use the likelihood contribution and can highlight observations poorly represented by the fitted distribution. Randomized quantile residuals and simulation-based residuals provide distributional reference scales for discrete outcomes, though their interpretation depends on the randomization or simulation method. No residual type removes the need to respect clustering.

Display choiceUseful forImportant caution
Pearson residual against fitted meanLocating scaled departures and broad mean-related patternsSmall fitted means yield discrete and asymmetric values
Residual against a covariateFinding a trend or subgroup pattern tied to a predictorA pattern may reflect another omitted or misspecified feature
Simulation-based residual displayComparing an observed pattern with patterns generated under the fitted GLMMSimulations must represent the cluster structure and estimation process

The main alternative to a residual display is a numerical summary or a predictive comparison. A summary can compress the data and hide where misfit occurs; a plot can localize it but is sensitive to choices such as smoothing and binning. Simulation-based checks provide a model-based reference, but depend on the model and simulation design being correctly implemented. Use these approaches as complements: first specify the feature of concern, then inspect the corresponding display and, when useful, compare it with simulated reference displays.

Common pitfalls and limitations

  • Expecting a normal cloud. Sparse counts naturally produce repeated zeros and separated bands of residuals. Assess systematic structure and model-based plausibility, not visual resemblance to a continuous normal sample.
  • Treating clustered points as independent. Residuals from the same cluster can be related. A smooth or a bin average does not automatically account for that dependence.
  • Mixing prediction scales. Pair conditional residuals with conditional fitted means, or use a marginal diagnostic defined for marginal predictions. Otherwise, a pattern can be created by comparing unlike quantities.
  • Overinterpreting a few large residuals. An isolated point may be an expected count realization. Look for repeated structure and use an appropriate model-based reference before concluding that the model is inadequate.
  • Searching many covariates until a pattern appears. Exploratory displays are useful, but patterns found after many unplanned comparisons need confirmation and substantive interpretation.

Residual displays are limited by the information in the data. When most observations are zero and only a few are positive, the plot may have little power to distinguish competing explanations. It can identify where predictions appear discordant with observed counts, but it cannot by itself determine the correct random-effects distribution, identify a causal mechanism, or replace assessment of the study design.

Key takeaway: For sparse count GLMMs, plot residuals against fitted means and scientifically relevant covariates, but judge structure against the discrete count model and its cluster dependence. Use simulation displays when a direct visual reference is unclear, and treat any pattern as a prompt for focused investigation rather than a diagnosis by itself.

Check Your Understanding

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

  1. For a conditional Poisson GLMM with \(Y_i=0\) and \(\hat{\mu}_i=0.25\), calculate the conditional Pearson residual. What does its sign indicate?
  2. Why is a visually asymmetric Pearson residual plot not, by itself, evidence that a sparse count GLMM is wrong?
  3. A plot against a covariate shows residuals mostly negative at low values and positive at high values. State one plausible interpretation and one reason not to treat the pattern as proof.
  4. Why must a simulation reference for a clustered count model preserve its cluster structure?

Solutions. (1) \(r_{Pi}=(0-0.25)/\sqrt{0.25}=-0.25/0.50=-0.500\). The negative sign means the observed count is below its fitted conditional mean. (2) Counts are discrete, and zeros often dominate when fitted means are small; Pearson residuals therefore need not look symmetric or normal even when the model is adequate. (3) The pattern may indicate that the model underpredicts at high covariate values and overpredicts at low values, perhaps because the modeled effect is too simple. It is not proof because sampling variability, cluster dependence, or other model features can also produce a pattern. (4) Within-cluster observations share modeled random effects, so simulations that break the cluster structure produce an inappropriate reference for the dependence and variability in the observed residual display.

Clinical Biostats