Why Plot Residuals Against Predictors?
A residual plot against a predictor asks a focused question: does the fitted model tend to miss responses in a particular part of this predictor's range or within a particular category? A pattern can point to a mean structure that is too simple—for example, a curved relationship represented by a straight-line term on the link scale—or to a predictor whose categories differ after accounting for the predictors already in the model. A plot is diagnostic evidence, not a formal test and not proof of a particular cause.
The residual type matters. Raw residuals are observed responses minus fitted means, but their variability can change with the fitted mean in a GLM. Pearson residuals scale that difference by its model-based standard deviation. Deviance residuals are another useful choice and preserve the sign of the casewise deviance contribution. The earlier material on GLM residuals establishes these alternatives; here the emphasis is on what their plots against individual predictors reveal.
For an independent Poisson response with conditional mean \(\mu_i\), the model specifies \(\operatorname{Var}(Y_i\mid x_i)=\mu_i\). Its Pearson residual is
For a Bernoulli response with fitted success probability \(\hat{p}_i\), the variance is \(\hat{p}_i(1-\hat{p}_i)\), giving
These expressions use fitted values, so their residuals are not literally independent observations from a fixed distribution. They are diagnostic scales: under a correctly specified conditional mean and variance, residuals should not show a systematic relationship with a predictor merely because the expected response or its variance changes over that predictor.
Why Pearson Scaling Helps
The justification follows directly from the conditional mean and variance. If \(Y_i\) has conditional mean \(\mu_i\) and variance \(\phi V(\mu_i)\), then the Pearson residual using the true mean is
Conditioning on the predictors, \(E(Y_i-\mu_i\mid x_i)=0\), and multiplying a random variable by a constant divides its variance by the square of that constant. Therefore,
This explains why a raw-residual plot can show a fan as the expected response changes even when the variance model is correct. Pearson scaling compensates for the specified variance. In practice, \(\mu_i\) is replaced by \(\hat{\mu}_i\), so estimated parameters and individual observations can still produce scatter or unusual points.
Worked Example: A Curved Pattern Against a Continuous Predictor
A hypothetical insurer fits an independent Poisson GLM for the number of service calls per account, using a log link and a linear term for account tenure \(x\). The fitted values shown below are the model's estimated means. Assume the Poisson variance specification is appropriate for this diagnostic calculation. Calculate the Pearson residuals and interpret their pattern.
| Tenure \(x\), years | Observed calls \(Y_i\) | Fitted mean \(\hat{\mu}_i\) | \(Y_i-\hat{\mu}_i\) | Pearson residual |
|---|---|---|---|---|
| 0 | 3 | 4 | -1 | -1/2 = -0.5000 |
| 1 | 3 | 5 | -2 | -2/√5 = -0.8944 |
| 2 | 4 | 6 | -2 | -2/√6 = -0.8165 |
| 3 | 10 | 7 | 3 | 3/√7 = 1.1339 |
| 4 | 12 | 8 | 4 | 4/√8 = 1.4142 |
| 5 | 14 | 9 | 5 | 5/3 = 1.6667 |
For example, at tenure 2 the difference is \(4-6=-2\), and the Poisson standard deviation is \(\sqrt{6}\). The Pearson residual is \(-2/\sqrt{6}=-0.8165\), rounded to four decimal places. At tenure 5, it is \((14-9)/\sqrt{9}=5/3=1.6667\). The table gives every fitted residual on the same scale.
The first three residuals are negative and the last three are positive. Thus, at lower tenures, the model tends to predict too many calls; at higher tenures, it tends to predict too few. This orderly change is evidence that the current mean structure may be inadequate. A curved effect of tenure is one possibility, but the plot alone does not establish that explanation: a missing predictor associated with tenure or another modeling issue could produce a similar pattern. The method is to plot the chosen residual against tenure, inspect its direction and shape, then investigate plausible model changes rather than treating the visual pattern as a test result.
Check: Each residual has the sign of \(Y_i-\hat{\mu}_i\). In particular, the first three fitted means exceed the observations and yield negative residuals, while the last three observations exceed their fitted means and yield positive residuals.
Reading Continuous-Predictor Plots
A useful plot includes a horizontal zero reference and displays the predictor on its meaningful scale. Look for broad, repeated structure rather than trying to explain every point. A smooth curve or a sequence of mostly negative residuals followed by mostly positive residuals may indicate that a linear predictor term does not capture the mean relationship. A fan-shaped spread can instead suggest that the variance changes in a way not captured by the model's variance assumption. A cluster of unusual points in one region can warrant closer examination, but a residual plot alone does not establish why those observations differ.
When the predictor is continuous, preserve its actual values: arbitrary grouping can hide local structure or create an impression that depends on cut points. Also distinguish a pattern against a predictor from a pattern against fitted values. The former asks whether model errors vary with a particular explanatory variable; the latter asks whether they vary with the overall predicted response. These plots answer different diagnostic questions.
Worked Example: Residuals Across a Categorical Predictor
A hypothetical Poisson model predicts claim counts using an intercept but not the categorical risk tier \(G\). There are nine independent observations, three in each tier. The fitted mean is 2 for every observation. Assume the Poisson variance equals the mean. Calculate Pearson residuals by tier and assess whether the omitted tier distinctions merit attention.
| Tier | Observed counts | Individual Pearson residuals | Mean residual in tier |
|---|---|---|---|
| A | 0, 1, 2 | -1.4142, -0.7071, 0.0000 | -0.7071 |
| B | 1, 2, 3 | -0.7071, 0.0000, 0.7071 | 0.0000 |
| C | 2, 3, 4 | 0.0000, 0.7071, 1.4142 | 0.7071 |
For any observation, the residual is \((Y_i-2)/\sqrt{2}\). In tier A, the three calculations are \((0-2)/\sqrt{2}=-1.4142\), \((1-2)/\sqrt{2}=-0.7071\), and \((2-2)/\sqrt{2}=0\), with four-decimal rounding. Their mean is \((-1.4142-0.7071+0)/3=-0.7071\). Tier B's residuals sum to zero, so its mean is zero. Tier C's residuals sum to \(0+0.7071+1.4142=2.1213\); dividing by three gives \(0.7071\).
The pattern is ordered across the tiers: the model tends to overpredict tier A and underpredict tier C. The pooled observed count is \(18\), equal to the pooled fitted count \(9(2)=18\), so the overall total conceals the group pattern. Because the categories have a natural order in this example, the progression is easy to describe; a plot should nevertheless treat the predictor as categories, not assume equal spacing between them. A categorical effect may be worth assessing, while recognizing that only three observations per tier make the pattern uncertain.
Check: The residuals sum to zero across all nine observations: tier A sums to \(-2.1213\), tier B to \(0\), and tier C to \(2.1213\). The opposing group patterns can therefore exist even when the pooled residual total is zero.
Binary Responses and Category Comparisons
A binary response can also be plotted against a categorical predictor, but individual residuals take a limited set of values when fitted probabilities are similar. Consider a logistic model with an intercept only, fitted to ten hypothetical policies: five have response \(1\), and five have response \(0\). Its fitted probability is \(\hat{p}=5/10=0.5\). The Bernoulli Pearson residual is \(1\) for a response of 1 and \(-1\) for a response of 0, because the denominator is \(\sqrt{0.5(1-0.5)}=0.5\), while the numerator is respectively \(0.5\) or \(-0.5\).
Worked Example: Comparing Binary Residuals by Group
Suppose those ten policies are divided into two categories of five. Category A has responses \(0,0,0,1,0\), and category B has responses \(1,1,0,1,1\). Calculate the mean Pearson residual in each category under the intercept-only model, then interpret the result.
Each response of 0 has residual \((0-0.5)/0.5=-1\); each response of 1 has residual \((1-0.5)/0.5=1\). Category A has one response of 1 and four of 0, so its residuals sum to \(1-1-1-1-1=-3\), and its mean residual is \(-3/5=-0.6\). Category B has four responses of 1 and one of 0, so its residuals sum to \(1+1-1+1+1=3\), and its mean is \(3/5=0.6\).
The opposite group means indicate that the intercept-only model underpredicts responses in category B and overpredicts them in category A. This is a reason to examine whether the category is relevant to the conditional mean. It is not proof that the category causes the outcome or that the model with a category effect will be adequate. The total is still consistent with the fitted probability: there are five observed successes and five predicted successes overall.
Check: The group residual sums, \(-3\) and \(3\), cancel, matching the zero total residual from five successes and five failures under \(\hat{p}=0.5\).
Common Traps and Limits
A frequent mistake is to interpret the vertical size of raw Poisson residuals as if it had the same meaning everywhere. For instance, deviations of \(2\) at fitted means of \(4\) and \(100\) have raw residuals of 2 in both cases, but their Poisson Pearson residuals are \(2/\sqrt{4}=1\) and \(2/\sqrt{100}=0.2\). The wrong conclusion is that equal raw differences represent equally unusual departures. The correction is to account for the model variance: compare residuals on an appropriate scale and inspect the plot for systematic structure, not just raw magnitude.
A second trap is to assign numbers to nominal categories and read the resulting horizontal positions as meaningful order. If categories are plan types with no natural ordering, coding them 1, 2, and 3 does not make a residual trend from 1 to 3 evidence of a linear effect. Display the categories separately and compare their residual centers and spreads. For genuinely ordered categories, preserve the order but do not assume equal distances unless the coding has that meaning.
- Do not diagnose from one point. A single large residual may be chance variation or an unusual observation; a systematic pattern is about repeated departures.
- Do not equate a pattern with its cause. Curvature may reflect a missing predictor, an unsuitable mean form, or another feature of the data. A plot suggests questions to investigate.
- Do not demand perfectly patternless residuals. Random variation remains, fitted parameters affect residuals, and a finite sample can show accidental runs or clusters.
- Do not confuse zero pooled residual with good fit everywhere. Positive residuals in one group can cancel negative residuals in another, as the examples show.
Check Your Understanding
For each problem, calculate or interpret the predictor-specific residual pattern. Use four decimal places for Pearson residuals when needed.
- A Poisson model has fitted mean \(\hat{\mu}=9\) for an observation with count \(Y=6\). Calculate its Pearson residual and state whether the model overpredicted or underpredicted. (Answer: \(-1.0000\); the model overpredicted.)
- For a Poisson response, fitted means increase across a continuous predictor. Raw residuals appear to fan out, but Pearson residuals show no systematic trend or changing spread. Which plot is more appropriate for assessing the mean pattern, and what conclusion is warranted? (Answer: The Pearson-residual plot; there is no visible systematic predictor pattern, but this alone does not prove the model is correct.)
- An intercept-only Poisson model predicts \(\hat{\mu}=3\) for every record. In one category, observed counts are \(1,3,5\). Calculate the three Pearson residuals and their mean. (Answer: \(-1.1547,\ 0.0000,\ 1.1547\); mean \(0.0000\).)
- A logistic model predicts \(\hat{p}=0.25\) for an observation with \(Y=1\). Calculate its Bernoulli Pearson residual. (Answer: \(0.75/\sqrt{0.25(0.75)}=1.7321\).)
- A nominal predictor is coded 1, 2, and 3, and residuals appear to rise with the code. What is the key diagnostic correction before interpreting this as a trend? (Answer: Plot and compare the categories as distinct levels; numeric codes do not establish an order or equal spacing.)