Skip to content

ENH: Add the Andrews (1991) AR(1) plug-in bandwidth to the kernel estimators - #964

Open
bashtage wants to merge 1 commit into
mainfrom
a91-f887-andrews-bandwidth
Open

bashtage wants to merge 1 commit into
mainfrom
a91-f887-andrews-bandwidth

Conversation

@bashtage

Copy link
Copy Markdown
Owner

Target 9.1: merge after v9.0.0 is tagged. Closes #887.

Adds bandwidth_method="newey-west" | "andrews" to every kernel covariance estimator
(including the Andrews, Gallant, NeweyWest and ZeroLag aliases) and to
PreWhitenedRecolored, which passes it to its kernel.

  • The value is lower case and case-insensitive. It is exposed as a read-only
    bandwidth_method property.
  • "newey-west" is the default and is unchanged: the bandwidths and long-run sums are
    bit-identical to main on 12 kernels.
  • "andrews" implements Andrews (1991, Section 6, eqs. 6.3-6.4).
    • An AR(1) is fitted to each column: OLS with an intercept, and sigma^2 = RSS/(T-1),
      as R's ar(method="ols") does.
    • The bandwidth is c_k (alpha(q) T)^(1/(2q+1)). arch's existing kernel constants are
      already Andrews' constants (Bartlett 1.1447, Parzen 2.6614, QS 1.3221, Tukey-Hanning
      1.7462), and the derivation reproduces them.
    • Weights are respected. Constant and zero-weight columns are skipped.
    • Complex data are handled as separate real and imaginary columns.
    • An explicit bandwidth overrides the method. force_int and the nobs - 1 cap work
      as before.

Validation: R 4.6.1 with sandwich 3.1.3, bwAndrews(x, kernel=..., approx="AR(1)", weights=w, prewhite=FALSE).

  • 6 seeded datasets (univariate and multivariate, T = 50 to 500, nonzero means,
    non-uniform and zero weights) × 4 kernels × center.
  • Largest relative difference 2.2e-15. The tests use rtol 1e-10, with the R values stored
    as constants.
  • Also checked: one value by hand from the formulas, and all 12 kernels against an
    independent least-squares reference.

Tests:

  • arch/tests/covariance/test_andrews_bandwidth.py, 153 tests.
  • Validation rows and case-insensitivity checks for every estimator.
  • Fast suite 27,325 passed. The new tests pass in random orders and without matplotlib.
    numpydoc lint 0, and the docs build has no new warnings.

For review:

  • The TukeyParzen kernel_const is 1.8576, but the formula gives 1.8587 (0.06%). It is
    left unchanged, since changing it would alter the default bandwidth; the test tolerates
    the difference.
  • PhillipsPerron could use bandwidth_method="andrews" for its long-run variance. That
    belongs in a separate issue.

Thanks to @ZacKienzle2 for the proposal.

🤖 Generated with Claude Code

…imators

Add bandwidth_method to the kernel covariance estimators and to
PreWhitenedRecolored. The default, "newey-west", is the existing automatic
bandwidth and is unchanged. "andrews" selects the bandwidth using the AR(1)
plug-in estimate of alpha(q) in Section 6 of Andrews (1991), eqs. (6.3)-(6.4),
with the kernel constants and exponent q of each kernel. The AR(1) is fit to each
column by OLS with an intercept, as in sandwich::bwAndrews, which the tests match.

xref #887
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.31034% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.95%. Comparing base (d2c90b4) to head (60e97ab).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
arch/tests/covariance/test_andrews_bandwidth.py 99.14% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #964    +/-   ##
========================================
  Coverage   98.95%   98.95%            
========================================
  Files         136      137     +1     
  Lines       30043    30334   +291     
  Branches     2331     2345    +14     
========================================
+ Hits        29729    30018   +289     
- Misses        256      257     +1     
- Partials       58       59     +1     
Flag Coverage Δ
adder 98.90% <99.31%> (+<0.01%) ⬆️
subtractor 98.90% <99.31%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Andrews (1991) AR(1) plug-in bandwidth for the kernel covariance estimators

1 participant