Computes an estimate of the \(n\times n\) covariance matrix \(\Omega\) (assumed to be diagonal) of the random error vector of a linear regression model, using a specified method
hccme(
mainlm,
hcnum = c("3", "0", "1", "2", "4", "5", "6", "7", "4m", "5m", "const"),
sandwich = FALSE,
as_matrix = TRUE
)
A numeric matrix (if as_matrix
is TRUE
) or else a
numeric vector
Either an object of class
"lm"
(e.g., generated by lm
), or
a list of two objects: a response vector and a design matrix. The objects
are assumed to be in that order, unless they are given the names
"X"
and "y"
to distinguish them. The design matrix passed
in a list must begin with a column of ones if an intercept is to be
included in the linear model. The design matrix passed in a list should
not contain factors, as all columns are treated 'as is'. For tests that
use ordinary least squares residuals, one can also pass a vector of
residuals in the list, which should either be the third object or be
named "e"
.
A character corresponding to a subscript in the name of an HCCME according to the usual nomenclature \(\mathrm{HC\#}\). Possible values are:
"3", the default, corresponding to HC3 MacKinnon85skedastic
"0", corresponding to HC0 White80skedastic
"1", corresponding to HC1 MacKinnon85skedastic
"2", corresponding to HC1 MacKinnon85skedastic
"4", corresponding to HC4 Cribari04skedastic
"5", corresponding to HC5 Cribari07skedastic
"6", corresponding to HC6 Aftab16skedastic
"7", corresponding to HC7 Aftab18skedastic
"4m", corresponding to HC4m Cribari11skedastic
"5m", corresponding to HC5m Li17skedastic
"const", corresponding to the homoskedastic estimator, \((n-p)^{-1}\displaystyle\sum_{i=1}^{n}e_i^2\)
A logical, defaulting to FALSE
, indicating
whether or not the sandwich estimator
$$\mathrm{Cov}{\hat{\beta}}=(X'X)^{-1}X'\hat{\Omega}X(X'X)^{-1}$$
should be returned instead of \(\mathrm{Cov}(\epsilon)=\hat{\Omega}\)
A logical, defaulting to TRUE
, indicating whether
a covariance matrix estimate should be returned rather
than a vector of variance estimates
vcovHC
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
Omega_hat <- hccme(mtcars_lm, hcnum = "4")
Cov_beta_hat <- hccme(mtcars_lm, hcnum = "4", sandwich = TRUE)
Run the code above in your browser using DataLab