# NOT RUN {
series <- subset(AirPassengers, end = 50)
cvmod1 <- cvts(series, FUN = snaive,
windowSize = 25, maxHorizon = 12)
accuracy(cvmod1)
# We can also use custom model functions for modeling/forecasting
stlmClean <- function(x) stlm(tsclean(x))
series <- subset(austres, end = 38)
cvmodCustom <- cvts(series, FUN = stlmClean, windowSize = 26, maxHorizon = 6)
accuracy(cvmodCustom)
# }
# NOT RUN {
# Use the rwf() function from the "forecast" package.
# This function does not have a modeling function and
# instead calculates a forecast on the time series directly
series <- subset(AirPassengers, end = 26)
rwcv <- cvts(series, FCFUN = rwf, windowSize = 24, maxHorizon = 1)
# Don't return the model or forecast objects
cvmod2 <- cvts(USAccDeaths, FUN = stlm,
saveModels = FALSE, saveForecasts = FALSE,
windowSize = 36, maxHorizon = 12)
# If we don't need prediction intervals and are using the nnetar model, turning off PI
# will make the forecasting much faster
series <- subset(AirPassengers, end=40)
cvmod3 <- cvts(series, FUN = hybridModel,
FCFUN = function(mod, h) forecast(mod, h = h, PI = FALSE),
rolling = FALSE, windowSize = 36,
maxHorizon = 2)
# }
Run the code above in your browser using DataLab