long_run_variance#
- cultivars.diagnostics.unit_roots.long_run_variance(endog, *, kernel='bartlett', bandwidth=None)[source]#
Kernel estimate of a series’ long-run variance about its mean.
The long-run variance \(\lambda^2 = \sum_{j = -\infty}^{\infty} \gamma_j = 2\pi f(0)\) is the variance of the normalized partial sum in the limit, and the quantity every kernel-corrected test in this module divides by. The estimator is
\[\hat\lambda^2 = \hat\gamma_0 + 2 \sum_{j = 1}^{T - 1} k\!\left(\frac{j}{b}\right) \hat\gamma_j,\]with \(k\) the Bartlett or quadratic-spectral kernel and \(b\) the bandwidth. The Bartlett kernel is the Newey-West estimator, always positive and with bandwidth \(\lfloor 4 (T / 100)^{2/9} \rfloor\) by default; the quadratic spectral kernel is Andrews’ (1991) optimal choice among positive definite kernels, with his AR(1) plug-in bandwidth by default, and converges faster at the cost of weight on distant lags.
- Parameters:
- Return type:
- Returns:
The estimate, a positive float.
- Raises:
SpecificationError – If the kernel or bandwidth is unusable.
DimensionError – If the series is not one-dimensional.
NumericalError – If the series is not finite.
See also
kpss()andphillips_perron()– the tests that divide by this estimate.canova_hansen()– its multivariate form for the seasonal scores.
References
Newey, W. K., & West, K. D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelation consistent covariance matrix. Econometrica, 55(3), 703-708.
Andrews, D. W. K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59(3), 817-858.
Example
White noise has long-run variance one; an AR(1) with root 0.9 has \(1 / (1 - 0.9)^2 = 100\), which the kernel estimate approaches from below because its bandwidth is short relative to the persistence:
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> e = rng.standard_normal(2000) >>> bool(0.8 < long_run_variance(e) < 1.2) True >>> y = np.zeros(2000) >>> for t in range(1, 2000): ... y[t] = 0.9 * y[t - 1] + rng.standard_normal() >>> bool(long_run_variance(y) < long_run_variance(y, bandwidth=50) < 100) True