9
votes

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

1
stl 'decomposes a time series into seasonal, trend and irregular components using loess' (local regression), see ?stl. Thus, this is no ARIMA model. If you know that your time series follows an ARIMA process with seasonality and trend, why don't you fit a seasonal ARIMA model and difference the data accordingly? See e.g. otexts.org/fpp/8/9. If STL or ARIMA performs better is up to interpretation/testing. - thie1e
Thanks, @Khl4v I was looking at otexts.org/fpp/6/6 which describes stl where the author writes "To forecast the seasonally adjusted component, any non-seasonal forecasting method may be used. For example, a random walk with drift model, or Holt’s method (discussed in the next chapter), or a non-seasonal ARIMA model". This is why I tried to use an arima model to model the unseasonal part and then afterwards to put the season, the trend and the remainder together for forecasting purposes. But you think this is not the way to go? Thanks once again :) - bbiegel
OK, so you have read that already. I was just wondering why you are not using an ARIMA model when you think it is an ARIMA process. - thie1e
Thanks for the reply! :) Yes, I will try both seasonal arima and the stl+arima method and see what performs best. - bbiegel

1 Answers

10
votes

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.