estimate_long_run_covariance: Long-Run Covariance Estimator via Bartlett Kernel (HAC)

View source: R/statistical_tests.R

estimate_long_run_covarianceR Documentation

Long-Run Covariance Estimator via Bartlett Kernel (HAC)

Description

Estimates the long-run covariance matrix using the Newey-West (1987) approach with a Bartlett kernel. Provides Heteroskedasticity and Autocorrelation Consistent (HAC) variance estimates used for studentizing Reality Check test statistics.

Usage

estimate_long_run_covariance(loss_differences, block_length)

Arguments

loss_differences

A numeric matrix (P x K) of loss differences (benchmark loss minus forecast loss), where P is the number of forecast periods and K is the number of competing forecasts.

block_length

integer. The truncation lag l for the Bartlett kernel, numerically set equal to the MBB block length used elsewhere in this package for consistency. In HAC estimation this controls how many autocovariance lags are included; in MBB it controls block size – both capture the same dependence horizon. A commonly used rule of thumb is l \approx T^{1/3} (Politis & Romano, 1994). For P = 165 this gives approximately 5–6.

Details

Implements the Newey-West (1987) HAC covariance matrix estimator with Bartlett kernel weights w_j = 1 - j / (l + 1) for lags j = 1, \ldots, l, where l denotes the truncation lag (following the notation of Newey & West, 1987, and Politis & Romano, 1994), here set equal to block_length. This is essential for accounting for serial dependence in time-series forecast evaluations.

Value

A symmetric positive semi-definite matrix of dimensions K x K representing the estimated long-run covariance.

References

Newey, W. K., & West, K. D. (1987). A Simple Positive Semi-Definite Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica, 55(3), 703–708. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/1913610")}

Politis, D. N., & Romano, J. P. (1994). The stationary bootstrap. Journal of the American Statistical Association, 89(428), 1303–1313. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.1994.10476870")}

Examples

data(metals)
# metals: 165 x 15; columns 1-14 are competing forecasts, column 15 is the benchmark
# A small offset (+0.5) is added to the lagged benchmark to avoid degenerate zero
# loss differences when forecasts equal the realized value exactly (illustration only).
P <- nrow(metals)
K_total <- ncol(metals)
K <- K_total - 1 # 14 competing forecasts
realized <- c(metals[-1, K_total], metals[P, K_total]) + 0.5
benchmark_loss <- (metals[, K_total] - realized)^2
model_loss     <- (metals[, 1:K] - realized)^2
loss_diff      <- benchmark_loss - model_loss
lrc_result <- estimate_long_run_covariance(loss_diff, block_length = 5)
print(round(lrc_result[1:3, 1:3], 6))

RCtest documentation built on June 2, 2026, 9:07 a.m.