if (FALSE) {
### Building train_model function by adding its different components
# Create a skeleton model
md <- create_model()
class(md)
# Add input
data(USgas)
md <- add_input(model.obj = md, input = USgas)
# Add methods
methods <- list(ets1 = list(method = "ets",
method_arg = list(opt.crit = "lik"),
notes = "ETS model with opt.crit = lik"),
ets2 = list(method = "ets",
method_arg = list(opt.crit = "amse"),
notes = "ETS model with opt.crit = amse"),
arima1 = list(method = "arima",
method_arg = list(order = c(1,1,1),
seasonal = list(order = c(1,0,1))),
notes = "SARIMA(1,1,1)(1,0,1)"))
md <- add_methods(model.obj = md, methods = methods)
# Add additional methods
methods2 <- list(arima2 = list(method = "arima",
method_arg = list(order = c(2,1,2),
seasonal = list(order = c(1,1,1))),
notes = "SARIMA(2,1,2)(1,1,1)"),
hw = list(method = "HoltWinters",
method_arg = NULL,
notes = "HoltWinters Model"),
tslm = list(method = "tslm",
method_arg = list(formula = input ~ trend + season),
notes = "tslm model with trend and seasonal components"))
md <- add_methods(model.obj = md, methods = methods2)
# Remove methods
md <- remove_methods(model.obj = md, method_ids = c("ets2"))
# Add train method
md <- add_train_method(model.obj = md, train_method = list(partitions = 6,
sample.out = 12,
space = 3))
# Set the forecast horizon
md <- add_horizon(model.obj = md, horizon = 12)
# Add the forecast prediction intervals confidence level
md <- add_level(model.obj = md, level = c(90, 95))
### Alternatively, pipe the function with the magrittr package
library(magrittr)
md <- create_model() %>%
add_input(input = USgas) %>%
add_methods(methods = methods) %>%
add_methods(methods = methods2) %>%
add_train_method(train_method = list(partitions = 4,
sample.out = 12,
space = 3)) %>%
add_horizon(horizon = 12) %>%
add_level(level = c(90, 95))
# Run the model
fc <- md %>% build_model()
}
Run the code above in your browser using DataLab