vcovHC {sandwich} | R Documentation |
Heteroskedasticity-consistent estimation of the covariance matrix of the coefficient estimates in a linear regression model.
vcovHC(x, order.by = NULL, data = list(), type = c("HC3", "const", "HC", "HC0", "HC1", "HC2", "HC4"), omega = NULL)
x |
a fitted model object of class "lm" . |
order.by |
formula. A formula with a single explanatory
variable like ~ x . The observations in the model
are ordered by the size of x . If set to NULL (the
default) the observations are assumed to be ordered (e.g. a
time series). |
data |
an optional data frame containing the variables in the order.by
model. By default the variables are taken from the environment which
vcovHC is called from. |
type |
a character string specifying the estimation type. For details see below. |
omega |
a function depending on the arguments residuals
(the residuals of the linear model), diaghat (the diagonal
of the corresponding hat matrix) and df (the residual degrees of
freedom). For details see below. |
When type = "const"
constant variances are assumed and
and covHC
gives the usual estimate of the covariance matrix of
the coefficient estimates:
sigma^2 (X'X)^{-1}
All other methods do not assume constant variances and are suitable in case of
heteroskedasticity. "HC"
(or equivalently "HC0"
) gives White's
estimator, the other estimators are refinements of this. They are all of form
(X'X)^{-1} X' Omega X (X'X)^{-1}
and differ in the choice of Omega. This is in all cases a diagonal matrix whose elements are function of the residuals, the diagonal elements of the hat matrix and the residual degrees of freedom. For White's estimator
omega <- function(residuals, diaghat, df) residuals^2
Instead of specifying a type
the argument omega
can also be specified
directly. For details see the references.
A matrix containing the covariance matrix estimate.
Cribari-Neto F. (2004), Asymptotic inference under heteroskedasticity of unknown form. Computational Statistics & Data Analysis 45, 215-233.
MacKinnon J. G., White H. (1985), Some heteroskedasticity-consistent covariance matrix estimators with improved finite sample properties. Journal of Econometrics 29, 305-325.
White H. (1980), A heteroskedasticity-consistent covariance matrix and a direct test for heteroskedasticity. Econometrica 48, 817-838.
## generate linear regression relationship ## with homoskedastic variances x <- sin(1:100) y <- 1 + x + rnorm(100) ## compute usual covariance matrix of coefficient estimates fm <- lm(y ~ x) vcovHC(fm, type="const") vcov(fm) sigma2 <- sum(residuals(lm(y~x))^2)/98 sigma2 * solve(crossprod(cbind(1,x)))