Repository navigation
BUG: Use the AutoReg and ARDL regressors in acorr_breusch_godfrey - #10400
Merged
Merged
Conversation
acorr_breusch_godfrey used model.exog as the regressors of the auxiliary regression. For AutoReg and ARDL, model.exog only holds the user exog over the full sample, so the test failed with a shape mismatch when exog was given, and otherwise left out the lagged endogenous variables and the deterministic terms. Results also do not have k_constant, so the test raised AttributeError for these models. Use the design matrix used in estimation and the model's k_constant for AutoReg and ARDL. Reference values are from lmtest::bgtest in R. closes statsmodels#9090
| "Model resid must be a 1d array. Cannot be used on multivariate models." | ||
| ) | ||
| exog_old = res.model.exog | ||
| from statsmodels.tsa.ar_model import AutoReg |
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.
Until now, attempting a Breusch-Godfrey test on AutoReg and ARDL models would result in immediate error due to k_constant AttributeError or crashes due to mismatch in lengths of series when exogenous variables are present. In addition, even if those crashes did not occur, the auxiliary regression had the incorrect set of regressors since it was based on model.exog, which excluded the constant, trend, and lags. This fix addresses the issues by using the complete design matrix (model._x) and the right set of constant attributes for AutoReg and ARDL models, while other models remain the same. It has been tested against R's lmtest::bgtest in four different scenarios; the no-constant scenario is tested against statsmodels' OLS alone due to differences in R and statsmodels' implementations.
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.