Search code examples
rtime-seriesforecastingforecast

baggedModel (fn="ets") function for weekly data?


Is there any way to use the baggedModel() function in the R forecast package with the ets function argument for weekly data?

As the default ets can't handle data with a frequency greater than 24, baggedModel doesn't work for weekly data when the function chosen is ETS.

Without bagging, using stlf() works well for weekly data, but I would like to try bagging as well, if possible.

Sub-question: is there any difference between forecasts produced by the forecast() and forecast.baggedModel() functions when both are fed by a baggedModel object? For some reason, R cannot find the forecast.baggedModel() function, although all other functions in the forecast package work well.


Solution

  • No, as you have already found ets() does not work for high seasonal periods. The reason is that there are too many degrees of freedom associated with the seasonality --- with period 52, there would be 51 degrees of freedom just on the seasonal component which makes little sense.

    Using forecast v8.5+, you can use the equivalent of stlf() with bagging as follows.

    library(fpp2)
    
    gasoline %>%
     baggedModel(fn=stlm, method='arima') %>%
     forecast(h=2*52) %>%
     autoplot()
    

    forecast() is a method that calls the appropriate forecast.xxx() function depending on the class of its first argument. For the objects produced by baggedModel, is uses forecast.baggedModel(). This function is not exported, but you can see the code using forecast:::forecast.baggedModel().