Tutorials › Exam SRM - Statistics for Risk Modeling › Choosing Pearson or Deviance Residuals for GLM Diagnostics

Exam SRM · GLM Modeling Cases · Tutorial 875 of 926

Choosing Pearson or Deviance Residuals for GLM Diagnostics

Calculate Pearson and deviance residuals for binomial and Poisson observations, then use their signs and magnitudes to identify where a fitted model misses the data.

Advanced 12 min read

What You'll Learn

  • Calculate Pearson residuals from the fitted mean and model variance for binomial and Poisson observations
  • Calculate signed deviance residuals from the likelihood-ratio deviance contribution
  • Handle zero counts and zero successes using the appropriate limiting convention
  • Interpret a residual’s sign and compare its magnitude with that of other observations
  • Recognize why Pearson and deviance residuals may differ, especially for sparse data
  • Avoid treating residuals as exact standard normal scores or as proof of model failure

Why GLM Residuals Need a Model-Based Scale

A generalized linear model (GLM) predicts a conditional mean, not usually the observed response exactly. For a binomial outcome, a group with a fitted success probability of 0.40 will not necessarily have exactly 40% successes. For a count outcome, a fitted mean of 4 does not require the observed count to equal 4. A useful diagnostic therefore compares the observation with its fitted mean on a scale that accounts for the response distribution.

Two common choices are the Pearson residual and the deviance residual. Both are signed: positive values mean the observed response exceeds the fitted mean, and negative values mean it falls below the fitted mean. Their magnitudes measure discrepancy in different ways. Neither residual, by itself, proves that the model is wrong.

Definition: For observation \(i\), let \(y_i\) be the observed response, \(\hat{\mu}_i\) its fitted mean, and \(V(\hat{\mu}_i)\) the variance function evaluated at that mean. With dispersion fixed at 1, the Pearson residual is \(r_{P,i}=(y_i-\hat{\mu}_i)/\sqrt{V(\hat{\mu}_i)}\). The deviance residual is the signed square root of that observation’s deviance contribution: \(r_{D,i}=\operatorname{sign}(y_i-\hat{\mu}_i)\sqrt{d_i}\).

For the ordinary binomial and Poisson models, the dispersion parameter is fixed at 1. Thus the variance used here is the variance specified by the distribution and fitted mean. If a model instead uses an estimated dispersion parameter, residual scaling must reflect that model’s convention. The formulas below are for the standard binomial and Poisson GLMs.

Binomial Residuals

Suppose observation \(i\) records \(y_i\) successes in \(m_i\) trials, with a fitted success probability \(\hat{p}_i\). The model assumes a binomial response conditional on the predictors, so \(\hat{\mu}_i=m_i\hat{p}_i\) and its variance is \(m_i\hat{p}_i(1-\hat{p}_i)\). The Pearson residual is therefore

$$ r_{P,i}= \frac{y_i-m_i\hat{p}_i} {\sqrt{m_i\hat{p}_i(1-\hat{p}_i)}}. $$

The binomial deviance contribution compares the fitted model’s likelihood for the observation with the likelihood under a saturated model, which fits that observation exactly. Its signed square root is

$$ r_{D,i} = \operatorname{sign}(y_i-m_i\hat{p}_i) \sqrt{ 2\left[ y_i\ln\left(\frac{y_i}{m_i\hat{p}_i}\right) +(m_i-y_i)\ln\left(\frac{m_i-y_i}{m_i(1-\hat{p}_i)}\right) \right] }. $$

A term of the form \(0\ln(0/c)\) is defined to be 0 by continuity. This convention is necessary when an observation has no successes or no failures. The formula assumes \(0<\hat{p}_i<1\); a fitted probability at a boundary requires care because the likelihood comparison can be infinite or undefined.

Worked Example: Comparing Residuals for a Grouped Binomial Observation

A hypothetical insurer models whether a policy receives a particular optional service during the year. For one risk group, the fitted service probability is \(\hat{p}=0.50\). Among 30 policies, 18 receive the service. Calculate the Pearson and deviance residuals, and interpret them. Treat the 30 outcomes as conditionally independent Bernoulli trials with the stated common fitted probability.

Method and fitted mean. The response is the number of successes, \(y=18\), out of \(m=30\) trials. The fitted mean is \(m\hat{p}=30(0.50)=15\). The fitted variance is \(m\hat{p}(1-\hat{p})=30(0.50)(0.50)=7.5\), so its square root is \(\sqrt{7.5}=2.7386\).

Pearson residual. The observed-minus-fitted difference is \(18-15=3\). Thus \(r_P=3/2.7386=1.0954\), or 1.095 to three decimal places.

Deviance residual. The fitted expected failures are \(30-15=15\), while the observed failures are \(30-18=12\). Substitute both components: \(d=2[18\ln(18/15)+12\ln(12/15)]\). The ratios are \(18/15=1.2\) and \(12/15=0.8\). Using \(\ln(1.2)=0.182322\) and \(\ln(0.8)=-0.223144\), \(18(0.182322)=3.281796\), and \(12(-0.223144)=-2.677728\). Therefore \(d=2(3.281796-2.677728)=1.208136\), and \(r_D=+\sqrt{1.208136}=1.099\) to three decimals.

Both residuals are positive because 18 successes exceed the fitted 15. Their similar magnitudes indicate a modest discrepancy on either scale. The common mistake is to use the Bernoulli variance \(p(1-p)\) for the grouped total; the variance of the total is \(m p(1-p)\), so omitting \(m\) would overstate this residual.

Count Residuals

For a Poisson GLM, assume the observed count \(Y_i\), conditional on its predictors and exposure, has a Poisson distribution with fitted mean \(\hat{\mu}_i>0\). Its variance is also \(\hat{\mu}_i\). The Pearson residual is

$$ r_{P,i}=\frac{y_i-\hat{\mu}_i}{\sqrt{\hat{\mu}_i}}. $$

The Poisson deviance residual is

$$ r_{D,i} = \operatorname{sign}(y_i-\hat{\mu}_i) \sqrt{ 2\left[ y_i\ln\left(\frac{y_i}{\hat{\mu}_i}\right) -(y_i-\hat{\mu}_i) \right] }. $$

When \(y_i=0\), define \(y_i\ln(y_i/\hat{\mu}_i)=0\), again by continuity. An exposure offset changes the fitted mean, not the residual formula: if the fitted rate is \(\hat{\lambda}_i\) per unit exposure \(e_i\), then \(\hat{\mu}_i=e_i\hat{\lambda}_i\).

Worked Example: A Poisson Count Above Its Exposure-Based Mean

A hypothetical claims model predicts 0.40 reports per unit of exposure. One policy group contributes 10 units of exposure and has 9 reported claims. Assume a Poisson count conditional on exposure, with the fitted rate fixed at 0.40. Calculate both residuals.

Method and fitted mean. The exposure-adjusted fitted mean is \(\hat{\mu}=10(0.40)=4\) claims. The observed-minus-fitted difference is \(9-4=5\), and the Poisson variance is 4.

Pearson residual. The standard deviation is \(\sqrt{4}=2\), so \(r_P=5/2=2.500\).

Deviance residual. The deviance contribution is \(d=2[9\ln(9/4)-(9-4)]\). Here \(9/4=2.25\), \(\ln(2.25)=0.810930\), and \(9(0.810930)=7.298370\). Subtracting \(9-4=5\) gives \(2.298370\); doubling gives \(d=4.596740\). Therefore \(r_D=+\sqrt{4.596740}=2.144\) to three decimals.

Both residuals are positive and fairly large relative to zero: the count is above the fitted mean. The common mistake is to use the rate 0.40 as the Poisson mean. The mean for this observation includes its exposure, so using 0.40 would produce the wrong variance and the wrong residual.

Why the Deviance Formula Has This Form

The deviance measures how much log-likelihood is lost by using the fitted model rather than a model that fits the observed response exactly. For a single observation, twice that log-likelihood difference gives its deviance contribution. Taking a square root puts the contribution on a residual-like scale, and assigning the sign of \(y_i-\hat{\mu}_i\) records the direction of the discrepancy.

For a Poisson observation, its log-likelihood, ignoring a constant that is the same for both models, is \(y_i\ln(\mu_i)-\mu_i\). The saturated model sets its mean to the observed count \(y_i\); the fitted model uses \(\hat{\mu}_i\). Their log-likelihood difference, multiplied by two, is

$$ 2\{[y_i\ln(y_i)-y_i]-[y_i\ln(\hat{\mu}_i)-\hat{\mu}_i]\} = 2\left[y_i\ln\left(\frac{y_i}{\hat{\mu}_i}\right)-(y_i-\hat{\mu}_i)\right]. $$

This is nonnegative because the saturated model can fit the observation at least as well as the restricted fitted model. The signed square root retains this magnitude information while distinguishing overprediction from underprediction. For binomial data, the same likelihood comparison uses the saturated probability \(y_i/m_i\); the binomial combinatorial term cancels between the two likelihoods, leaving the two logarithmic terms in the binomial deviance formula.

1
Identify the response and fitted mean.
For a grouped binomial observation, use the fitted number of successes \(m_i\hat{p}_i\). For a Poisson observation, use its exposure-adjusted mean if an offset is present.
2
Choose the residual scale.
Use the model variance in the Pearson formula, or calculate the observation’s likelihood-based deviance contribution for the deviance residual.
3
Assign the sign and interpret cautiously.
Use the sign of observed minus fitted. Compare magnitudes in context and investigate conspicuous discrepancies rather than treating a single cutoff as a universal decision rule.

How to Compare and Interpret the Two

Pearson residuals divide the observed-minus-fitted difference by the model standard deviation. Deviance residuals instead reflect the likelihood penalty for the discrepancy. For observations close to their fitted means, these scales are often similar. They need not agree closely for sparse counts, small expected binomial cell counts, or observations near the response boundaries. The examples above illustrate that the formulas respond differently to the same kind of discrepancy.

A positive residual indicates an observation larger than predicted; a negative residual indicates an observation smaller than predicted. A larger absolute residual signals a more pronounced discrepancy on that residual’s scale. It does not automatically mean the model is inadequate: chance variation can produce unusual observations, and model parameters were estimated from data that may include the observation itself. Residuals are not generally independent exact standard normal variables.

The sum of squared Pearson residuals is the Pearson goodness-of-fit statistic, and the sum of the deviance contributions is the residual deviance. A signed deviance residual’s square is its individual deviance contribution; summing the signed residuals themselves is not the residual deviance. These quantities summarize fit differently, so a large individual residual is a reason to examine the observation and model assumptions, not a standalone formal test.

Common exam trap: Do not confuse the signed deviance residual with the deviance contribution. The contribution \(d_i\) is nonnegative; the residual is \(\operatorname{sign}(y_i-\hat{\mu}_i)\sqrt{d_i}\). Also check whether the response is a grouped binomial total or an individual Bernoulli result, and whether a count mean must include exposure.

Worked Example: Handling a Zero Count

A hypothetical monitoring model predicts a mean of 3 events during a fixed observation period. No events occur. Assume a Poisson response with fitted mean \(\hat{\mu}=3\). Compute both residuals and explain the sign.

Method and Pearson residual. Here \(y=0\), so \(y-\hat{\mu}=0-3=-3\), and the standard deviation is \(\sqrt{3}=1.7321\). Thus \(r_P=-3/1.7321=-1.732\), to three decimals.

Deviance residual. The convention for the zero-count logarithmic term gives \(0\ln(0/3)=0\). Hence \(d=2[0-(0-3)]=2(3)=6\). Since \(y-\hat{\mu}=-3\), \(r_D=-\sqrt{6}=-2.449\), to three decimals.

The negative signs correctly indicate fewer events than fitted. The deviance residual has a larger absolute value than the Pearson residual here. The common mistake is to substitute \(y=0\) into the logarithm and attempt to evaluate \(\ln(0)\); the product \(y\ln(y/\hat{\mu})\) is defined by its limit as zero.

Check Your Understanding

For each item, use the stated fitted values and standard binomial or Poisson assumptions. Round residuals to three decimal places.

  1. A grouped binomial observation has 12 successes in 20 trials, with fitted probability 0.50. Calculate its Pearson and deviance residuals. (Answer: \(r_P=0.894\), \(r_D=0.897\))
  2. A Poisson count is 0, with fitted mean 3. Calculate both residuals, including the sign of the deviance residual. (Answer: \(r_P=-1.732\), \(r_D=-2.449\))
  3. A Poisson model predicts 4 events for an observation that has 6. Calculate the Pearson and deviance residuals. (Answer: \(r_P=1.000\), \(r_D=0.930\))
  4. A grouped binomial observation has 4 successes in 10 trials, with fitted probability 0.60. Calculate both residuals. (Answer: \(r_P=-1.291\), \(r_D=-1.274\))
  5. Two Poisson observations have observed and fitted counts \((10,5)\) and \((14,9)\), respectively. Calculate their Pearson residuals and identify which has the larger absolute Pearson residual. (Answer: \(r_{P,1}=2.236\), \(r_{P,2}=1.667\); the first observation has the larger absolute residual.)
Clinical Biostats