Skip to content

Commit c5bcd93

Browse files
authored
Merge pull request statsmodels#5984 from bashtage/err-breusch
MAINT: Clarify breusch_pagan is for scalars
2 parents 94e2d24 + 6fb8fa1 commit c5bcd93

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

statsmodels/sandbox/stats/diagnostic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ def acorr_breusch_godfrey(results, nlags=None, store=False):
489489
490490
'''
491491

492-
x = np.asarray(results.resid)
492+
x = np.asarray(results.resid).squeeze()
493+
if x.ndim != 1:
494+
raise ValueError('Model resid must be a 1d array. Cannot be used on'
495+
' multivariate models.')
493496
exog_old = results.model.exog
494497
nobs = x.shape[0]
495498
if nlags is None:

statsmodels/stats/tests/test_diagnostic.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
"""
1212
import os
13+
import json
1314

1415
import numpy as np
1516
import pandas as pd
@@ -21,11 +22,9 @@
2122
from statsmodels.regression.linear_model import OLS
2223
from statsmodels.tools.tools import add_constant
2324
from statsmodels.datasets import macrodata
24-
2525
import statsmodels.stats.sandwich_covariance as sw
2626
import statsmodels.stats.diagnostic as smsdia
27-
import json
28-
27+
from statsmodels.tools.tools import Bunch
2928
import statsmodels.stats.outliers_influence as oi
3029

3130
cur_dir = os.path.abspath(os.path.dirname(__file__))
@@ -305,6 +304,11 @@ def test_acorr_breusch_godfrey(self):
305304
bg3 = smsdia.acorr_breusch_godfrey(res, nlags=14)
306305
assert_almost_equal(bg2, bg3, decimal=13)
307306

307+
def test_acorr_breusch_godfrey_multidim(self):
308+
res = Bunch(resid=np.empty((100,2)))
309+
with pytest.raises(ValueError, match='Model resid must be a 1d array'):
310+
smsdia.acorr_breusch_godfrey(res)
311+
308312
def test_acorr_ljung_box(self):
309313

310314
#unit-test which may be useful later

0 commit comments

Comments
 (0)