Skip to content

DOC: Follow up #10711 (constants and trends in the ARIMA GLS notes) - #10716

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

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

Conversation

@bashtage

Copy link
Copy Markdown
Member

Follow up to #10711 (documentation of the deterministic terms of the ARIMA GLS estimator, #6159). Its review left the items below; none of them changes the code, and #6159 stays open for its other items.

  • tests added / passed. (Docstring and release note only; see below for what was run.)
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Changes

  • DOC: The Notes of gls said that a linear trend in exog "becomes a constant after first differencing and can represent drift", which is true but silent about when it is not. Each case was run on simulated data (an I(1) series with drift 0.5 and AR(1) errors on the differences, n=200, np.random.default_rng(12345)):
    • With one difference the coefficient is the drift per unit of the column: exog=t with order=(1, 1, 0) gives 0.5126 and exog=t/n gives 102.52 (n times as large). With only seasonal differencing (order=(1, 0, 0), seasonal_order=(0, 1, 0, 4), a seasonal random walk with slope 0.5) exog=t gives 0.482, and exog=t/n gives 96.46.
    • After a second difference (order=(1, 2, 0), or order=(1, 1, 0) with seasonal_order=(0, 1, 0, 4)) the column is zero: gls returns exog_params equal to [0.] with two SingularMatrixWarning, and no error.
    • The text now says: a trend becomes a constant after one difference (regular or seasonal), its coefficient is then the drift per unit of the column, and after a second difference the column is zero and cannot be estimated.
  • DOC: A constant column that the user puts in exog is eliminated by differencing like the include_constant column, but it is not rejected: gls(y, exog=np.ones(n), order=(1, 1, 0)) returns [0.] and exog=np.c_[np.ones(n), t] returns [0., 0.5126], both with SingularMatrixWarning; only include_constant=True raises "Cannot include a constant in an integrated model". One sentence says so.
  • DOC: The exog description said "If not included, then include_constant must be True", which cannot be satisfied for an integrated model: gls(y, order=(1, 1, 0)) raises ValueError: diff requires input that is at least one dimensional for include_constant None and False, and the "Cannot include a constant" ValueError for True. It now says that the model must not include integration when exog is omitted.
  • DOC: The "why" of the item in ENH: Improvements to new ARIMA-type estimators #6159: the regression absorbs every deterministic term, so the ARMA estimator receives the regression residuals and must not demean them again. In the code, include_constant is applied to exog before the regression, every ARMA estimator is called with demean=False and the state space estimator with include_constant=False.
  • DOC: Release note: added :pr:10711``, moved the bullet to the end of "Documentation" (the section is appended in order of merging) and removed the blank line after it, and added "Numerical behavior is unchanged." like the neighbouring bullet.

Not changed

  • An integrated model without exog has no valid call to gls (the errors above; with only seasonal differencing it is an IndexError: too many indices for array; include_constant=False without exog fails for a non-integrated model too, with a ValueError about the dimensions in a concatenation). The messages are not helpful. This is a code defect, not a documentation one, and is not changed here.
  • gls is not in the Sphinx API documentation, so the changes are visible through help() and the source only.

Tests

  • The code is unchanged: the AST of gls.py with the docstrings removed is identical to main. Rendered with numpydoc 1.10.0 and docutils 0.22.4, the docstring gives the same messages as on main (the three about the arma_estimator bullet list that are already there, and the "Unknown directive" artifact of rendering without Sphinx). ruff check and git diff --check pass; test_gls.py passes (22). 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 DOC: Clarify deterministic terms in ARIMA GLS estimation #10711, and writing and checking the docstring and release-note changes.
    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:17
…d models

Follow up statsmodels#10711, which addressed statsmodels#6159. Checked by running gls on
simulated AR(1) data with drift:

- exog description: an integrated model without exog fails for every
  value of include_constant, so say the model must not include
  integration when exog is omitted.
- A constant column in exog is removed by differencing like the
  include_constant column and makes the regression singular, but is not
  rejected.
- A trend in exog becomes a constant after one (regular or seasonal)
  difference and its coefficient is the drift per unit of the column;
  after a second difference the column is zero and cannot be estimated.
- State why the ARMA step does not demean: the regression absorbs all
  deterministic terms and the estimators receive its residuals.

Docstring only; the code is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Follow up statsmodels#10711, which addressed statsmodels#6159. Add the PR role, move the
bullet to the end of the Documentation section (entries are appended in
merge order), drop the blank line after it and state that numerical
behavior is unchanged, like the neighbouring bullets.

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