Last answered:

15 Apr 2020

Posted on:

13 Apr 2020

0

Error in Fitting Higher Lag AR Models for Prices

Getting the following error please help   Definition of Function: def LLR_test(mod_1, mod_2, DF=1):     L1 = mod_1.fit().llf     L2 = mod_2.fit().llf     LR = (2*(L2-L1))     p = chi2.sf(LR, DF).round(3)     return p   LLR_test(model_ar_2, model_ar_3)       Error Message:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-be745ec553e3> in <module>()
----> 1 LLR_test(model_ar_2, model_ar_3)

3 frames
<ipython-input-20-3e315fe52fa6> in LLR_test(mod_1, mod_2, DF)
      1 def LLR_test(mod_1, mod_2, DF=1):
----> 2     L1 = mod_1.fit().llf
      3     L2 = mod_2.fit().llf
      4     LR = (2*(L2-L1))
      5     p = chi2.sf(LR, DF).round(3)

/usr/local/lib/python3.6/dist-packages/statsmodels/tsa/arima_model.py in fit(self, start_params, trend, method, transparams, solver, maxiter, full_output, disp, callback, start_ar_lags, **kwargs)
    902         # (re)set trend and handle exogenous variables
    903         # always pass original exog
--> 904         k_trend, exog = _make_arma_exog(endog, self.exog, trend)
    905 
    906         # Check has something to estimate

/usr/local/lib/python3.6/dist-packages/statsmodels/tsa/arima_model.py in _make_arma_exog(endog, exog, trend)
    395         exog = np.ones((len(endog), 1))
    396     elif exog is not None and trend == 'c':  # constant plus exogenous
--> 397         exog = add_trend(exog, trend='c', prepend=True, has_constant='raise')
    398     elif exog is not None and trend == 'nc':
    399         # make sure it's not holding constant from last run

/usr/local/lib/python3.6/dist-packages/statsmodels/tsa/tsatools.py in add_trend(x, trend, prepend, has_constant)
    106                 msg = "x contains a constant. Adding a constant with " \
    107                       "trend='{0}' is not allowed.".format(trend)
--> 108                 raise ValueError(msg)
    109             elif has_constant == 'skip':
    110                 columns = columns[1:]

ValueError: x contains a constant. Adding a constant with trend='c' is not allowed.
1 answers ( 0 marked as helpful)
Instructor
Posted on:

15 Apr 2020

0
Hey Devansh, 
 
This question has already been answered in the Q&A Hub. https://365datascience.com/question/comparing-higher-lag-ar-models/
 
Best,
365 Vik

Submit an answer