A least-squares line can be computed for any scatter of points with at least two distinct predictor values, including points that follow a curve, fan out or drift over time. Before the line is used for inference or prediction, two questions need answers. Do the data fit the model behind the line, and does any single observation decide the result? This lesson reads residual plots and Q-Q plots as evidence about the assumptions, uses hat values to find observations that could pull the line toward themselves, and uses Cook’s distance to find those whose removal would change the fit.
Key terms
Residual plot and linear conditional mean
Definition Classical inference for a line uses the model , with unknown coefficients and and random errors . The linear conditional mean assumption says that , so that the mean response at each predictor value lies on a straight line,
for every in the range studied. A residual plot shows the residuals of the fitted line on the vertical axis against the predictor values or against the fitted values , with a horizontal reference line at zero. When the conditional mean is not linear, the residuals tend to follow a systematic pattern, such as a curve, instead of scattering around zero with no trend across the plot.
In plain words The fitted line removes the straight-line part of the relationship, and the residual plot enlarges what is left. With an intercept, least squares makes the residuals average zero overall, so the question is whether they also average about zero in every part of the predictor range. A plot without a visible pattern is consistent with the assumption but does not prove it, especially with few points.
Example The constructed points with and lie on the curve . Their least-squares line is horizontal, , and the residuals are , , , and . Every fitted value is 2, so a plot against the fitted values would stack all five residuals at one position, and the plot against is the useful one. It shows residuals positive at both ends and negative in the middle, a U shape. They still add to zero, so the zero total hides the curvature instead of repairing it. A squared term justified by the subject matter could describe the curve, and the new fit would need its own residual plot. Trying many shapes on the same small data set and keeping whichever fits best invites overfitting.
Constant variance and heteroscedasticity
Definition The constant variance assumption says that the errors have the same variance at every predictor value, . Heteroscedasticity, also spelled heteroskedasticity, means that this conditional variance changes with . A common sign is a fan shape in a residual plot, with the vertical spread of the residuals growing or shrinking along the horizontal axis. When the linear conditional mean holds, heteroscedasticity does not bias the least-squares coefficients, but the usual standard errors, tests and confidence intervals, which use a single , can be wrong. Prediction intervals built on one common tend to be too wide where the spread is small and too narrow where it is large.
In plain words The line may still describe the mean well while the scatter around it widens. Possible responses are to model how the variance changes, for example with weighted least squares, to fit the model to a transformation of the response such as the logarithm of a positive response, or to use a standard error method designed for unequal variances when the sample is large enough. Each choice changes what is assumed or what is estimated, so it should fit the question being asked.
Example Eight constructed observations have and . The least-squares line is , and the residuals are at , at , at and at , a widening fan. A single residual standard deviation for all eight points is
more than three times the size 0.5 of the residuals at and smaller than the size 2 of the residuals at .
Independent errors
Definition The errors are independent when, given the predictor values, the errors of some observations carry no information about the errors of the others. Dependence is common when several observations come from the same person, device or cluster, or when observations are taken close together in time or space. Independence is judged mainly from the design, meaning how the units were selected or assigned and how the measurements were made. A residual plot in the order of data collection can reveal runs of residuals with the same sign, or cycles, that a plot against may hide. When errors are positively correlated, the usual standard errors are often too small, so intervals are too narrow and tests reject too often.
In plain words Twenty readings from one machine on one afternoon are not twenty independent pieces of information if the machine drifts. Sorting the rows differently or drawing a different plot does not remove such dependence. The analysis has to account for it, for example with a time trend, a term for each cluster or a method for time series.
Example Ten constructed residuals, listed in the order the readings were taken, are , , , , , , , , and . Their signs form only three runs, four positive, then five negative, then one positive, and neighboring residuals are similar in size. If five positive and five negative signs were put in a random order, the average number of runs would be 6. A slow drift during the session, such as a room warming up, could produce this pattern, and the fitted model has no term for it.
Q-Q plot
Definition Exact small-sample t and F inference for a line also assumes normal errors, so that given the predictor values the are independent with distribution . This condition concerns the distribution of the errors around the conditional mean, not the distribution of the predictor values or of all the response values taken together. A normal Q-Q plot, short for quantile-quantile plot, shows the ordered residuals against standard normal quantiles at matching probabilities, for example the values with . If the errors are normal, the points tend to lie near a straight line, and curvature at one or both ends suggests skewness or tails heavier or lighter than normal. Residuals are not the errors. A fit with an intercept forces them to sum to zero, and when the errors are independent with constant variance, the residual variances generally differ from one observation to another, with the hat value defined below. So the plot is approximate evidence, and standardized residuals are often plotted instead.
In plain words The plot asks whether the residuals are spread like a sample from a normal distribution. A nearly straight pattern is consistent with normal errors and a bend is a warning, but with few points either can happen by chance. With many observations the t procedures for the slope can be approximately valid even when the errors are moderately non-normal, while independence and the form of the mean matter at every sample size.
Example Suppose half the observations have and half have , with mean response and normal errors with standard deviation 1. A histogram of all the responses has two separate clusters, near 2 and near 32, and looks nothing like a normal curve, yet the normal-error condition holds exactly. In the other direction, the five residuals , , , and add to zero. Plotted against the normal quantiles , , , and , they lie on a flat line except for the last point, far above it. That shape points to a long right tail, though five points are weak evidence either way.
Hat value
Definition For a least-squares line with an intercept and at least two distinct predictor values, the hat value of observation is
also called the leverage of the observation. It depends only on the predictor values, not on the responses. Each fitted value is a weighted sum of all the responses, with , and is the weight of in its own fitted value. The hat values satisfy and add up to 2, the number of coefficients, so their average is . An observation whose hat value is large compared with that average is called a high-leverage point.
In plain words The hat value measures how unusual an observation’s predictor value is, and so how strongly its response can pull the fitted line toward itself. Because the line is pulled toward such a point, its residual tends to be small, so a small residual does not show that a point is harmless. A large hat value is a potential for influence, not influence itself. Whether the line actually moves depends on whether the response agrees with the pattern of the other points.
Example Five constructed points have and , with least-squares line . Add a sixth point at . Now and , so
far above the average . If the sixth response is , exactly on the line , the refitted line is the same as before, so this high-leverage point does not change the coefficients at all.
Cook’s distance
Definition Consider a least-squares fit with coefficients, so for a line with an intercept, and residual mean square . For an observation with , Cook’s distance is
where is the fitted value for observation from the fit with observation left out. It measures how much all the fitted values change together when that one observation is removed. It can be computed without refitting from
which combines the size of the residual with the hat value. A common rule of thumb treats values near or above 1 as large, and a value far above the others deserves a look at any size.
In plain words Cook’s distance is large when a point combines a sizable hat value with a response far from the line fitted to the other points, so that it pulls the line toward itself. Its own residual can then look modest, because the line has already moved toward it. A large value is a reason to investigate, not an instruction to delete. Check the record for entry or measurement errors, ask whether the observation belongs to the population the analysis is about, and report the results with and without it. Removing a legitimate observation because the p-value looks better without it changes what the analysis means.
Example Give the sixth point at the response 0 instead of 11.6. The line becomes , so one observation has almost erased the positive slope of 1.2. Its residual is only about , smaller in size than the residual of about at , because the line has moved toward it. With and , its Cook’s distance is . By contrast, adding the point to the five original points gives that point a residual of but a hat value of only , since is the mean of the six predictor values. The slope stays 1.2, the intercept rises from to , and Cook’s distance is .
Check yourself
- Match each residual pattern to the assumption it calls into question, and suggest a response that does not discard observations. First, residuals plotted against form a U shape around zero. Second, the vertical spread of the residuals widens steadily from left to right. Third, residuals plotted in collection order show long runs with the same sign.
Show the answer
The U shape questions the linear conditional mean. Consider a curved term or another form of the predictor that the subject matter supports, refit, and check the new residual plot.
The widening spread questions constant variance, so it suggests heteroscedasticity. Model the variance, for example with weighted least squares, fit the model to a suitable transformation of the response, or use standard errors designed for unequal variances.
The runs in collection order question independent errors. Look for drift or other time structure in how the data were collected, and add a time term or use a method for dependent data.
Each pattern is evidence that needs context. None of them proves a particular cause on its own.
- A line with an intercept is fitted to points with predictor values . Find the hat values. The first four points are , , and . Must the point at be influential? Compare the responses 21 and 5 at .
Show the answer
Here and . The hat values are , , , and . They add to 2, and the point at has by far the largest.
It need not be influential. The first four points lie on the line . With response 21, which equals , all five points lie on that line, and the least-squares line is the same with or without the fifth point. With response 5, the line becomes , so the slope drops from 2 to 0.08. The hat value is the same in both cases, and the response decides whether the potential for influence is used.
- An analyst sees that the histogram of the response values is strongly skewed and concludes that the normal-error condition fails. The analyst then deletes the observation with the largest Cook’s distance, finds that the slope’s p-value drops below 0.05, and reports only the second fit. What is wrong with each step?
Show the answer
The normal-error condition is about the errors around the conditional mean, not about the response values taken together. If most observations have small predictor values, a few have large ones and the mean response rises with , the responses inherit that skew even when every error is exactly normal. The right check is a residual plot together with a normal Q-Q plot of the residuals.
A large Cook’s distance is a reason to check the observation, not to remove it. If the record is correct and belongs to the population under study, it stays in the data. The analyst should report the fits with and without it and explain the difference. Choosing a deletion because it makes the p-value small means the reported p-value no longer has its stated meaning, since the analysis was picked after seeing its result.