Skip to content

heteroskedasticity-robust standard errors

4 messages · Grant Farnsworth, Ott Toomet, David Barron +1 more

#
I am trying to compute the white heteroskedasticity-robust standard errors
(also called the Huber standard errors) in a linear model, but I can't seem
to find a function to do it.  I know that the design library in S+ has
something like this (robcov?), but I have not yet seen this library ported
to R.

Anyone know if there is already a function built into R to do this
relatively simple job?

Thanks,
Grant

------------------------------------------------------
Grant Verdell Farnsworth
gvf at email.byu.edu
http://thegrantman.freewebsites.com
------------------------------------------------------


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi,

I attach a version of small program for White stderrors.  Basically, it
calculates a new covariance matrix and prints the results with new stderrors
(without any tests and additional information).  It should be rewritten to
use the object-oriented architecture, but I have not had need so long.

you should call it as:
summaryw(lm(y~x))

Regards,
Ott Toomet

P.S.  If you get/write a better version, let me know.

--------------------------------------------------------------------
### ols with White' heteroscedasticity consistent stderrors
summaryw <- function( model) {
  s <- summary( model)
  X <- model.matrix( model)
  u2 <- residuals( model)^2
  XDX <- 0
  ## here one needs essentially to calculate X'DX.  But due to the fact that D
  ## is huge (NxN), it is better to do it with a cycle.
  for( i in 1:nrow( X)) {
    XDX <- XDX + u2[i]*X[i,]%*%t( X[i,])
  }
  XX1 <- solve( t( X)%*%X)
  varcovar <- XX1 %*% XDX %*% XX1
  stdh <- sqrt( diag( varcovar))
  t <- model$coefficients/stdh
  p <- 2*pnorm( -abs( t))
  results <- cbind( model$coefficients, stdh, t, p)
  dimnames(results) <- dimnames( s$coefficients)
  results
}
On Thu, 21 Mar 2002, Grant Farnsworth wrote:
|I am trying to compute the white heteroskedasticity-robust standard errors
  |(also called the Huber standard errors) in a linear model, but I can't seem
  |to find a function to do it.  I know that the design library in S+ has
  |something like this (robcov?), but I have not yet seen this library ported
  |to R.
  |
  |Anyone know if there is already a function built into R to do this
  |relatively simple job?
  |
  |Thanks,
  |Grant

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Try the function hccm in the car package.

David

----- Original Message -----
From: "Grant Farnsworth" <gvf at email.byu.edu>
To: "rhelp" <r-help at stat.math.ethz.ch>
Sent: Friday, March 22, 2002 2:09 AM
Subject: [R] heteroskedasticity-robust standard errors
seem
-.-.-
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Grant Farnsworth wrote:
There are some version of heteroskedasticity consistent covariance
matrices in the "car" package in hccm() and in "strucchange" in covHC().
In particular both contain the White (1980) estimator as type "hc0" and
"HC" respectively.
Z
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._