Skip to contents

Reproduces sandwich::vcovHAC / sandwich::NeweyWest with the Bartlett kernel and a fixed lag. The meat accumulates the weighted lag-l autocovariances of the score contributions.

Usage

morie_vcov_hac(model, lag = NULL, prewhite = FALSE, adjust = TRUE)

Arguments

model

A fitted lm / glm.

lag

Number of lags (default the Newey-West rule \(\lfloor 4 (n/100)^{2/9} \rfloor\)).

prewhite

Currently ignored (kept for signature parity).

adjust

Apply the \(n/(n-k)\) finite-sample factor (default TRUE, matching sandwich::NeweyWest).

Value

The coefficient covariance matrix.

References

Newey, W. K., & West, K. D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelation consistent covariance matrix. Econometrica, 55(3), 703-708.

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_hac(fit, lag = 2L)
#>              (Intercept)            x
#> (Intercept)  0.011502902 -0.005215055
#> x           -0.005215055  0.013489118