Statsmodels SARIMAX: How can I deal with the maxlag error?
Asked Answered
U

2

6

I am trying to predict a seasonal time series using SARIMAX. The time series consits of daily maximum values for PV-feed-in, which leads to the assumption of a 365 day periodicity.

Here is my code:

mod= SARIMAX(realy.Max, order=(0,1,1), seasonal_order=(0,1,1,365))
results_SARIMAX = mod.fit(disp= -1)

I set s in seasonal_order to 365 because of my periodicity. Also I set the variables p,d,q, respectively P,D,Q according to some pre-considerations. My problem is, that after executing the code the following error is drawn:

ValueError: maxlag should be < nobs

When I set the value for s down from 365 to i.e. 150 it is working, but the result is bad, since this isn't my seasonality at all. The question is, where are maxlag or nobs defined and am I able to change them accordingly?

The docstring of the SARIMAX function is only telling about quaterly or monthly data and not daily data. Does someone has experience in working with SARIMAX and already did predictions with a time series based on daily values? I've scoured the internet for solving the problem, but I cannot find anything helpful.

Similar questions already came up here How to set maxlag when Forecasting Sales for smaller data in SARIMAX? and here How to change maxlag for ARMAX.predict?

But I don't understand how to overcome this problem in my case, since I don't have any exogenous values to commit.

I also built a model based on ARIMA with which I am able to do proper predictions. Since I'm not having a non-seasonal time series, I thought it might be a good idea to use SARIMAX for getting even better results. Unfortunately, I'm not able to deal with this error.

Thanks for your help in advance!

Unhandled answered 9/3, 2017 at 17:41 Comment(4)
how many years of data do you have?Killick
Sorry, thought I mentioned that. I got 2,5 years of data.Unhandled
Apparently, there is a problem with setting Q =1 and s = 365 at the same time. By setting Q=0 and s =365 it is working. Though, I don't understand that. As far as I understood, in a seasonal ARIMA model I have three more knobs to play with, which are P,Q,D. The three of them must not be larger than 1 each. Setting Q = 1 means, that I'm adding a multiple of my seasonal lagged error et-s with s =365 to the forecast of my time series. When it's only working with Q =0, I have no seasonality anymore?!Unhandled
An alternative to the SARIMAX model is to use Facebook's Prophet libraryHaircloth
K
6

You need several years (full seasonal cycles) to be able to estimate the seasonal part of a SARIMAX, see https://github.com/statsmodels/statsmodels/issues/3529 .

As an alternative you could use a spline or fourier series to model the seasonal pattern as exog. See for example http://robjhyndman.com/hyndsight/longseasonality/

Here is a draft notebook that uses patsy formula to create a seasonal spline for OLS and ARMA. SARIMAX will work in the same way. https://gist.github.com/josef-pkt/1ea164439b239b228557

Killick answered 10/3, 2017 at 13:4 Comment(1)
Thanks for the answer. I'll check whether this helps.Unhandled
M
0

You can try this, it solved my problem:

mod_sl_ar = sm.tsa.statespace.SARIMAX(train[var],exog=train[arimax_vars],order= [0,1,2] , seasonal_order= [0,1,1,52] ,mle_regression=True)
start_params = np.r_[[0] * (mod_sl_ar.k_params - 1), 1]
res_sl_ar = mod_sl_ar.fit(start_params=start_params)
predictions = res_hl_ar.forecast(len(test),exog=test[arimax_vars], dynamic= True)

Source

Mahalia answered 19/5, 2022 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.