Residual Diagnostics in Linear Regression
Residuals
Recall the linear regression model:
with
-
What major assumptions are we making?
- The response function is linear.
- The errors are normally distributed.
- The errors have constant variance (Homoscedasticity).
- The errors are independent and identically distributed.
-
Other considerations
- Does the model fit all but one or a few outlying observations?
- Have one or several important predictor variables been omitted from the model?
Notice the true errors can be expressed as:
Note: The errors are unobservable.
Note: The best guess of the true errors are the residuals , .
Definition
Then the ith residual is defined by:
Analyzing the residuals provides insight on whether or not the regression assumptions are satisfied.
- Sample mean and sample variance of the residuals
- Although the errors are independent random variables, the residuals are not independent random variables.
This can be seen by the following two properties:
Semistudentized residuals
Definition
Let be the residual defined in and let be the mean square error.
Then the ith semistudentized residual is defined by:
Studentized residuals
Recall that the residual vector can be expressed as
where the hat matrix is defined by
The mean and variance of the residual vector are respectively
Consequently, the ith studentized residual is defined by:
where is the ith diagonal element of the hat matrix .
Note: If is big ( is close to 1 for an outlier)
Deleted residuals
A useful refinement to make residuals more effective for detecting outlying observations is to measure the ith residual when the fitted regression is based on all of the cases except the ith one. Denote
- : the fitted regression equation based on all cases except the ith one.
- the ith fitted response value based on the predicted model
Consequently, the deleted residual denoted is defined by

Note: This relates to leave-one-out cross validation.
We want to studentize (or standardize) the deleted residuals, i.e., we want to find an expression for
An algebraically equivalent expression for that does not require a recomputation of the fitted regression function omitting the ith case is:
Define as the mean square error based on all cases except the ith one.
The following equation analogous to relates with the regular :
Studentized deleted residuals
Using the above relation, the studentized deleted residuals can be expressed as:
Uses of studentized deleted residuals
- Using the deleted studentized residuals in diagnostic plots is a common technique of validating the regression assumptions.
- The deleted studentized residuals are particularly useful in identifying outlying values.
Proof. Derivation of the Studentized Deleted Residual
The Studentized Deleted Residual (also called the Externally Studentized Residual) is defined as:
Where:
- : the residual of observation
- : the leverage of observation (diagonal of the hat matrix)
- : the variance of residuals calculated by excluding observation
Step 1: Express
We estimate the leave-one-out residual variance as:
We can approximate the leave-one-out sum of squared errors as:
Thus:
Step 2: Substitute into the definition of
Plug into the original formula:
Step 3: Simplify the expression
Multiply terms in the denominator:
So we arrive at:
This formula allows you to compute the Studentized Deleted Residual without explicitly re-fitting the model for each observation, making it highly efficient for outlier diagnostics.
Use the studentized or deleted studentized residuals to construct residual plots.
Some recommendations follow:
-
Scatter plot matrix of all variables.
Linearity, Constant Variance, General exploratory analysis -
Plot of the studentized residuals against all (or some) of the predictor variables .
Linearity, Constant Variance, Normality, Independence -
Plot of the studentized residuals against fitted values.
Same as the previous plot -
Plot of the studentized residuals against time or other sequence.
Independence, Normality -
Plots of the studentized residuals against omitted predictor variables.
Model validation -
Box plot (or histogram) of the studentized residuals.
Normality -
Normal probability plot of studentized residuals.
Normality, Linearity
Summary
| Term | Symbol | Formula | Description |
|---|---|---|---|
| Residual | The raw error between the observed value and the predicted value. | ||
| Semistudentized Residual (Semistandardized Residual) | Raw residual divided by the overall RMSE (ignores leverage). | ||
| Studentized Residual (Internally Studentized Residual, Standardized Residual) | Adjusts residual by both RMSE and leverage | ||
| Deleted Residual | The residual when observation is left out from model fitting (leave-one-out prediction error). | ||
| Studentized Deleted Residual (Externally Studentized Residual) | Residual scaled by RMSE computed excluding observation . Most reliable for outlier detection. |
Notes
- : The standard deviation of residuals computed using all observations (i.e., the RMSE).
- : The standard deviation of residuals computed by excluding observation from the model. This is used in externally studentized residuals.
- : The leverage of observation — it represents how much influence observation has on its own predicted value (i.e., the diagonal element of the hat matrix ).
Practical Tips
- In real-world applications, the Studentized Deleted Residual (also called Externally Studentized Residual) is most commonly used for outlier detection, because it accounts for the influence of the observation being tested.
- The Deleted Residual (i.e., the prediction error when leaving out a point) is important for assessing predictive performance, especially in cross-validation contexts.
- The Semistudentized Residual is less commonly used in practice, but it serves as a basic form of normalization (dividing residuals by the global RMSE).
Example
import numpy as np import pandas as pd import matplotlib.pyplot as plt import statsmodels.api as sm from statsmodels.stats.outliers_influence import OLSInfluence # Simulate new data with an internal outlier np.random.seed(42) n = 30 x = np.linspace(0, 10, n) y = 3 * x + np.random.normal(0, 2, n) # Add an outlier within the range of x but with a strange y value x = np.append(x, 5.5) # within x range y = np.append(y, 30) # y value inconsistent with trend at x=5.5 # Create new DataFrame data_internal = pd.DataFrame({'x': x, 'y': y}) X_internal = sm.add_constant(data_internal['x']) model_internal = sm.OLS(data_internal['y'], X_internal).fit() # Get influence measures influence_internal = OLSInfluence(model_internal) studentized_residuals_internal = influence_internal.resid_studentized_external # Plot fig, ax = plt.subplots(figsize=(10, 6)) ax.scatter(range(len(studentized_residuals_internal)), studentized_residuals_internal, color='blue') ax.axhline(y=3, color='red', linestyle='--', label='Threshold (+3)') ax.axhline(y=-3, color='red', linestyle='--', label='Threshold (-3)') ax.set_xlabel('Observation Index') ax.set_ylabel('Studentized Deleted Residual') ax.set_title('Studentized Deleted Residual Plot') # Highlight potential outliers outlier_indices_internal = np.where(np.abs(studentized_residuals_internal) > 3)[0] for idx in outlier_indices_internal: ax.annotate(f"{idx}", (idx, studentized_residuals_internal[idx]), textcoords="offset points", xytext=(0, 10), ha='center', color='red') ax.legend() plt.tight_layout() plt.show() # Return suspected outlier info print('Outlier Info: \n', data_internal.iloc[outlier_indices_internal])
Outlier Info: x y 30 5.5 30.0
Note: Understanding Hat Matrix
In linear regression, the predicted values can be written as:
Here, is called the hat matrix. It maps the observed values to the predicted values :
The diagonal element shows how much the prediction depends on its own observed value :
Why is called "Leverage"?
- tells us how much influence observation has on its own predicted value.
- If is large, then contributes a large weight to predicting .
- This usually happens when is far from the center of the predictor space.
- Such points are said to have high leverage, because they can pull the regression line toward themselves.
Properties of
- (where is the number of model parameters including the intercept)
- Average leverage:
- A rule of thumb: if or , the point may be considered high leverage
High Leverage ≠ Outlier
- A high doesn't necessarily mean the point is an outlier.
- To detect influential outliers, we need to look at both:
- The residual
- The leverage
- → This is what studentized deleted residuals are designed to detect.
Conclusion
- (leverage) measures how much the predicted value is influenced by the actual observation .
- High leverage points are far from the center of the -space and can strongly affect the regression fit.