create_combined_fc_errors_table: Create fc_error table by combination of two groups

Description Usage Arguments Value Examples

View source: R/HELPER_create_combined_fc_errors_table.R

Description

create_combined_fc_errors_table is a function to create a tibble, that has the same structure as the fc_errors table. It is formed by combining two groups via one of the four basic operators.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
create_combined_fc_errors_table(
  first_main_forecasting_table,
  second_main_forecasting_table,
  first_fc_model = "",
  second_fc_model = "",
  new_fc_model = "",
  operator = c("addition", "subtraction", "division", "multiplication"),
  group_variable = "",
  new_group_name = ""
)

Arguments

first_main_forecasting_table

A tibble containing a single row and several columns of data required for time series forecasting, which has been created using the create_main_forecasting_table function and which has been extended with the fc_models and fc_errors columns using the add_fc_models_to_main_forecasting_table function. This will be used on the left side of the operation.

second_main_forecasting_table

A tibble containing a single row and several columns of data required for time series forecasting, which has been created using the create_main_forecasting_table function and which has been extended with the fc_models and fc_errors columns using the add_fc_models_to_main_forecasting_table function. This will be used on the right side of the operation.

first_fc_model

A character specifying which forecast model to filter from first_main_forecasting_table. Only one specified forecast model may be selected!

second_fc_model

A character specifying which forecast model to filter from second_main_forecasting_table. Only one specified forecast model may be selected!

new_fc_model

The name for the fc_model column in the new fc_error table.

operator

A character that specifies what operation you want to take place between the two values. It can be either "addition", "subtraction", "multiplication" or "division".

group_variable

The name of the grouping column where the two main_forecasting_tables differ

new_group_name

The name of the new group you have created!

Value

A tibble object, structured almost identical to a typical fc_errors table. The difference is that this object also has the historical actuals data

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
29
30
31
main_forecasting_table <- dummy_gasprice %>%
      tstools::initialize_ts_forecast_data(
      date_col = "year_month",
      col_of_interest = "gasprice",
      group_cols = c("state", "oil_company")
   ) %>%
   dplyr::filter(period >= as.Date("2004-01-31")) %>%
   dplyr::filter(grouping %in% c(
      "state = New York   &   oil_company = CompanyB",
      "state = New York   &   oil_company = CompanyA"
   )) %>%
   create_main_forecasting_table() %>%
   add_fc_models_to_main_forecasting_table(
      fc_methods = c("basic", "linear", "prophet")
   )
first_main_forecasting_table <- main_forecasting_table %>%
   dplyr::filter(ts_split_date == 200512) %>%
   dplyr::filter(grouping == "state = New York   &   oil_company = CompanyB")
second_main_forecasting_table <- main_forecasting_table %>%
   dplyr::filter(ts_split_date == 200512) %>%
   dplyr::filter(grouping == "state = New York   &   oil_company = CompanyA")
create_combined_fc_errors_table(
   first_main_forecasting_table = first_main_forecasting_table,
   second_main_forecasting_table = second_main_forecasting_table,
   first_fc_model = "fc_linear_trend",
   second_fc_model = "fc_prophet_050cps",
   new_fc_model = "fc_division",
   operator = "division",
   group_variable = "oil_company",
   new_group_name = "Company-B over CompanyA"
)

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