hccme: Heteroskedasticity-Consistent Covariance Matrix Estimators...

View source: R/hccme.R

hccmeR Documentation

Heteroskedasticity-Consistent Covariance Matrix Estimators for Linear Regression Models

Description

Computes an estimate of the n\times n covariance matrix Ω (assumed to be diagonal) of the random error vector of a linear regression model, using a specified method

Usage

hccme(
  mainlm,
  hcnum = c("3", "0", "1", "2", "4", "5", "6", "7", "4m", "5m", "const"),
  sandwich = FALSE,
  as_matrix = TRUE
)

Arguments

mainlm

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".

hcnum

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 \insertCiteMacKinnon85skedastic

  • "0", corresponding to HC0 \insertCiteWhite80skedastic

  • "1", corresponding to HC1 \insertCiteMacKinnon85skedastic

  • "2", corresponding to HC1 \insertCiteMacKinnon85skedastic

  • "4", corresponding to HC4 \insertCiteCribari04skedastic

  • "5", corresponding to HC5 \insertCiteCribari07skedastic

  • "6", corresponding to HC6 \insertCiteAftab16skedastic

  • "7", corresponding to HC7 \insertCiteAftab18skedastic

  • "4m", corresponding to HC4m \insertCiteCribari11skedastic

  • "5m", corresponding to HC5m \insertCiteLi17skedastic

  • "const", corresponding to the homoskedastic estimator, (n-p)^{-1}\displaystyle∑_{i=1}^{n}e_i^2

sandwich

A logical, defaulting to FALSE, indicating whether or not the sandwich estimator

\mathrm{Cov}{\hat{β}}=(X'X)^{-1}X'\hat{Ω}X(X'X)^{-1}

should be returned instead of \mathrm{Cov}(ε)=\hat{Ω}

as_matrix

A logical, defaulting to TRUE, indicating whether a covariance matrix estimate should be returned rather than a vector of variance estimates

Value

A numeric matrix (if as_matrix is TRUE) or else a numeric vector

References

\insertAllCited

See Also

vcovHC

Examples

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)


skedastic documentation built on Nov. 10, 2022, 5:43 p.m.