Skip to content

BUG: Use the AutoReg and ARDL regressors in acorr_breusch_godfrey - #10400

Merged
bashtage merged 1 commit into
statsmodels:mainfrom
shan3520:bug-9090-bg-autoreg
Oct 5, 2026
Merged

bashtage merged 1 commit into
statsmodels:mainfrom
shan3520:bug-9090-bg-autoreg

Conversation

@shan3520

@shan3520 shan3520 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

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.

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

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
@bashtage
bashtage merged commit d5d3577 into statsmodels:main Oct 5, 2026
13 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.

Breusch-Godfrey test dimensions mismatch

3 participants