I have a data series that has a seasonal component, a trend and an arma part. I want to forecast 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 in doing this I am not able to choose the parameters of the Arima part, which I would like to. The above seems to be using something like auto.arima as i chooses the arima parameters by itself - but it runs really fast and much faster than auto.arima - so not sure what happens.
Alternatively I can use the above to split the data into a season a trend and a remainder part. But then how do I forecast it? Should I make an arma model for both the trend and the remainder?
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))
and then use forecast() and add the two above components and the season. Or is there some way to extract the trend model that stl has found?
Thanks for any hints :) Benjamin
The forecast.stl
function is using auto.arima
for the remainder series. It is fast because it does not need to consider seasonal ARIMA models.
You can select a specific model with specific parameters via the forecastfunction
argument. For example, suppose you wanted to use an AR(1) with parameter 0.7, the following code will do it:
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 select the ARIMA order, but not the parameters, then leave out the fixed
argument.