liveBook · Manning

Homoscedasticity

As explained in Statistics Every Programmer Needs

Homoscedasticity is the regression condition that errors have constant variance across levels of the predictors or fitted values.

Homoscedasticity is the regression condition that residual variability remains consistent across all predictor values or fitted values. When residual spread changes systematically, heteroscedasticity can produce inefficient estimates, biased standard errors, and unreliable hypothesis tests or confidence intervals. section 4.2.4

Assess homoscedasticity as part of regression assumption checking:

  • Plot residuals against fitted values and look for changing spread or a systematic pattern. section 4.2.4
  • Apply the Breusch–Pagan test, whose null hypothesis states that residuals have constant variance. section 4.2.4
  • Use a p-value below 5% to reject homoscedasticity and conclude that residual variance is heterogeneous; a larger p-value does not reject constant variance. section 4.2.4

Breusch–Pagan diagnostic in Python

With a fitted statsmodels regression named lm, run het_breuschpagan(lm.resid, lm.model.exog) and inspect element 1 of the result. The reported p-value, 0.181071316321208, exceeds 0.05, so the test does not reject constant residual variance. section 4.2.4

>>> plt.scatter(lm.fittedvalues, lm.resid)    #1
>>> plt.axhline(y = 0, color = 'red', 
>>>             linestyle = '--')     #2
>>> plt.title('Residuals Plot')     #3
>>> plt.xlabel('Fitted Values')     #4
>>> plt.ylabel('Residuals')   #5
>>> plt.show()    #6

Use the residuals-versus-fitted-values plot to inspect whether residual spread stays approximately constant across the regression’s fitted values. section 4.2.4

How Statistics Every Programmer Needs covers it

How deep it goes
Defines constant residual variance, explains inferential consequences, and gives visual and Breusch–Pagan diagnostics.
Examples
Uses residuals-versus-fitted-values plots and a statsmodels Breusch–Pagan test returning p-value 0.181.
What it assumes
Assumes a fitted linear regression, predictors, fitted values, residuals, and p-value interpretation.
What you can do after
Diagnose with statsmodels and interpret whether regression residuals provide evidence of nonconstant variance.
How it connects
Connects linear regression with residuals, heteroscedasticity, standard errors, hypothesis tests, and confidence intervals.

Also explained in

Compare how 3 books explain homoscedasticity →

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.