I'm currently working on a time-series project to forecast a cumulative variable 6 steps ahead. In my model selection process I'm trying to perform a rolling origin accuracy analysis for forecasts of ARIMA, ets and other exponential smoothing models, using the ro() function.
I will use example time series data a10 for my example; Monthly anti-diabetic pharmaceutical sales in Australia from 1999 - 2008. To simplify things I shortened the time series to Jul-91 to Jun-95 (4 years worth of data).
This is the usage of the ro() function from RDocumentaton:
ro(data, h = 10, origins = 10, call, value = NULL, ci = FALSE, co = TRUE, silent = TRUE, parallel = FALSE, ...)
I want to perform a constant holdout rolling origin/cross-validation for 6 forecasts using 8 origins. When I define the "call" parameter as a forecast object for ets models I get the following error:
library("fpp")
library("forecast")
library(greybox)
a10 ## Australian anti-diabetic drug sales ts
a10_4yrs <- window(a10, end = c(1995,06)) ## shortening time series
OurCall <- "forecast(ets(a10_4yrs, model = 'AAA'), h = h, level = 85)"
OurValue <- c("mean", "lower", "upper")
## Constant holdout rolling origin using ets method
ReturnedValues <- ro(a10_4yrs, h = 6, origins = 8, call = OurCall, value = OurValue, ci = FALSE, co = TRUE)
## Error message I get when typing to run code
Error in UseMethod("forecast") :
no applicable method for 'forecast' applied to an object of class "ets"
4. forecast(ets(a10_4yrs, model = "AAA"), h = h, level = 85) at <text>#1
3. eval(parse(text = call))
2. eval(parse(text = call))
1. ro(a10_4yrs, h = 6, origins = 8, call = OurCall, value = OurValue, ci = FALSE, co = TRUE)
Any ideas on why I am getting this error? ro() is supposed to be applicable for any forecasting function, many online textbooks and articles have demonstrated the use of ro() with a forecast object so it should work
I appreciate any advice anyone can lend
Thank you in advance :)
The
forecast()generic (and so the methods registered to them) used by the{forecast}and{greybox}packages are different.This has been fixed in the latest CRAN versions of these packages, as they both now use the same generic function.
You can either update your packages, or be explicit about where the
forecast()generic is obtained from by usingforecast::forecast().Created on 2022-07-28 by the reprex package (v2.0.1)