liveBook · Manning

Durbin–Watson test

As explained in Statistics Every Programmer Needs

durbin_watson is a statsmodels function that computes the Durbin–Watson statistic from regression residuals.

The Durbin–Watson test detects correlation among regression residuals, testing whether the independence assumption is plausible. Its statistic ranges from 0 to 4. section 4.2.4

Interpret the statistic as follows:

  • Values between 1.5 and 2.5 generally support failing to reject the null hypothesis of no residual correlation. section 4.2.4
  • Values near 0 indicate stronger positive correlation, while values near 4 indicate stronger negative correlation. section 4.2.4
  • Compute the statistic as squared differences between successive residuals divided by total squared residuals. section 4.2.4

Python calculation

Pass the fitted model's residuals to statsmodels: from statsmodels.stats.stattools import durbin_watson; print(durbin_watson(lm.resid)). A reported value of 2.3264601831112186 supports the independence assumption under the stated interpretation. section 4.2.4

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the statistic, formula, range, interpretation, and Python calculation, but does not develop a formal derivation.
Examples
Uses regression residuals and a statsmodels calculation producing 2.3264601831112186.
What it assumes
Assumes a fitted linear regression and access to its residuals, while defining residual independence and correlation.
What you can do after
Diagnose residual independence with statsmodels and interpret the resulting statistic against its stated range.
How it connects
Connects residual correlation with linear regression assumptions and residual diagnostics.

Related concepts

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.