Site icon R-bloggers

Heteroscedasticity

[This article was first published on V. » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If a model is estimated using the following code:
lm(y~x1+x2)->p

1. bptest(p) does the Breuch Pagan test to formally check presence of heteroscedasticity. To use bptest, you will have to call lmtest library.

2. If the test is positive (low p value), you should see if any transformation of the dependent variable helps you eliminate heteroscedasticity. Also check if the right hand side of the model is okay.

3. If 2 does not work, you can use the white’s heteroscedasticity-corrected covariance matrices to make inference. Package car has a function hccm that gives you the heteroscedasticity-corrected covariance matrix (there is a similar function in package sandwich also). coeftest(p,vcov=hccm(p)) will give you the results of the tests using this matrix. Use these results instead of summary(p).

library(lmtest)
library(car)
bptest(p)
coeftest(p,vcov=hccm(p))< !-- technorati tags begin -->

Tags: GNU-R

< !-- technorati tags end -->

To leave a comment for the author, please follow the link and comment on their blog: V. » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.