Repository navigation
BUG: Count coefs_exog columns in VARProcess - #10446
Merged
Merged
Conversation
coefs_exog has shape (neqs, k_exog) but VARProcess used shape[0] to set k_trend, so a standalone process with only an intercept looked like it had a higher order trend and simulate_var failed on endog_lagged. Raise a clear error when simulating a standalone process that needs exog or trend data without an offset. closes statsmodels#8926
bashtage
force-pushed
the
bug-8926-varprocess-simulate
branch
from
October 5, 2026 15:19
73c5779 to
3769d4a
Compare
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling simulate_var() on a standalone VARProcess instance with coefs, coefs_exog, and sigma_u raises an AttributeError for the lack of endog_lagged attribute, even if the model contains only an intercept with a 2-dimensional coefs_exog.
This is because the VARProcess.init method incorrectly computes the number of trends and exogenous regressors using coefs_exog.shape[0] (number of equations) instead of the number of terms, leading simulate_var to believe there is a time trend that needs the endog_lagged array available only in the VARResults instance.
Fix involves switching coefs_exog.shape[0] to coefs_exog.shape[1].
Since it is not possible to run a simulation of a standalone process with a real time trend or exogenous regressors without any data, now a proper ValueError is raised requiring an offset, instead of failing with a mysterious AttributeError.
Also added the shape of coefs_exog to the parameters documentation of its parameter.
No change was necessary for the VARResults since it explicitly passes k_trend parameter, and for SVAR, since it has its own init method.
Added test cases that check if running the standalone simulation with constant trend ("c") generates exactly the same output as the VARResults simulation, and if "ct" trend raises the expected ValueError requiring an offset while generating the same simulation as the VARResults with the offset passed from the fitted model. Both test cases previously failed on main.
No external R reference is provided for these tests, since they merely test if two different code paths give identical results, hence there are no new numerical results to compare.
This PR fixes #8926.
NumPy's guide.
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.
Tool(s):
Claude Code (Claude Opus 5.5).Used for:
drafting the fix and tests.I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.