liveBook · Manning

Independence of residuals

As explained in Statistics Every Programmer Needs

Independence of residuals is the condition that regression errors are not correlated with one another.

Independence of residuals means that regression errors are not correlated with one another. Correlated residuals can indicate that the model missed a systematic pattern. section 4.2.4

Assess the assumption with the Durbin–Watson test:

  • Compute a statistic from squared differences between successive residuals divided by the total squared residuals. section 4.2.4
  • Interpret values from 1.5 to 2.5 as generally consistent with failing to reject no correlation. section 4.2.4
  • Treat values nearer 0 or 4 as stronger evidence of positive or negative residual correlation. section 4.2.4

Testing residual independence in Python

Use statsmodels: `from statsmodels.stats.stattools import durbin_watson`; then evaluate `durbin_watson(lm.resid)`. A result of 2.3264601831112186 falls within the usual 1.5–2.5 range, supporting the assumption of independent residuals. section 4.2.4

How Statistics Every Programmer Needs covers it

How deep it goes
Defines residual correlation, gives the Durbin–Watson formula and thresholds, and stops short of remedies for detected dependence.
Examples
Uses a statsmodels residual vector and reports a Durbin–Watson statistic of 2.3264601831112186.
What it assumes
Assumes a fitted linear regression with accessible residuals and teaches the independence assumption from its definition.
What you can do after
Diagnose/debug with it by testing residual correlation using statsmodels and interpreting the resulting statistic.
How it connects
Connects linear regression, residuals, correlation, and the Durbin–Watson test.

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.