R forecast and data trend using stl and arima

I have a series of data that has a seasonal component, a trend, and part of the arm. I want to predict this series based on history.

I can use the procedure

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE) 
f <- forecast(data_deseason, method='arima', h = N)

but at the same time, I cannot select the parameters of the Arima part that I would like. The above seems to use something like auto.arima, as I select the arima parameters on my own, but it works very fast and much faster than auto.arima, so I'm not sure what is going on.

As an alternative, I can use the above to split the season data by trend and the rest. But how can I predict this? Should I create an arm model for both the trend and the rest?

trend_arima <- Arima(data_deseason$time.series[,'trend'], order = c(1,1,1))
remainder_arima <- Arima(data_deseason$time.series[,'remainder'], order = c(1,1,1))

then use the forecast () and add the two above components and the season. Or is there a way to extract the trend model found by stl?

Thanks for any tips :) Benjamin

+4
source share
1 answer

Function forecast.stluses auto.arimafor the remaining series. This is fast because ARIMA seasonal models do not need to be considered.

You can select a specific model with specific parameters using the argument forecastfunction. For example, suppose you want to use AR (1) with parameter 0.7, the following code will do this:

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE) 
f <- forecast(data_deseason, h=N,
        forecastfunction=function(x,h,level){
        fit <- Arima(x, order=c(1,0,0), fixed=0.7, include.mean=FALSE)
        return(forecast(fit,h=N,level=level))})
plot(f)

If you just want to choose the ARIMA order, but not the parameters, leave an argument fixed.

+5
source

All Articles