Carrasco-Torrecilla, Roman R
2008-Sep-04 13:03 UTC
[R] Correct for heteroscedasticity using car package
Dear all, Sorry if this is too obvious. I am trying to fit my multiple regression model using lm() Before starting model simplification using step() I checked whether the model presented heteroscedasticity with ncv.test() from the CAR package. It presents it. I want to correct for it, I used hccm() from the CAR package as well and got the Heteroscedasticity-Corrected Covariance Matrix. I am not sure what am I supposed to do with the matrix. I guess I should run my model again telling it to use that matrix but I don't really find the parameter in lm() to tell R so. I guess it should be somewhere in weights? I would really appracite if you could show me how I would do it or recommend a text on how to correct heteroscedasticity with R. Many thanks. Roman Carrasco.
Dear Roman, You can use the coefficient-covariance matrix returned by hccm() for calculating "corrected" standard errors for the coefficients. Alternatively, if you know the pattern of heteroscedasticity [as you probably do if you used ncv.test()], you could try to correct for it by a transformation of the response variable or by weighted-least-squares estimation. I hope this helps, John ------------------------------ John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of Carrasco-Torrecilla, Roman R > Sent: September-04-08 9:03 AM > To: r-help at r-project.org > Subject: [R] Correct for heteroscedasticity using car package > > Dear all, > Sorry if this is too obvious. > I am trying to fit my multiple regression model using lm() > Before starting model simplification using step() I checked whether the > model presented heteroscedasticity with ncv.test() from the CAR package. > It presents it. > > I want to correct for it, I used hccm() from the CAR package as well and > got the Heteroscedasticity-Corrected Covariance Matrix. > > I am not sure what am I supposed to do with the matrix. I guess I should > run my model again telling it to use that matrix but I don't really find > the parameter in lm() to tell R so. I guess it should be somewhere in > weights? > > I would really appracite if you could show me how I would do it or > recommend a text on how to correct heteroscedasticity with R. > > Many thanks. > > Roman Carrasco. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On Thu, 4 Sep 2008, Carrasco-Torrecilla, Roman R wrote:> Dear all, > Sorry if this is too obvious. > I am trying to fit my multiple regression model using lm() > Before starting model simplification using step() I checked whether the > model presented heteroscedasticity with ncv.test() from the CAR package. > It presents it. > > I want to correct for it, I used hccm() from the CAR package as well and > got the Heteroscedasticity-Corrected Covariance Matrix. > > I am not sure what am I supposed to do with the matrix. I guess I should > run my model again telling it to use that matrix but I don't really find > the parameter in lm() to tell R so. I guess it should be somewhere in > weights?If you have a reasonable approximation of the pattern of heteroskedasticity, you can supply it in the "weights" argument to lm() and perform WLS. hccm() on the other hand does not assume a particular pattern of heteroskedasticity (with the obvious advantages and disadvantages). You can easily employ it for inference based on Wald statistics. The "car" package provides linear.hypothesis() for this and the package "lmtest" provides functions coeftest() and waldtest().> I would really appracite if you could show me how I would do it or > recommend a text on how to correct heteroscedasticity with R.The "sandwich" package which provides more flexible implementations of the estimators underlying hccm() as well as other estimators has vignette("sandwich", package = "sandwich") with some background information and hands-on examples. hth, Z
Apparently Analagous Threads
- function for linear regression with White std. errors
- Incorporating the results of White's HCCM into a linear regression:
- {nlme} Question about modeling Level two heteroscedasticity in HLM
- {nlme} Question about modeling Level two heteroscedasticity in HLM
- {nlme} Question about modeling Level two heteroscedasticity in HLM