liveBook · Manning

Residual error

As explained in Effective Data Analysis

A residual is the difference between an observed outcome and the value predicted by a fitted model.

A residual is an observed outcome minus the value predicted by a fitted model. It shows how far the model missed on one record. In regression, examining residuals alongside coefficients and overall fit metrics helps reveal discrepancies those summaries can hide. section 9.4 section 9.1.2

Use residuals to check where a regression model struggles:

  • Plot residuals against predicted values. Look for patterns, changing spread, gaps, and unusually large errors rather than judging the model by one fit metric. section 9.2.2 section 4.3.2
  • Inspect the underlying records behind outliers. A suspicious prediction may reflect a data problem; a legitimate outlier calls for a considered modeling decision. section 9.2.2
  • Check the distribution of residuals and revisit model assumptions. Patterns may point to a missing variable or transformation; inconsistent error spread may call for a transformed outcome or weighted least-squares regression. section 9.4 section 4.3.2
housing_prices["residuals"] = model.resid
housing_prices["predicted_values"] = model.predict()     #1

plt.scatter(
    housing_prices["predicted_values"],
    housing_prices["residuals"]
)     #2
plt.axhline(y=0, color= "black", linestyle="-")     #3

The housing-price workflow stores fitted residuals and predictions, then plots each residual against its predicted price with a zero line for reference. section 9.1.2

Investigating a rat-sighting prediction

A residual plot for daily rat sightings shows a gap and outliers among low predicted counts. Inspecting those records reveals one with missing weather data previously filled with zero. Removing that bad record and reassessing the plot is more defensible than automatically discarding every outlier; other unusual records may be legitimate. section 9.2.2

Treat a residual plot as a diagnostic, not a verdict. After correcting data or changing the outcome—for example, with a square-root transformation—fit the model again and check its residuals before relying on its predictions. section 9.2.2 section 9.4

How Effective Data Analysis covers it

How deep it goes
Defines observed-minus-predicted differences and works through plots, record checks, and revision without deriving a formal residual test.
Examples
Plots housing-price and rat-sighting residuals and investigates a rat-sighting record with missing weather entered as zero.
What it assumes
Assumes basic familiarity with regression predictions while defining residuals from observed and predicted outcomes.
What you can do after
Diagnose/debug with it by locating unusual errors, checking their records, and reassessing residuals after revising a regression model.
How it connects
Links residuals to linear regression, outliers, normality, homoscedasticity, and outcome transformations.

Also explained in

Compare how 11 books explain residual error →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.