Skip to contents

Native robust variance via morie_vcov_robust (no external dependency). Returns the requested variance-covariance matrix and the corresponding robust standard errors. Supports HC0-HC5 (cross-section), HAC (time-series), and clustered (one-way) variance, each cross-validated against sandwich to machine precision.

Usage

morie_causal_robust_se(model, type = "HC3", cluster = NULL, ...)

Arguments

model

A fitted stats::lm or stats::glm.

type

One of "HC0", "HC1", "HC2", "HC3", "HC4", "HC4m", "HC5", "HAC", or "CL" (clustered). Default "HC3" (Long-Ervin small-sample default).

cluster

Optional one-sided formula or vector identifying the cluster variable (required when type = "CL").

...

Additional arguments forwarded to the chosen sandwich estimator.

Value

Named list with elements vcov (variance matrix), se (named numeric vector of robust SEs), type, and n_coef.

References

Zeileis A, Koll S, Graham N (2020). Various Versatile Variances: An Object-Oriented Implementation of Clustered Covariances in R. Journal of Statistical Software, 95(1), 1-36.

Examples

set.seed(1)
df <- data.frame(y = rnorm(60), x = rnorm(60))
fit <- stats::lm(y ~ x, data = df)
str(morie_causal_robust_se(fit), max.level = 1)
#> List of 4
#>  $ vcov  : num [1:2, 1:2] 0.01441 -0.00786 -0.00786 0.01885
#>   ..- attr(*, "dimnames")=List of 2
#>  $ se    : Named num [1:2] 0.12 0.137
#>   ..- attr(*, "names")= chr [1:2] "(Intercept)" "x"
#>  $ type  : chr "HC3"
#>  $ n_coef: int 2