R forecast season and trend of data using stl and arima R forecast season and trend of data using stl and arima r r

R forecast season and trend of data using stl and arima


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.