Why GLM Residuals Need Different Scales
A residual measures the discrepancy between an observed response and the value predicted by a model. In a linear model, subtracting the fitted value gives a familiar error on the response scale. In a generalized linear model (GLM), responses may be counts or binary outcomes, and their variability can change with the fitted mean. A difference of two units therefore does not have the same meaning for every observation or outcome family.
This tutorial compares three residuals used to examine GLM fit: the response residual, the Pearson residual, and the deviance residual. Each describes the gap between an observed value and a fitted value, but on a different scale. The right choice depends on the question being asked and on the outcome distribution.
For unit-weight Poisson and Bernoulli models, \(\phi=1\) is standard, so the conventional Pearson residual is already in model-standard-deviation units. In other settings, software may report Pearson residuals without dividing by \(\sqrt{\phi}\). Always check the convention before comparing numerical values. R’s glm residual methods use the conventional Pearson and deviance definitions, which account for prior weights but do not apply a dispersion scaling factor.
What the Three Residuals Tell You
| Residual | Scale and interpretation | Useful diagnostic question |
|---|---|---|
| Response | Original response units; the signed raw difference \(y_i-\hat{\mu}_i\) | How far off was the prediction in the units that matter operationally? |
| Pearson | Difference relative to the variance function; optionally scaled by \(\sqrt{\phi}\) | Is the discrepancy large relative to the variability expected at this fitted mean? |
| Deviance | Signed square root of a likelihood-based contribution to deviance | How discrepant is the observation on a likelihood scale? |
The response residual is easiest to explain, but its magnitude can be misleading when variance changes with the mean. Pearson residuals adjust for that changing variance. Deviance residuals compare the fitted model with a saturated model, one that fits each observation as closely as the outcome family permits. Neither Pearson nor deviance residuals automatically follow a normal distribution. This is particularly important for discrete outcomes, where residual values are restricted or can cluster.
Why Pearson Residuals Divide by a Standard Deviation
The Pearson adjustment follows directly from the GLM variance assumption. If \(Y_i\) has conditional mean \(\mu_i\), then its model-based standard deviation is \(\sqrt{\phi V(\mu_i)/w_i}\). Subtracting the fitted mean and dividing by that standard deviation expresses the difference in standard-deviation units:
The right-hand expression is the conventional Pearson residual divided by \(\sqrt{\phi}\). This also explains why a fixed raw error can be a modest discrepancy for an observation with high expected variability but a large discrepancy for one with low expected variability. The calculation is meaningful only to the extent that the specified variance function and dispersion adequately describe the response variation.
Worked Example: A Poisson Count Above Its Fitted Mean
A hypothetical GLM models the number of equipment alerts in a fixed monitoring period as Poisson, with unit weight and fitted mean \(\hat{\mu}=4\). One period records \(y=7\) alerts. Calculate the response, Pearson, and deviance residuals. Use natural logarithms and round residuals to four decimal places.
Model and method. For a Poisson response, \(V(\mu)=\mu\) and \(\phi=1\). The Poisson unit deviance contribution is \(d_i=2[y_i\log(y_i/\hat{\mu}_i)-(y_i-\hat{\mu}_i)]\) when \(y_i>0\).
Response residual. Subtract the fitted mean from the observed count: \(e=7-4=3\) alerts.
Pearson residual. The fitted variance is \(V(4)=4\), so the fitted standard deviation is \(\sqrt{4}=2\). Thus \(r_P=(7-4)/2=1.5\).
Deviance residual. First, \(\log(7/4)=\log(1.75)\approx0.5596158\). Then \(7\log(1.75)\approx3.9173105\), and \(y-\hat{\mu}=3\). Therefore \(d=2(3.9173105-3)=1.8346210\). Since \(y-\hat{\mu}\) is positive, the deviance residual is \(+\sqrt{1.8346210}\approx1.3545\).
Check and interpretation. All three residuals are positive because the observed count exceeds the fitted mean. The response residual is in alerts; the Pearson residual is 1.5 fitted standard deviations. The deviance residual is positive and reflects the likelihood-based discrepancy. The common mistake is to call the raw difference of 3 a three-standard-deviation error: the fitted standard deviation is 2, so that conclusion does not follow.
Residuals for Binary and Gaussian Outcomes
For an individual Bernoulli observation, \(y_i\) is 0 or 1 and the fitted mean is the fitted probability \(\hat{p}_i\). Its variance is \(\hat{p}_i(1-\hat{p}_i)\). A Pearson residual can become large when the fitted probability is near 0 or 1 and the observed outcome is contrary to that prediction, because the model assigns that outcome a small variance. The deviance residual also reflects how poorly the fitted probability accommodates the observed outcome. But binary residuals have only two possible response values at a given fitted probability, so visual patterns and approximate normality should not be interpreted as though these were continuous errors.
For grouped binomial data, the response may be a count \(y_i\) of successes from \(n_i\) trials. The fitted mean count is \(n_i\hat{p}_i\), and the variance is \(n_i\hat{p}_i(1-\hat{p}_i)\) when \(\phi=1\). The Pearson and deviance calculations must use counts and trial totals consistently; treating a success proportion as though it were a count changes the residual scale.
Worked Example: A Binary Outcome Surprising Under the Model
A hypothetical logistic GLM predicts a 0.20 probability that a particular device requires a manual inspection. The observed outcome is \(y=1\), meaning inspection was required. Calculate all three residuals, assuming a Bernoulli model with unit weight and \(\phi=1\). Round to four decimal places.
Response residual. The fitted mean is \(\hat{\mu}=\hat{p}=0.20\). Thus \(e=1-0.20=0.80\).
Pearson residual. The Bernoulli variance is \(0.20(1-0.20)=0.20(0.80)=0.16\), with standard deviation \(\sqrt{0.16}=0.40\). Therefore \(r_P=0.80/0.40=2.0000\).
Deviance residual. For an individual Bernoulli outcome of 1, the unit deviance contribution is \(d=2\log(1/\hat{p})\). Here \(d=2\log(1/0.20)=2\log(5)\approx3.2188758\). The residual is positive, so \(r_D=+\sqrt{3.2188758}\approx1.7941\).
Check and interpretation. The observation is above its fitted mean, so both scaled residuals are positive. Its Pearson residual is 2.0000, while the deviance residual is 1.7941; the measures need not agree. The trap is to infer that the outcome was impossible because its predicted probability was low. A probability of 0.20 is not zero, and a single observation does not by itself establish model failure.
For a Gaussian GLM with identity link, the variance function is \(V(\mu)=1\), so \(\operatorname{Var}(Y_i\mid x_i)=\phi\) for unit weights. Its unit deviance contribution is \((y_i-\hat{\mu}_i)^2\), making the deviance residual equal to the response residual. The conventional Pearson residual, by contrast, is the response residual divided by \(\sqrt{V(\hat{\mu}_i)}=1\); a Pearson residual scaled to the model standard deviation also divides by \(\sqrt{\phi}\). This distinction matters when \(\phi\ne1\).
Worked Example: Gaussian Residuals With Nonunit Dispersion
A hypothetical Gaussian GLM predicts a repair duration of 10 hours, and the observed duration is 14 hours. Assume unit weight and dispersion \(\phi=9\), so the model variance is 9 hours squared. Calculate the response residual, conventional Pearson residual, model-standardized Pearson residual, and deviance residual. Round to four decimal places.
Response residual. The observed-minus-fitted difference is \(14-10=4\) hours.
Pearson residuals. Since \(V(\hat{\mu})=1\), the conventional Pearson residual is \((14-10)/\sqrt{1}=4\). To express the difference in model standard-deviation units, divide by \(\sqrt{\phi}=\sqrt{9}=3\): \(4/3=1.3333\).
Deviance residual. The Gaussian unit deviance contribution is \(d=(14-10)^2=16\). Its signed square root is \(+\sqrt{16}=4\), because the observed duration exceeds the fitted duration. This is the conventional unscaled deviance residual; dividing by \(\sqrt{\phi}\) would give \(1.3333\) if a dispersion-scaled version were wanted.
Check and interpretation. The raw difference and unscaled deviance residual are both 4 hours, while the model-standardized Pearson residual is about 1.3333 standard deviations. The common mistake is to compare the conventional Pearson value of 4 directly with a residual already scaled by \(\sqrt{\phi}\). The values are consistent once the dispersion convention is stated.
Choosing a Residual for Diagnostic Review
Use response residuals when the practical size and direction of an error in original units matter. They are often easy to explain to a stakeholder, but they are not a fair cross-observation measure of unusualness when the conditional variance changes with the mean. For example, a count error of 3 may be substantial when the fitted count is near 1 and comparatively ordinary when it is near 100.
Use Pearson residuals when the aim is to scale discrepancies by the family’s variance function. They help flag observations whose errors are large relative to the variability implied by the fitted mean. For comparisons across models or residual summaries, state whether the dispersion adjustment has been applied. A Pearson residual is not automatically a standard normal score, especially in small samples or for discrete outcomes.
Use deviance residuals when a likelihood-based measure of each observation’s discrepancy is useful. Their squares add to the model deviance under the stated convention, which makes them a natural observation-level decomposition of that fit measure. They can be more interpretable than raw errors when the response is discrete, but they too do not guarantee a normal-looking residual distribution.
Confirm whether the outcome is, for example, a count, binary response, grouped binomial count, or continuous Gaussian response. Use the variance function that belongs to that model.
Use response residuals for errors in original units, Pearson residuals for variance-scaled discrepancies, or deviance residuals for likelihood-based discrepancies.
Account for prior weights and determine whether residuals have been scaled by \(\sqrt{\phi}\). State the convention before interpreting their magnitudes.
Check residual signs, magnitudes, and whether their behavior is plausible for the outcome family. Discrete residuals are not expected to behave exactly like continuous normal errors.
In R, a fitted GLM can be inspected with residuals(fit, type = "response"), residuals(fit, type = "pearson"), or residuals(fit, type = "deviance"). These calls select a residual definition; they do not decide whether the model is adequate. Interpret the output alongside the response family, weights, dispersion convention, and modeling purpose. These distinctions are aligned with the SOA Exam PA (Predictive Analytics) syllabus.
Check Your Understanding
For each problem, identify the relevant residual scale and work through the arithmetic before checking the final answer.
- A Poisson model with unit weight and \(\phi=1\) predicts a fitted mean of 9 calls; 12 calls are observed. Find the response and Pearson residuals. (Answer: response residual \(=3\); Pearson residual \(=1.0000\).)
- A Bernoulli model predicts a 0.80 probability of an event, but the event does not occur. Find the response and Pearson residuals, assuming unit weight and \(\phi=1\). (Answer: response residual \(=-0.8000\); Pearson residual \(\approx-2.0000\).)
- A Poisson model predicts a mean of 2 for a unit-weight observation, and the observed count is 0. Calculate the response residual and deviance residual. (Answer: response residual \(=-2\); deviance residual \(=-2.0000\).)
- A Gaussian model with unit weight predicts 6 units; the observation is 9 units and \(\phi=4\). Give the conventional Pearson residual and the model-standardized Pearson residual. (Answer: conventional Pearson residual \(=3.0000\); model-standardized Pearson residual \(=1.5000\).)
- A grouped binomial model has 10 trials, 6 observed successes, and fitted success probability \(0.50\). Assuming \(\phi=1\), calculate the response residual and Pearson residual for the success count. (Answer: response residual \(=1\); Pearson residual \(=1/\sqrt{2.5}\approx0.6325\).)