# How to test if the errors of a linear regression are constant? [duplicate]

Possible Duplicate:
Kruskal-Wallis or Fligner test to check homogeneity of variances?

Is there a test to check if the residuls of a linear regression are constant?

Thanks

• Do you mean how to check if the residuals of a linear regression have a constant variance? The residuals from a regression will of course per definition be random... Sep 23, 2011 at 15:30
• The residuals can't be constant. The math of a linear regression is such that some must be positive and some negative. Perhaps you mean something else.
– John
Sep 23, 2011 at 15:31
• To learn about tests for constant variance, you can look up the terms homo- and hetero-skedasticity on this site. Maybe you had in mind a constant mean. As in, residuals should not be generally high for some values of predicted Y but generally low for others. You could test this by dividing your predicted Y into discrete groups and running an anova using the residuals as the dependent variable. Sep 23, 2011 at 16:07
• Closing, because this question is either empty (interpreted as written) or it covers previous ground.
– whuber
Sep 23, 2011 at 16:18

I'm going to assume you mean a test for constant variance for the residuals. The following R code illustrates the test.

library(lmtest)
# Create data set
y<-sin(1:100)
x<-y+rnorm(100, 0.2, 0.2)
# Build model
lmfit<-lm(y~x)
# Perform the Breusch-Pagan test against heteroskedasticity
res<-bptest(lmfit)


If the p-value returned from the bptest is > 0.2 you cannot reject the null hypothesis of constant variance.