Tutorials › Generalized Linear Mixed Models (GLMM) › Deviance Residuals in Sparse Data

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

Deviance Residuals in Sparse Data

Learn how signed deviance residuals are calculated from fitted discrete distributions, and why their magnitudes and shapes need cautious interpretation in sparse GLMMs.

Intermediate 11 min read

What You'll Learn

  • Define a signed deviance residual using the fitted and saturated conditional likelihoods.
  • Calculate residuals for Bernoulli, grouped-binomial, and Poisson observations.
  • Explain why sparse discrete outcomes produce residuals that are asymmetric and take only a limited set of values.
  • Distinguish deviance residuals from raw response and Pearson residuals.
  • Identify when conditional deviance residuals are only approximate diagnostics in a GLMM.

Why Deviance Residuals Need Careful Reading

A residual for a discrete response cannot vary smoothly around zero in the way a residual for a continuous response might. For a binary observation, for example, the response is either zero or one, so a given fitted probability permits only two possible residual values. With rare events, those values can be very different in magnitude: an observed event may be surprising under a small fitted probability, while a non-event may be quite ordinary. Deviance residuals summarize this discrepancy through a likelihood comparison, but they do not remove the discreteness or make the resulting residuals normally distributed.

In a generalized linear mixed model (GLMM), the distribution used for a residual must also be identified. One common diagnostic uses the response distribution conditional on the random effects, evaluated at fitted random effects and fixed-effect estimates. This is a useful plug-in diagnostic, not a residual from a fully known distribution: the random effects and model parameters have been estimated. A marginal distribution instead averages over the random effects and is generally a mixture. The two choices need not give the same fitted probabilities or residuals.

Definition: For an observation \(y_i\), let \(\ell_i(y_i)\) be its fitted log-likelihood contribution and let \(\ell_{i,\mathrm{sat}}(y_i)\) be the log-likelihood contribution under a saturated model that fits that observation exactly. The deviance contribution is \(d_i=2\{\ell_{i,\mathrm{sat}}(y_i)-\ell_i(y_i)\}\). The signed deviance residual is \(r_{D,i}=\operatorname{sign}(y_i-\hat\mu_i)\sqrt{d_i}\), where \(\hat\mu_i\) is the fitted conditional mean. If \(y_i=\hat\mu_i\), the residual is zero. For discrete models, the saturated contribution is understood using the same response distribution and the observation's appropriate support.

The saturated model is a reference for measuring lack of fit, not a scientifically plausible model with many parameters to interpret. Under a correctly specified likelihood, \(d_i\) is nonnegative because the saturated likelihood cannot be lower than the fitted likelihood. The square root returns the discrepancy to the scale of a residual, and the sign records whether the observed response is above or below its fitted mean. A residual is therefore not merely a signed difference: its magnitude depends on how plausible the observation is under the fitted distribution.

Common Discrete-Response Formulas

For a Bernoulli response \(Y_i\in\{0,1\}\) with fitted event probability \(\hat p_i\), the deviance contribution is

$$ d_i=2\left[y_i\log\left(\frac{y_i}{\hat p_i}\right) +(1-y_i)\log\left(\frac{1-y_i}{1-\hat p_i}\right)\right]. $$

Terms with a zero multiplier are defined as zero, using the limit \(0\log(0/a)=0\) for \(a>0\). Thus \(y_i=1\) gives \(d_i=2\log(1/\hat p_i)\), while \(y_i=0\) gives \(d_i=2\log\{1/(1-\hat p_i)\}\). The residual sign is positive for an observed event and negative for a non-event.

For a binomial observation \(Y_i\sim\operatorname{Binomial}(m_i,p_i)\), where \(m_i\) is the number of trials and \(\hat\mu_i=m_i\hat p_i\) is the fitted number of successes, the corresponding contribution is

$$ d_i=2\left[ y_i\log\left(\frac{y_i}{\hat\mu_i}\right) +(m_i-y_i)\log\left(\frac{m_i-y_i}{m_i-\hat\mu_i}\right) \right]. $$

Again, zero-count terms contribute zero. This formula applies when \(0<\hat p_i<1\); boundary fitted probabilities require care because likelihood ratios can be infinite or undefined. A Bernoulli observation is the special case \(m_i=1\).

For a Poisson response \(Y_i\sim\operatorname{Poisson}(\mu_i)\) with fitted mean \(\hat\mu_i>0\),

$$ d_i=2\left[y_i\log\left(\frac{y_i}{\hat\mu_i}\right)-(y_i-\hat\mu_i)\right], \qquad r_{D,i}=\operatorname{sign}(y_i-\hat\mu_i)\sqrt{d_i}. $$

When \(y_i=0\), the log term is zero and \(d_i=2\hat\mu_i\). For other discrete families, the general likelihood definition still applies: compute twice the difference between the saturated and fitted log likelihoods under that family, then take the signed square root. A formula should not be transferred from the Poisson or binomial distribution to a different response family without checking its likelihood.

Worked Example: Two Possible Residuals for a Rare Bernoulli Event

Suppose a hypothetical observation has a fitted event probability \(\hat p=0.20\). Under the Bernoulli model, the possible outcomes are \(y=1\) and \(y=0\). The model assumptions for this calculation are that the response is binary and that \(0<\hat p<1\); the calculation itself is conditional on the fitted probability.

If an event occurs, \(y=1\), so

$$ d=2\log\left(\frac{1}{0.20}\right) =2\log(5) \approx 3.2189, \qquad r_D=+\sqrt{3.2189}\approx +1.794. $$

If no event occurs, \(y=0\), so

$$ d=2\log\left(\frac{1}{0.80}\right) =2\log(1.25) \approx 0.4463, \qquad r_D=-\sqrt{0.4463}\approx -0.6680. $$

The possible residuals are not symmetric about zero: the event has a larger positive residual because it is less likely under the fitted model than the non-event. This asymmetry is a feature of the fitted Bernoulli distribution, not by itself evidence that the model is wrong.

Worked Example: A Poisson Count Larger Than Its Fitted Mean

For a hypothetical count observation, suppose \(Y=3\) and the fitted Poisson mean is \(\hat\mu=0.50\). Assume the response is a nonnegative count with a Poisson conditional distribution and a strictly positive fitted mean. The deviance contribution is

$$ d=2\left[3\log\left(\frac{3}{0.50}\right)-(3-0.50)\right] =2[3\log(6)-2.5] \approx 5.7506. $$

Since the observed count exceeds its fitted mean, the sign is positive:

$$ r_D=+\sqrt{5.7506}\approx +2.398. $$

This is a fairly large positive residual: a count of three is substantially less compatible with a fitted mean of one-half than a count near one-half would be. It is not a p-value and does not, on its own, quantify the probability that the model is correct.

Worked Example: A Grouped Binomial Observation With No Successes

Suppose a hypothetical group has \(m=5\) trials, a fitted success probability \(\hat p=0.20\), and therefore fitted success count \(\hat\mu=5(0.20)=1\). If the observed count is \(y=0\), the binomial deviance is

$$ d=2\left[ 0\log\left(\frac{0}{1}\right) +5\log\left(\frac{5}{4}\right) \right] =10\log(1.25) \approx 2.2314. $$

The first term is zero by convention. Since \(0<1\), the signed residual is negative:

$$ r_D=-\sqrt{2.2314}\approx -1.494. $$

The calculation assumes that the five trials are represented by the stated binomial observation with the same fitted success probability. It gives one residual for the group. Expanding the group into five separate Bernoulli residuals would answer a different diagnostic question and would not generally give this same single group-level residual.

Why the Residuals Are Not Normally Distributed

A short likelihood argument explains both the usefulness and the limits of the deviance scale. For a fixed observation, the likelihood ratio comparing the saturated fit with the fitted model is \(\exp\{\ell_{i,\mathrm{sat}}-\ell_i\}\). Taking twice its log gives \(d_i\). Thus a large deviance contribution means that the observation is less well supported by the fitted model than by a model tailored to that observation. The signed square root preserves this ordering in magnitude while retaining the direction of the discrepancy. This construction does not imply a normal sampling distribution for \(r_{D,i}\).

For example, a Bernoulli observation with a fixed fitted probability has only two possible residuals, as the first example showed. A sparse Poisson count also puts much of its probability on zero, with occasional positive counts; its residual distribution can consequently be strongly asymmetric. In a sample with few events, there may be too few distinct observed values to make a histogram or a normal reference line informative. Repeated zeros can produce repeated residual values, while a small number of events can produce a few large positive residuals.

The sign convention is tied to \(y_i-\hat\mu_i\), but the deviance magnitude is tied to the likelihood. Consequently, it is possible for a deviance residual and a Pearson residual to have the same sign but different magnitudes. Pearson residuals scale the response difference by a model-based standard deviation; deviance residuals use a likelihood discrepancy. Neither transformation makes sparse discrete residuals independent standard-normal observations.

Justification: If observations are conditionally independent given the random effects, their conditional log-likelihood contributions add. Therefore the conditional deviance is \(D=\sum_i d_i=\sum_i r_{D,i}^2\). This identity is algebraic; it does not establish that \(D\) follows a chi-squared distribution in a finite, sparse GLMM. Parameter estimation, dependence induced by shared random effects, and the discreteness of the responses all affect its reference distribution.

Using Deviance Residuals in a GLMM

For an observation-level conditional diagnostic, the analyst must state which fitted distribution is being compared with the observation. In a GLMM, this often means using the response distribution conditional on fitted random effects, with the fixed effects and random effects replaced by their estimates. The resulting \(\hat\mu_i\) or \(\hat p_i\) is a plug-in value. The residual therefore does not incorporate all uncertainty in the estimated random effects, fixed effects, or variance parameters.

A marginal diagnostic instead compares observations with a distribution averaged over random effects. Because that distribution is generally a mixture, its likelihood and residual calculations are not obtained simply by substituting a marginal mean into a conditional deviance formula. A mean alone does not specify the mixture distribution. The conditional and marginal targets answer different questions, so residuals should be labelled and interpreted accordingly.

When using conditional deviance residuals, check that the response family, trial counts or exposure offsets, and fitted means are appropriate for the observations being assessed. A wrong denominator for grouped-binomial data or an omitted exposure adjustment for counts can create apparent lack of fit that is actually a data specification error. Also check for boundary fitted probabilities or means: numerical values near zero or one can yield very large residuals and require stable likelihood calculations.

Useful diagnostic questions include whether a small number of observations dominate the residual magnitudes, whether observed zeros or extreme counts occur more often than the fitted model anticipates, and whether residual signs show a systematic pattern across fitted means or covariate values. Such patterns are prompts to investigate the model and data, not automatic proof of a particular failure. In sparse settings, simulated reference distributions or other diagnostics can be more informative than expecting residuals to look like a normal sample.

Comparison, Limitations, and Common Pitfall

ResidualConstructionUseful featureImportant limitation
Response residual\(y_i-\hat\mu_i\)Directly shows the discrepancy in response unitsDoes not account for the response variance or likelihood shape
Pearson residualResponse difference divided by a model-based standard deviationScales the discrepancy by its expected variabilityCan remain asymmetric and discrete; scaling does not guarantee normality
Deviance residualSigned square root of the saturated-versus-fitted deviance contributionMeasures discrepancy through the assumed likelihoodIts distribution is discrete and may be skewed, especially for sparse outcomes

A common mistake is to treat a deviance residual of \(+2\) as having the same universal interpretation as a normal \(z\)-score of \(+2\), or to count residuals outside a fixed normal range as if a normal reference distribution were guaranteed. The correction is to remember how the residual was constructed: it is a signed likelihood discrepancy under a fitted discrete distribution. Its reference behavior depends on that distribution, the fitted values, the sampling structure, and parameter estimation. In particular, a large residual identifies an observation worth investigating; it is not by itself a formal significance test or evidence that a specific model component is missing.

Deviance residuals are also not a substitute for checking the random-effects structure or the dependence assumptions. Conditional residual calculations may hide uncertainty from estimating random effects, while marginal calculations require the appropriate mixture distribution. Sparse data make these issues more consequential because a few observations can carry a large share of the apparent discrepancy.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A Bernoulli observation has fitted probability \(0.10\) and observed value \(1\). Give the sign of its deviance residual and explain why its magnitude is not a normal-theory \(z\)-score.
  2. For a Poisson observation with \(y=0\) and fitted mean \(\hat\mu=0.30\), calculate the deviance residual.
  3. Why can grouped-binomial data produce a different residual when represented as one group than when represented as separate Bernoulli observations?
  4. What does a large absolute deviance residual indicate, and what does it not establish?
  5. In a GLMM, why should a conditional plug-in deviance residual not be described as including all random-effect uncertainty?

Solutions. (1) Its sign is positive because \(1>0.10\). The residual has a discrete sampling distribution determined by the Bernoulli probability, not a guaranteed standard normal distribution. (2) For \(y=0\), \(d=2\hat\mu=0.60\), so \(r_D=-\sqrt{0.60}\approx-0.7746\). (3) A grouped residual compares the group likelihood with a fitted group-level binomial likelihood; separate residuals compare each trial's Bernoulli likelihood. They are different likelihood contributions and answer different diagnostic questions. (4) It indicates that the observation is relatively poorly supported by the fitted likelihood compared with a saturated fit. It does not by itself provide a p-value, prove model failure, or identify its cause. (5) The calculation substitutes estimated random effects and model parameters into a conditional response distribution. It does not integrate over their estimation uncertainty.

Clinical Biostats