Skip to contents

Reproduces sandwich::vcovCL for one-way clustering: the meat sums the outer products of cluster-summed score contributions, with the CR1 small-sample factor \(\frac{G}{G-1}\cdot\frac{n-1}{n-k}\) by default.

Usage

morie_vcov_cl(model, cluster, type = "HC1")

Arguments

model

A fitted lm / glm.

cluster

A grouping vector (length n).

type

"HC1" (CR1, default) or "HC0" (CR0).

Value

The coefficient covariance matrix.

References

Cameron, A. C., & Miller, D. L. (2015). A practitioner's guide to cluster-robust inference. Journal of Human Resources, 50(2), 317-372.

Examples

set.seed(1)
df <- data.frame(y = rnorm(60), x = rnorm(60),
                 cl = rep(1:6, each = 10))
fit <- stats::lm(y ~ x, data = df)
morie_vcov_cl(fit, cluster = df$cl)
#>              (Intercept)            x
#> (Intercept)  0.003606061 -0.005381011
#> x           -0.005381011  0.018076041