Repository navigation
BUG: ARDLResults.apply/append loses exog lag order - #9915
Conversation
|
CI failure unrelated to this PR: Also seeing an unrelated docs-build failure: Sphinx/IPython directive raises: Not touched by this PR's diff (statsmodels/tsa/ardl/ only). |
|
Don't worry about that test failure. It is a known random failure that needs a look at. It won't block. |
| Keyword arguemnts to pass to `fit` (if `refit=True`) | ||
|
|
||
| Returns | ||
| ------------------ |
There was a problem hiding this comment.
Dashed lines must match the length of the word above.
| Updated results object containing results for the new dataset. | ||
|
|
||
| Additional | ||
| ------------------- |
There was a problem hiding this comment.
Same. Also Additional is not a recognized section. Could go under Notes.
Or perhaps this is a See Also
|
I haven't looked at code, just some small but necessary fixes for the docstring. |
a8f47bf to
388857e
Compare
|
Sorry, guys. This PR got a bit messy. |
no issues 😊 ... Now its clean
great 👍 |
|
Thanks. |
Closes #9579
Summary:
ARDLResultsdidn't define its ownapply()instead it inheritedAutoRegResults.apply(), which always reconstructs the cloned model as a plainAutoReg(...), regardless of whatself.modelactually is.AutoReghas no concept of ARDL'sorder(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 fittedparamsget reused unchanged against that narrower matrix, and anypredict()/forecast()call fails withmatmul: ... 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 currentmain.Changes:
**statsmodels/tsa/ardl/model.py**Added an
apply()override onARDLResultsthat reconstructs the clone asARDL(...)instead ofAutoReg(...). It passesorder=existing._orderin the exact dict already stored on the fitted model, not the flattenedardl_orderproperty, which loses the per-variable lag structure; along withhold_back,causal,fixed,seasonal,deterministic(re-anchored to the new data's index, same as the base class does forAutoReg),period, andtrend.append()was deliberately left alone:AutoRegResults.append()already ends withreturn self.apply(...), and since that call is polymorphic onself, 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()andpredict()) and asserts it no longer raises and returns the correctly shaped output. Addedtest_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 constructedARDLmodel fit directly on the new data under the same order, ruling out a design matrix that merely has the right shape but wrong values.