[R] function for linear regression with White std. errors

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Fri Apr 28 14:25:33 CEST 2006


Brian:

> Thanks for the suggestion, but tomorrow I am teaching a little seminar
> for my department trying to convince people about how wonderful R is.
> These people are all Stata users, and they really like the idea that
> they only have to type ", robust" to get het. consistent std. errors.

With the package lmtest, you can do
  fm <- lm(...)
  coeftest(fm, vcov = hccm)
which does not seem to be too hard. Also look at the sandwich package
which provides a flexible framework and large collection of HC and HAC
estimators (more so than Stata afaik).

Also see
  Achim Zeileis (2004). Econometric Computing with HC and HAC
  Covariance Matrix Estimators. Journal of Statistical Software 11(10),
  1-17. URL http://www.jstatsoft.org/v11/i10/
for more examples.

Best wishes,
Z

> My pitch to a lot of them has been that R is a great and flexible tool
> which one doesn't have to be a programming whiz to use.  If they have
> to start writing functions to do something as basic as this, then my
> colleagues will probably stay in Stata-land.  I'm trying to prevent
> that!
> 
> Regards,
> 
> Brian
> 
> 2006/4/27, John Fox <jfox at mcmaster.ca>:
> > Dear Brian,
> >
> > How about sqrt(diag(hccm(mod)))? If that's too onerous, then you
> > could define a function to do it, e.g.,
> >
> >  wse <- function(mod) sqrt(diag(hccm(mod)))
> >
> > and then enter wse(mod). If you want a more complete, table-like
> > summary of the model using White standard errors, then you could
> > easily write a function to provide that.
> >
> > Regards,
> >  John
> >
> > --------------------------------
> > John Fox
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario
> > Canada L8S 4M4
> > 905-525-9140x23604
> > http://socserv.mcmaster.ca/jfox
> > --------------------------------
> >
> > > -----Original Message-----
> > > From: r-help-bounces at stat.math.ethz.ch
> > > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Brian
> > > Quinif Sent: Thursday, April 27, 2006 7:34 PM
> > > To: r-help at stat.math.ethz.ch
> > > Subject: [R] function for linear regression with White std. errors
> > >
> > > I would like to know if there is a function that will run a
> > > linear regression and report the White (heteroscedasticity
> > > consistent) std.
> > > errors.
> > >
> > > I've found the hccm() function in the car library, but that
> > > just gives me the White covariance matrix.  I'd like to be
> > > able to see the White std. errors without having to do much
> > > more work, if possible.
> > >
> > > Thanks,
> > >
> > > Brian
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide!
> > > http://www.R-project.org/posting-guide.html
> >
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list