Skip to content

TST: Follow up #10713 (lag polynomial products in the ARIMA GLS whitening) - #10717

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-gls-whitening-followup
Nov 10, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-gls-whitening-followup

Conversation

@bashtage

Copy link
Copy Markdown
Member

Follow up to #10713 (ARIMA GLS whitening with the reduced AR and MA lag polynomials). Its review left the items below. The code does not change, so the new tests pass on main as well; they pin the behaviour that #10713 fixed.

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Changes

  • TST: The 12 cases of test_gls_whitening_lags each have a single factor, so the product of the non-seasonal and the seasonal polynomial, the reason for reduced_ar_poly and reduced_ma_poly, was not tested: replacing the products by the sum of the two polynomials (losing the cross terms, for example lag 5 of (1, 0, 0)x(1, 0, 0, 4)) passed all 22 tests of the file. The new test_gls_whitening_polynomial_products (15 cases, about 3 s) has:
    • products: (1,0,0)x(1,0,0,4), (0,0,1)x(0,0,1,4), (1,0,1)x(1,0,1,4) and ([2],0,0)x(1,0,0,3);
    • differencing, which the old cases did not have (the case where main was most wrong): D=1 with (0,0,0)x(0,1,1,4) and (1,0,0)x(0,1,1,4), and d=1 with (1,1,0)x(0,0,1,4);
    • all of these for both innovations_mle and statespace, and one case with arma_estimator="hannan_rissanen" and the sparse lags ([2], 0, [2]), which was affected as well (it was about 0.12 off the exact GLS before BUG: Preserve seasonal and sparse lags in ARIMA GLS whitening #10713).
    • The reference does not use the innovations algorithm. The test differences endog and exog itself (differencing is not part of the whitening polynomials), multiplies the lag polynomials built from the parameters that the estimator found with np.convolve, takes the autocovariances from arma_acovf, and solves the GLS normal equations with np.linalg.solve; the coefficients agree to rtol=atol=1e-8. The simulated data use np.random.default_rng(13579), nobs=80, two regressors, all ARMA coefficients nonzero.
  • DOC: The release note of BUG: Preserve seasonal and sparse lags in ARIMA GLS whitening #10713 now has :pr:10713``, no blank line after the bullet (the other bullets of the list have none) and says who is affected: statsmodels.tsa.arima.estimators.gls.gls and `ARIMA.fit` for a model with `exog` or a trend that is estimated with a `method` other than "statespace", or with `method="statespace"` and `gls=True`, and that the estimates of such models with seasonal terms or non-consecutive lags change. The entry points were checked by spying on `estimate_gls` while fitting `ARIMA(endog, exog, (1, 0, 0), trend="n")`: `innovations_mle`, `hannan_rissanen`, `yule_walker`, `burg` and `statespace` with `gls=True` call it; the default `statespace` does not; with no `exog`, `trend="c"` calls it and `trend="n"` does not.

Mutations of gls.py that the new test must catch (each applied to a copy of the source, and undone):

  • sum of the non-seasonal and seasonal polynomials instead of the product: 8 of the 15 new cases fail (all the product cases); the 12 old cases still pass, so only the new test catches it;
  • the compact arrays p_arma.ar_params, p_arma.ma_params again (the code before BUG: Preserve seasonal and sparse lags in ARIMA GLS whitening #10713): all 15 fail;
  • no minus sign on the AR, only the non-seasonal polynomials, only the seasonal polynomials, AR reduced but MA compact and the reverse: caught by the new and the old cases.

Not changed

  • An R reference value (arima(..., fixed=..., transform.pars=FALSE, method="ML") returns the same coefficients to 1e-8 for the fixed ARMA parameters) and a case with n_iter > 1, which the review mentioned as optional.
  • A sentence in the docstring of gls about the reduced polynomials: DOC: Follow up #10711 (constants and trends in the ARIMA GLS notes) #10716 changes the Notes of the same docstring.

Tests

  • test_gls.py: 37 passed (22 before) on Python 3.13 with NumPy 2.5.4 and SciPy 1.18.1, and on Python 3.10 with NumPy 1.23.5 and SciPy 1.8.1; the whole statsmodels/tsa/arima directory: 223 passed, 3 xfailed (Python 3.13). ruff check passes and git diff --check is clean. The documentation was not built with Sphinx.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Sonnet 5.5).
    Used for: reviewing BUG: Preserve seasonal and sparse lags in ARIMA GLS whitening #10713, and writing the tests and the release-note text.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

🤖 Generated with Claude Code

bashtage and others added 2 commits November 10, 2026 13:23
Follow up statsmodels#10713, which made gls use the reduced (product) AR and MA lag
polynomials when whitening. Its tests each had a single factor, so replacing
the product by the sum of the non-seasonal and seasonal polynomials (losing
the cross terms) was not detected, and nothing had differencing.

Add test_gls_whitening_polynomial_products: models with a non-seasonal and a
seasonal factor, a sparse non-seasonal lag with a seasonal AR, D=1 and d=1
models, for innovations_mle and statespace, and sparse lags with the
hannan_rissanen estimator. The reference does not use the innovations
algorithm: it differences endog and exog itself, multiplies the lag
polynomials built from the estimated parameters with np.convolve, takes the
autocovariances from arma_acovf and solves the GLS normal equations with
np.linalg.solve (agreement to 1e-8).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Follow up statsmodels#10713. Add the missing PR reference to the release note, drop
the blank line after the bullet and say which calls are affected:
statsmodels.tsa.arima.estimators.gls.gls and ARIMA.fit for a model with
exog or a trend when the method is not "statespace" or gls=True.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@bashtage
bashtage marked this pull request as ready for review November 10, 2026 13:34
@bashtage
bashtage merged commit e62d937 into statsmodels:main Nov 10, 2026
11 of 12 checks passed
@bashtage
bashtage deleted the wip-gls-whitening-followup branch November 20, 2026 10:57
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.

1 participant