config-i1 / smooth

The set of functions used for time series analysis and in forecasting.
89 stars 19 forks source link

Error in polyroot(polysos.ar) : root finding code failed #78

Closed PetoLau closed 7 years ago

PetoLau commented 7 years ago

Hello Ivan, first of all, I am big fan of your package, great work! Especially with function es(). But :) little problem with function auto.ssarima(). has occurred. It outputs an error for my data: Error in polyroot(polysos.ar) : root finding code failed I have double seasonal TS and I'm trying to incorporate xreg to it (fourier() in package forecast). I have something like this (maybe little bit complicated): data_ts <- msts(data$value, seasonal.periods = c(period,period*7)) fuur <- fourier(data_ts, K = c(0, 6*2)) fuur <- rbind(fuur, fourier(data_ts, K = c(0, 6*2), h = period*7)) data_ts <- ts(data$value, freq = period) test.arima <- auto.ssarima(data_ts, orders = list(ar=c(3,3),i=c(1,1),ma=c(2,2)), lags=c(1,period), h=period*7, cfType = "MAE", xreg = fuur, intervals = "none", initial = "backcasting")

Simple ssarima() works perfectly, but auto.ssarima gives that error. Thank you very much for any help. Peter

config-i1 commented 7 years ago

Hi Peter, Thanks! Good to hear that package is useful :)

Can you, please, give a reproducible code? Or attach data somehow, so I can test it and find the error on my PC...

PetoLau commented 7 years ago

Ok. Code: library(data.table) data <- fread("sample_data.csv") and the same code from the above comment. Data here: sample_data.zip

Thanks

config-i1 commented 7 years ago

I run this:

test.arima <- auto.ssarima(data_ts, orders = list(ar=c(3,3),i=c(1,1),ma=c(2,2)), lags=c(1,24), h=24*7, cfType = "MAE", xreg = fuur, intervals = "none", initial = "backcasting")

I get this:

Time elapsed: 93.68 seconds Model estimated: SARIMAX(3,1,2)[1] (2,0,0)[24] with drift Matrix of AR terms: Lag 1 Lag 24 AR(1) 0.654 -0.013 AR(2) 0.227 0.258 AR(3) 0.013 0.000 Matrix of MA terms: Lag 1 MA(1) -0.476 MA(2) -0.166 Constant value is: -0.007 Initial values were produced using backcasting. 33 parameters were estimated in the process Residuals standard deviation: 212.059 Xreg coefficients were estimated in a normal style Cost function type: MAE; Cost function value: 116.128

Information criteria: AIC AICc BIC 5168.206 5171.723 5317.044

And a graph with a ridiculous forecast. But it seems to work okay on my PC (I used the recent version of smooth from github, v2.0.0).

But I get your error when I fit the following model with double seasonality: test.arima <- auto.ssarima(data_ts, orders = list(ar=c(3,3,2),i=c(1,1,1),ma=c(2,2,2)), lags=c(1,24,7*24), h=24*7, cfType = "MAE")

The error itself actually tells that polyroot() function (from base package) could not find the roots of polinomials, thus unable to test if the model is stationary and/or invertible. If you encounter this error and need to fix it fast, use bounds="none", which does not do that check and is dangerous, but may produce some acceptable results. However this feature didn't work until now in auto.ssarima(), but is now fixed in the recent commit. So update the package from github first.

Now let me investigate this thing and find a fix.

config-i1 commented 7 years ago

Okay. This is finally fixed in 93605fa9609259618118b493f4ac8e9fe770382c. The model takes more time to estimate now (e.g. 109.47 seconds for the model in the previous comment). But ssarima() is in general pretty slow model. I don't know how to fix this yet.

PetoLau commented 7 years ago

Thank you for your pieces of advice, Ivan. I am sorry, I forgot to set period to 48, it's not 24 :) I didn't know that to ssarima model is possibility to add double (or multiple) seasonality, I will try it too. It would be great to mention that on your already great vignettes.

config-i1 commented 7 years ago

That's a good idea. I'll include that in the vignettes. I will cover ssarima() at some point in one of the posts on my website: http://forecasting.svetunkov.ru/en/ I'll mention multiple seasonality feature.