5
$\begingroup$

My question is how do we check the constant variance assumption in a regression model?

$\endgroup$
1
  • $\begingroup$ Did my answer answer your question? If not, what else do you need to know? If yes, please check the accept button below the voting arrows. $\endgroup$
    – grssnbchr
    Commented Jun 27, 2013 at 19:31

1 Answer 1

6
$\begingroup$

Another name for contant variance assumption is homoskedasticity, and its opposite is heteroskedasticity. To find heteroskedasticity, you can both visually look at the relationship between the fitted values (predicted y) and the residuals and perform the Breusch-Pagan test. In R:

# generate a heteroskedastic independent variable x
set.seed(0)
n <- 1000
x <- rgamma(n, shape=6, scale=1/2)
e <- rnorm(length(x), sd=abs(sin(x)))
# which determines the dependent variable y
y <- x + e
# look at the relationship
plot(y ~ x)

relationship between x and y

By looking at the scatterplot it already becomes apparent that y doesn't have a constant variance.

You can then plot the linear model itself to get a plot of the relationship between the fitted values (predicted y) and the residuals:

# fit a linear model
lm1 <- lm(y ~ x)
# look at the residuals
plot(lm1)
# press enter once

relationship between fitted values and residuals

Again, it becomes pretty clear that the variance of the residuals isn't constant.

To get a quantitative measure of heteroskedasticity, perform the Breusch-Pagan test (requires the lmtest-Package):

# load library
library(lmtest)
# perform test
bptest(lm1)

This gives:

    studentized Breusch-Pagan test

data:  lm1 
BP = 12.2634, df = 1, p-value = 0.0004619

A high BP-Value with a significant p-value means that the Null-Hypothesis of fit and residuals being uncorrelated can be rejected, thus you have heteroskedasticity in your data (in this case).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.