ellisp / forecastHybrid

Convenient functions for ensemble forecasts in R combining approaches from the {forecast} package
GNU General Public License v3.0
79 stars 23 forks source link

CV ggplot2::economics #98

Closed Libardo1 closed 2 years ago

Libardo1 commented 2 years ago

Thanks for your package. I am trying to use it with ggplot2::economics but is not working for me.

myts <- ts(economics$unemploy , start = c(1967,7), frequency = 12, deltat = 1) plot(myts) stl_rw <- stlf(myts, forecastfunction = rwf) image

Then stlmMod <- cvts(myts, FUN = stlm, windowSize = 36, maxHorizon = 250) naiveMod <- cvts(myts, FUN = naive, windowSize = 36, maxHorizon = 250) accuracy(stlmMod) I receive this error message Error in { : task 1 failed - "Please select a longer horizon when the forecasts are first computed"

I change maxHrizon from 12 to 250 and the error is the same.

I would apreciate any hint to solved it.

dashaub commented 2 years ago

@Libardo1 The error is actually for the creation of naiveMod. The naive function in fact produces a class forecast object whereas the parameter for FUN needs to be a model object. To handle this kind of scenario, we have the FCFUN argument where our custom function generates the forecast class object directly. So try

stlmMod <- cvts(myts, FUN = stlm, windowSize = 36, maxHorizon = 250)
naiveMod <- cvts(myts, FCFUN = naive, windowSize = 36, maxHorizon = 250)
accuracy(naiveMod)
accuracy(stlmMod)