Skip to contents

Heteroskedasticity- and autocorrelation-consistent covariance with Bartlett weights 1 - l/(L+1), which guarantee a positive semi-definite estimate. lags defaults to floor(4 (n/100)^(2/9)), Newey and West's own rule; note sandwich::NeweyWest instead selects the bandwidth automatically, so pass R an explicit lag to compare.

Usage

morie_newey_west_vcov(fit, lags = NULL)

Arguments

fit

a morie_ols fit

lags

Bartlett bandwidth

Value

list with vcov, se and the lags used

Examples

if (requireNamespace("lmtest", quietly = TRUE) && requireNamespace("sandwich", quietly = TRUE)) {
  N <- 40
  X1 <- sapply(0:(N - 1), function(i) ((i * 7)%%13) + 0.5 * ((i *
      3)%%5))
  X2 <- sapply(0:(N - 1), function(i) ((i * 5)%%11) - 0.25 * ((i *
      2)%%7))
  E <- sapply(0:(N - 1), function(i) ((i * 13)%%17)/17 - 0.5)
  Y <- 3 + 1.5 * X1 - 0.8 * X2 + E * (1 + 0.05 * X1)
  X <- cbind(X1, X2)
  FIT <- morie_ols(Y, X)
  morie_newey_west_vcov(FIT, lags = 3)
}
#> $vcov
#>              (Intercept)            X1            X2
#> (Intercept)  0.036250086 -0.0028244502 -0.0033132344
#> X1          -0.002824450  0.0002814684  0.0001709776
#> X2          -0.003313234  0.0001709776  0.0004613485
#> 
#> $se
#> (Intercept)          X1          X2 
#>  0.19039455  0.01677702  0.02147902 
#> 
#> $lags
#> [1] 3
#>