Skip to content

Commit

Permalink
BUG: ARIMA fit with trend and constant exog
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jun 6, 2019
1 parent 701a6ae commit d6955db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion statsmodels/tsa/arima_model.py
Expand Up @@ -404,7 +404,7 @@ def _make_arma_exog(endog, exog, trend):
if exog is None and trend == 'c': # constant only
exog = np.ones((len(endog), 1))
elif exog is not None and trend == 'c': # constant plus exogenous
exog = add_trend(exog, trend='c', prepend=True)
exog = add_trend(exog, trend='c', prepend=True, has_constant='raise')
elif exog is not None and trend == 'nc':
# make sure it's not holding constant from last run
if exog.var() == 0:
Expand Down
17 changes: 17 additions & 0 deletions statsmodels/tsa/tests/test_arima.py
Expand Up @@ -2465,3 +2465,20 @@ def test_arima_no_full_output():
mod = ARIMA(endog, (1, 0, 1))
res = mod.fit(trend="c", disp=-1, full_output=False)
assert res.mle_retvals is None


def test_constant_column_trend():
# GH#3343 analogous to GH#5258 for AR, when the user passes a constant exog
# and also passes trend="c", raise instead _make_arma_exog used to
# silently drop a column and return an inconsistenct k_trend value.

exog = np.array([0.5, 0.5, 0.5, 0.5, 0.5])
endog = np.array([-0.011866, 0.003380, 0.015357, 0.004451, -0.020889])

model = ARIMA(endog=endog, order=(1, 1, 0), exog=exog)

# Fitting with a constant and constant exog raises because of colinearity
with pytest.raises(ValueError, match="already contains"):
model.fit(trend="c")

# FIXME: calling model.fit(trend="nc") raises for orthogonal reasons

0 comments on commit d6955db

Please sign in to comment.