Residual Analysis

1

Residual Analysis

Residual analysis is one of the most powerful diagnostic tools available to anyone building or evaluating a regression model. Once a model has been fitted, the immediate question is not simply "how well does it fit?" but rather "does it fit correctly?" A model can appear to explain a reasonable proportion of variance while still violating fundamental assumptions in ways that make its predictions unreliable and its inferences invalid. Residuals — the signed differences between what the model predicted and what was actually observed — provide a direct, granular record of the model's failures. Studying their behavior, patterns, and distribution reveals whether the model's assumptions are tenable and whether any remedial action is needed.

What Are Residuals?

At its most fundamental level, a residual is defined as:

e_i = y_i − ŷ_i

where y_i is the observed value of the outcome for observation i, and ŷ_i is the predicted (fitted) value produced by the regression model for that same observation. This simple subtraction carries considerable meaning:

  • A positive residual means the observed value was higher than what the model predicted — the model underestimated that observation.
  • A negative residual means the observed value was lower than what the model predicted — the model overestimated that observation.
  • A residual of exactly zero means the model's prediction was perfect for that case, though this is rarely expected in practice.

Collectively, residuals capture everything the model failed to explain. In a well-specified model with valid assumptions, the residuals should look like pure random noise — they should contain no systematic information, no patterns, and no structure. The moment residuals begin to show structure (curves, trends, clusters, changing spread), that structure is evidence that the model has missed something important about the underlying data-generating process. This is why residuals serve as such a direct window into model performance and assumption validity.

In ordinary least squares (OLS) regression, the model is fit by the specific criterion of minimizing the sum of squared residuals:

Minimize Σ e_i² = Σ (y_i − ŷ_i)²

This means OLS is not just using residuals as a diagnostic afterthought — residuals are the very quantity the estimation procedure is built around. The fitted regression coefficients are exactly those values that make the squared residuals as small as collectively possible. Understanding what the residuals look like after fitting therefore tells us how successful (and how appropriate) that optimization was.

Computing Residuals

The practical steps for computing residuals are straightforward but important to execute carefully:

  • Step 1 — Fit the regression equation. Using your sample data, estimate the regression coefficients (intercept and slopes) through OLS or another estimation method. For a simple linear regression this produces an equation of the form ŷ = b₀ + b₁x; for multiple regression, ŷ = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ.
  • Step 2 — Generate predicted (fitted) values. Apply the estimated equation to each observation's predictor values. Every observation in the dataset receives its own predicted value based on its specific combination of predictors.
  • Step 3 — Subtract predicted from observed. For each observation, compute e_i = y_i − ŷ_i. The result is a vector of residuals with one value per observation.

Consider a simple numeric example. Suppose we fit a regression of exam score (y) on hours studied (x) and obtain the equation ŷ = 40 + 5x. For a student who studied 6 hours and scored 74:

ŷ = 40 + 5(6) = 70
e = 74 − 70 = +4

The model predicted 70 but the student scored 74, so the residual is +4 (an underestimate). For another student who studied 4 hours and scored 56:

ŷ = 40 + 5(4) = 60
e = 56 − 60 = −4

The model predicted 60 but the student scored 56, giving a residual of −4 (an overestimate).

Standardized residuals are a particularly useful variant computed alongside raw residuals. Because the raw residual's scale depends on the units and variance of the outcome variable, direct comparison across observations or across different models is difficult. Standardizing removes this scale dependency:

e_i (standardized) = e_i / s_e

where s_e is the standard deviation of the residuals (also called the residual standard error or root mean square error). Standardized residuals are expressed in units of standard deviations, making them directly interpretable: a standardized residual of +2.5 means that observation's raw residual is 2.5 standard deviations above the mean residual. This standardization is essential for outlier detection, as discussed later.

Residual Plots: Residuals vs. Fitted Values

The most universally used diagnostic display in regression analysis is the residuals-vs-fitted-values plot, in which the fitted (predicted) values ŷ_i are plotted on the horizontal axis and the corresponding residuals e_i are plotted on the vertical axis. A horizontal reference line at zero is typically included.

When all of OLS regression's key assumptions are satisfied — linearity, independence, constant variance, and normality — this plot should display a random, structureless cloud of points centered near zero across the entire horizontal range. No systematic patterns should be visible; the points should scatter randomly above and below the zero line with roughly equal density and spread throughout.

Departures from this ideal pattern each diagnose a different type of problem:

  • A curved or arched pattern (e.g., residuals that are mostly positive at low and high fitted values, but mostly negative in the middle, or vice versa) indicates that the relationship between predictors and outcome is not linear. The model is systematically wrong in a structured way — it underestimates in some regions and overestimates in others.
  • A fan-shaped or funnel-shaped pattern — where the spread of residuals increases (or decreases) as fitted values increase — is the classic signature of heteroscedasticity, meaning the variance of the errors is not constant across the range of fitted values. This is one of the most important violations to detect because it directly undermines the reliability of standard errors.
  • Isolated points far from the zero line can indicate outliers — observations that the model fits very poorly regardless of where they fall on the fitted-value axis.

Below is an illustrative summary of what different residual plot patterns indicate:

Pattern in Residual Plot What It Suggests Possible Remedy
Random scatter around zero Assumptions appear satisfied No action needed
Curved or arch-shaped pattern Non-linearity in the relationship Add polynomial terms or transform variables
Fan or funnel shape (spread increases with fitted values) Heteroscedasticity (non-constant variance) Log/square-root transform outcome; use weighted least squares
Fan or funnel shape (spread decreases with fitted values) Heteroscedasticity (variance decreases) Variance-stabilizing transformation
A few extreme points far from zero Potential outliers Investigate individual cases; consider robust regression
Cyclical or wave-like pattern Autocorrelation (often in time series data) Use time-series models; add lag terms

Detecting Non-Linearity Through Residuals

One of the clearest uses of residual plots is to detect violations of the linearity assumption. OLS regression assumes that the true relationship between each predictor and the outcome is linear (after accounting for all other predictors). If this assumption is violated, the model is misspecified — it is fitting the wrong functional form to the data.

A non-random, curved pattern in the residuals-vs-fitted plot is direct evidence of non-linearity. Imagine fitting a simple linear regression to data where the true relationship is quadratic (a U-shaped curve). The linear model will overestimate values in the middle range and underestimate at the extremes, producing a characteristic U-shaped or inverted-U-shaped pattern in the residuals. The residuals are not randomly scattered — they are systematically positive in some regions and systematically negative in others, which means the model is making predictable errors that a better-specified model would not make.

When there are multiple predictors, the aggregate residuals-vs-fitted plot may not reveal which specific variable is causing the non-linearity. In this case, partial residual plots (also called component-plus-residual plots) are valuable: these plot residuals against each individual predictor separately, allowing the analyst to identify exactly which predictor is exhibiting a non-linear relationship with the outcome after accounting for the others.

For example, if a multiple regression model includes age, income, and education as predictors, and residuals plotted against age show a clear curve while residuals plotted against income and education appear random, this points to age being the variable with a non-linear effect. The analyst can then:

  • Add a quadratic term (e.g., age²) to capture the curved relationship.
  • Apply a variable transformation such as taking the logarithm or square root of the predictor.
  • Switch to a non-linear modeling approach such as generalized additive models (GAMs) or spline regression, which can fit flexible, smooth curves to the data without assuming a specific parametric form.

The key insight is that non-linearity detected through residuals is not a minor cosmetic issue — a misspecified functional form leads to systematically biased predictions and coefficients that cannot be meaningfully interpreted as the true marginal effect of the predictor.

Assessing Homoscedasticity with Residuals

The OLS assumption of homoscedasticity states that the variance of the error terms is constant across all values of the predictors (or equivalently, across all fitted values). When this assumption holds, the spread of residuals in the residuals-vs-fitted plot is roughly uniform from left to right — the vertical "width" of the cloud of points stays approximately the same throughout.

When residual variance is not constant — a condition called heteroscedasticity — several important consequences follow:

  • OLS coefficient estimates remain unbiased (they are still centered on the true values on average), but they are no longer efficient — they are no longer the minimum-variance unbiased estimators.
  • The standard errors computed by standard OLS formulas become incorrect — they may be inflated or deflated depending on the pattern of heteroscedasticity. This directly compromises the validity of t-tests and F-tests for the regression coefficients.
  • Confidence intervals for coefficients will be too wide or too narrow, leading to over-confident or under-confident inferences.

A typical real-world example of heteroscedasticity arises in income data: models predicting income often show that the variability of income is much larger for high-income individuals than for low-income individuals. A fan-shaped residual plot (narrow at low fitted values, wide at high fitted values) would clearly reveal this. Another common context is modeling physical measurements: the error in measuring a large object tends to be larger in absolute terms than the error in measuring a small object.

Corrective approaches for heteroscedasticity include:

  • Variance-stabilizing transformations: Taking the natural logarithm of the outcome variable is the most common remedy when variance increases with the level of the outcome. The square-root transformation is another option, particularly useful for count data. After transformation, re-examining the residual plot usually reveals a more uniform spread.
  • Weighted least squares (WLS): Instead of minimizing the unweighted sum of squared residuals, WLS assigns each observation a weight inversely proportional to its variance. Observations with higher variance contribute less to the objective function, correcting the efficiency problem directly.
  • Heteroscedasticity-consistent (robust) standard errors: Also known as "sandwich" standard errors or HC standard errors, these adjust the estimated standard errors to be valid even in the presence of heteroscedasticity, without changing the coefficient estimates themselves.

Identifying Outliers and Influential Points via Residuals

Residuals also serve as the primary instrument for identifying outliers — observations that are unusually poorly fit by the model — and influential observations — cases that, by virtue of their position in the data, exert a disproportionate effect on the estimated regression equation.

Using standardized residuals for outlier detection is preferable to using raw residuals because standardization accounts for the natural variation in the data. Common thresholds used in practice are:

  • |standardized residual| > 2: A commonly used threshold for initially flagging potential outliers. Under normality, roughly 5% of observations are expected to exceed this threshold by chance, so some false flags are expected in large samples.
  • |standardized residual| > 3: A stricter threshold that flags more extreme cases. Under normality, fewer than 0.3% of observations would be expected to exceed this threshold by chance, making it a stronger signal.

It is important to distinguish between two different types of unusual observations:

  • Outliers in the outcome (Y-direction): These are observations where the residual is very large in absolute value — the model fits them poorly regardless of where they fall on the predictor axis. They have high standardized residuals.
  • High-leverage points: These are observations with extreme values of the predictor(s) — they are far from the center of the predictor space. High-leverage points have the potential to pull the regression line toward them because the regression line, by construction, is more sensitive to observations at the extremes of the predictor range. Leverage is measured by a statistic called the hat value (h_ii), with higher hat values indicating greater leverage. A common rule of thumb flags observations with h_ii > 2(k+1)/n, where k is the number of predictors and n is sample size.
  • Influential observations: An observation is truly influential if removing it substantially changes the estimated regression coefficients. Influential points typically combine high leverage with a large residual. Cook's Distance is a widely used single statistic that quantifies overall influence by measuring how much all fitted values change if observation i is removed. A Cook's Distance greater than 1 (or greater than 4/n by a more conservative guideline) is often used as a flag.

The appropriate response to an identified outlier or influential observation requires careful judgment — never automatic removal. The analyst should investigate:

  • Is the unusual value the result of a data entry error or measurement error? If so, correcting or removing it is clearly justified.
  • Does the observation represent a genuinely different population from the rest of the data? If so, the model may need to be fit separately for different subgroups, or a more flexible model may be needed.
  • Is the observation legitimately extreme but real? In that case, removing it would distort the model — the correct approach is to acknowledge its influence, potentially report results both with and without it, and consider whether a robust regression method is more appropriate.

Automatically discarding outliers simply because they are unusual is a form of data manipulation that can introduce serious bias into the analysis.

Normality of Residuals

The OLS regression framework assumes that the error terms (and therefore the residuals) are approximately normally distributed. This assumption is required for the t-statistics and F-statistics computed from the regression output to follow their theoretical distributions under the null hypothesis, which in turn determines the validity of p-values and confidence intervals in small samples. (In large samples, the central limit theorem provides some protection against moderate departures from normality.)

The normality assumption applies specifically to the residuals, not to the outcome or predictor variables themselves — a common point of confusion. The predictors can be highly skewed or non-normal without violating regression assumptions; what matters is the distribution of the errors around the regression line.

Several tools are used to evaluate normality of residuals:

  • Q-Q (Quantile-Quantile) Plot: This is the most commonly used and most informative graphical diagnostic for normality. The quantiles of the standardized residuals are plotted on the vertical axis against the corresponding quantiles of a standard normal distribution on the horizontal axis. If the residuals are perfectly normally distributed, all points will fall exactly on the 45-degree diagonal reference line. In practice, perfect alignment is never expected, but close alignment along the diagonal is reassuring. Systematic departures reveal specific types of non-normality:
    • An S-shaped curve (points below the line at the left tail and above it at the right tail) indicates a distribution with heavier tails than the normal (leptokurtic), suggesting more extreme values than expected.
    • An inverted S-shape suggests lighter tails than the normal (platykurtic).
    • Points deviating only at one end suggest skewness — a long tail in one direction.
  • Histogram of Residuals: A histogram provides an accessible and intuitive visual check. Under normality, the histogram should display a roughly symmetric, bell-shaped distribution centered at zero. This is less precise than the Q-Q plot for detecting subtle departures but is more immediately interpretable and useful for communicating results to a non-technical audience.
  • Formal normality tests: The Shapiro-Wilk test is the most widely used formal hypothesis test for normality in the regression context. The null hypothesis is that the residuals are normally distributed, and a small p-value leads to rejection of normality. Other formal tests include the Kolmogorov-Smirnov test and the Anderson-Darling test. However, these formal tests have an important limitation: in large samples, they become extremely sensitive and will detect even trivially small, practically inconsequential departures from normality as statistically significant. In small samples, they have low power and may fail to detect important departures. For these reasons, formal normality tests should always be interpreted alongside visual diagnostics rather than used in isolation.

When serious non-normality is detected in the residuals, possible remedies include transforming the outcome variable (a log transformation often helps with right-skewed outcomes), identifying and addressing outliers that may be distorting the distribution, or considering a generalized linear model (GLM) that makes a different distributional assumption better suited to the data (for example, a Poisson model for count outcomes or a logistic model for binary outcomes).

In summary, residual analysis is not a single check but a comprehensive diagnostic process that examines the full character of the errors the model makes. Together, the residuals-vs-fitted plot, partial residual plots, Q-Q plots, histograms, and standardized residual diagnostics form an integrated toolkit for assessing whether a regression model is correctly specified, whether its assumptions are met, and where it may need improvement. No regression analysis is complete without a thorough examination of its residuals.

NotesThe topic covers all listed subtopics: definition and interpretation of residuals, OLS connection, computation steps (including standardized residuals), residuals-vs-fitted plots and their patterns, non-linearity detection and remedies, homoscedasticity assessment and consequences of heteroscedasticity, outlier/influential point identification (standardized residuals, leverage, Cook's Distance), and normality assessment (Q-Q plot, histogram, Shapiro-Wilk). A reference table for residual plot patterns is included as an HTML table.