Skip to content

BUG: ARDLResults.apply/append loses exog lag order - #9915

Merged
bashtage merged 4 commits into
statsmodels:mainfrom
imann128:fix/ardl-results-apply-exog-lags
Aug 7, 2026
Merged

bashtage merged 4 commits into
statsmodels:mainfrom
imann128:fix/ardl-results-apply-exog-lags

Conversation

@imann128

@imann128 imann128 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9579

Summary:

ARDLResults didn't define its own apply() instead it inherited AutoRegResults.apply(), which always reconstructs the cloned model as a plain AutoReg(...), regardless of what self.model actually is. AutoReg has no concept of ARDL's order (the per-variable exog lag spec, e.g. {"lry": [0], "ibo": [0,1,2,3], "ide": [0,1,2,3]}), so the new model's design matrix ends up built from raw, unlagged exog only, with 7 columns instead of 13. The original 13-length fitted params get reused unchanged against that narrower matrix, and any predict()/forecast() call fails with matmul: ... size 13 is different from 7. I confirmed this by running the reporter's exact repro from #9579 and reproducing their exact error on both the released 0.14.6 and current main.

Changes:

**statsmodels/tsa/ardl/model.py**
Added an apply() override on ARDLResults that reconstructs the clone as ARDL(...) instead of AutoReg(...). It passes order=existing._order in the exact dict already stored on the fitted model, not the flattened ardl_order property, which loses the per-variable lag structure; along with hold_back, causal, fixed, seasonal, deterministic (re-anchored to the new data's index, same as the base class does for AutoReg), period, and trend. append() was deliberately left alone: AutoRegResults.append() already ends with return self.apply(...), and since that call is polymorphic on self, it now dispatches to the new override automatically once it exists. Smaller diff, no duplicated index-validation logic.

**statsmodels/tsa/ardl/tests/test_ardl.py**
Added test_apply_forecast_matches_ardl_order, which reproduces the reporter's scenario end-to-end (fit on a subset, apply() to a larger sample, forecast() and predict()) and asserts it no longer raises and returns the correctly shaped output. Added test_apply_design_matrix_matches_fresh_fit, which goes a step further than "doesn't crash": it checks that the applied model's exog lag columns are numerically identical to an independently constructed ARDL model fit directly on the new data under the same order, ruling out a design matrix that merely has the right shape but wrong values.

@imann128 imann128 changed the title BUG: ARDLResults.apply/append loses exog lag order ARDLResults.apply/append loses exog lag order Jul 16, 2026
@imann128

imann128 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

CI failure unrelated to this PR: nonparametric/tests/test_kernel_regression.py::TestKernelReg::test_significance_seed_legacy
(and test_significance_discrete on a different run) fail on the Linux x86-64 / python_312_latest job.
My PR doesn't touch this module because the diff here only affects statsmodels/tsa/ardl/model.py and its tests.
Flagging it in case it's a known issue.

Also seeing an unrelated docs-build failure:

Sphinx/IPython directive raises:
RuntimeError processing docs/source/contingency_tables.rst:195 on the python_314 job.

Not touched by this PR's diff (statsmodels/tsa/ardl/ only).

@bashtage

Copy link
Copy Markdown
Member

Don't worry about that test failure. It is a known random failure that needs a look at. It won't block.

Comment thread statsmodels/tsa/ardl/model.py Outdated
Keyword arguemnts to pass to `fit` (if `refit=True`)

Returns
------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dashed lines must match the length of the word above.

Comment thread statsmodels/tsa/ardl/model.py Outdated
Updated results object containing results for the new dataset.

Additional
-------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. Also Additional is not a recognized section. Could go under Notes.

Or perhaps this is a See Also

@bashtage

Copy link
Copy Markdown
Member

I haven't looked at code, just some small but necessary fixes for the docstring.

@Aniketsy Aniketsy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh @imann128 you have this commit a0ed283 from your previous pr #9845

  • you need to rebase and drop the commit to make this pr clean, please let me know if you need any help.

thanks :)

@imann128
imann128 force-pushed the fix/ardl-results-apply-exog-lags branch from a8f47bf to 388857e Compare July 17, 2026 03:51
@imann128

Copy link
Copy Markdown
Contributor Author

Sorry, guys. This PR got a bit messy.
I have done the rebase and fixed the documentation errors.

@Aniketsy

Copy link
Copy Markdown
Contributor

Sorry, guys. This PR got a bit messy.

no issues 😊 ... Now its clean

I have done the rebase and fixed the documentation errors.

great 👍

@bashtage bashtage changed the title ARDLResults.apply/append loses exog lag order BUG: ARDLResults.apply/append loses exog lag order Jul 20, 2026
@bashtage bashtage self-assigned this Jul 20, 2026
@bashtage bashtage added this to the 0.15 milestone Jul 23, 2026
@bashtage
bashtage merged commit d641120 into statsmodels:main Aug 7, 2026
10 checks passed
@bashtage

bashtage commented Aug 7, 2026

Copy link
Copy Markdown
Member

Thanks.

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.

Possible BUG with ARDLResults

3 participants