Skip to content

BUG: Count coefs_exog columns in VARProcess - #10446

Merged
bashtage merged 1 commit into
statsmodels:mainfrom
shan3520:bug-8926-varprocess-simulate
Oct 5, 2026
Merged

bashtage merged 1 commit into
statsmodels:mainfrom
shan3520:bug-8926-varprocess-simulate

Conversation

@shan3520

@shan3520 shan3520 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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.

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 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.

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
bashtage force-pushed the bug-8926-varprocess-simulate branch from 73c5779 to 3769d4a Compare October 5, 2026 15:19
@bashtage
bashtage merged commit 2cdcdf1 into statsmodels:main Oct 5, 2026
10 of 11 checks passed
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.

VARProcess.simulate_var Crashes Due to Missing Variable Definition

2 participants