Recall the 4 assumptions made about residuals in linear models
We will address the 2nd assumption here in this demonstration.
Homoscedascity is the technical term to describe the variance of the residuals being constant across the range of predicted values.
Heteroscedascity is the converse scenario : the variance of the residuals differs along the range of values.
An excellent review of regression diagnostics is provided in John Fox’s aptly named Overview of Regression Diagnostics. Dr. Fox’s car package provides advanced utilities for regression modeling.
library(car)
# Assume that we are fitting a multiple linear regression
# on the MTCARS data
library(car)
fit <- lm(mpg~disp+hp+wt+drat, data=mtcars)
Suppose you plot the individual residuals against the predicted value, the variance of the residuals predicted value should be constant.
Consider the red line in the picture below, intended to indicate the trend in the variance of the residuals over the range of values For the OLS asummption to be valid, the orientation of the red lines should be more or less consistent across the range of values.
plot(fit,which=1,pch=18)
The test for non-constant error variance is implemented using the command ncvTest()
# Evaluate homoscedasticity of Residuals
# non-constant error variance test
library(car)
ncvTest(fit)
## Non-constant Variance Score Test
## Variance formula: ~ fitted.values
## Chisquare = 1.429672, Df = 1, p = 0.23182