add_ctree_forecast_model: Add CTREE forecast model

Description Usage Arguments Value Examples

View source: R/INTRA_FORECAST_add_ctree_forecast_model.R

Description

add_ctree_forecast_model is a function to add a single CTREE tree forecast model to a (named) list of forecast models. The forecast model has hyper-parameters that are automatically tuned. However the amount of fine-tuning can be determined by the user

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
add_ctree_forecast_model(
  fc_models,
  ts_object_train,
  ts_object_valid = NULL,
  fc_name,
  model_type = c("univariate", "multivariate"),
  periods_ahead = 1,
  periods_history = Inf,
  keep_fc_model_objects = FALSE,
  verbose = FALSE,
  log_message = ""
)

Arguments

fc_models

A named list of forecast models, with for each forecast model a list with the model itself and a table with forecast values.

ts_object_train

A time series object, which contains only the training data.

ts_object_valid

A time series object, which contains the validation data. This is used for multivariate frameworks, thus it should have the forecasted/actual values of the external regressors as well.

fc_name

A character string specifying the name to be used for the new model that is added to the list of existing forecast models.

model_type

A character string indicating whether a univariate model (without external regressors) or a multivariate model (with external regressors) should be estimated.

periods_ahead

A positive integer value indicating the number of periods to forecast ahead.

periods_history

A positive integer value indicating the number of historic datapoints to use for training, which is only relevant for specific forecast methods such as drift and mean.

verbose

Boolean, indicating whether or not the function should print messages while running.

Value

A named list of forecast models, with for each forecast model a list with the model itself and a table with forecast values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
ts_object_train <- tstools::initialize_ts_forecast_data(
      data = dummy_gasprice,
      date_col = "year_month",
      col_of_interest = "gasprice",
      group_cols = c("state", "oil_company"),
      xreg_cols = c("spotprice", "gemprice")
   ) %>%
   dplyr::filter(grouping == "state = New York   &   oil_company = CompanyA") %>%
   dplyr::slice(1:189) %>%
   tstools::transform_data_to_ts_object()
ts_object_valid <- tstools::initialize_ts_forecast_data(
      data = dummy_gasprice,
      date_col = "year_month",
      col_of_interest = "gasprice",
      group_cols = c("state", "oil_company"),
      xreg_cols = c("spotprice", "gemprice")
   ) %>%
   dplyr::filter(grouping == "state = New York   &   oil_company = CompanyA") %>%
   dplyr::slice(190:191) %>%
   tstools::transform_data_to_ts_object()
add_ctree_forecast_model(
   fc_models = list(),
   ts_object_train = ts_object_train,
   ts_object_valid = ts_object_valid,
   fc_name = "Example_CTREE",
   model_type = "multivariate",
   periods_ahead = 2
 )

ing-bank/tsforecast documentation built on Sept. 18, 2020, 9:40 a.m.