ctree_fit: Determine model fit of CTREE tree

Description Usage Arguments Value Examples

View source: R/INTRA_FORECAST_ctree_fit.R

Description

ctree_fit A function to gauge the fit of a model run of an CTREE tree, given parameters. This is a function that is used to fine-tune the CTREE tree when forecasting

Usage

1
2
3
4
5
6
7
8
9
ctree_fit(
  ML_data,
  minsplit,
  mincriterion,
  minbucket,
  testtype = c("Bonferroni", "MonteCarlo", "Univariate", "Teststatistic"),
  teststat = c("quad", "max"),
  nresample = 9999
)

Arguments

ML_data

Dataset that has been prepared to run through CTREE. If originally a time series object, then it has gone through the decompose_ts_object_for_ML function and the first difference of the column of interest has been taken

minsplit

CTREE parameter. The minimum number of observations that must exist in a node in order for a split to be attempted (default from CTREE = 20)

mincriterion

CTREE parameter. The value of the test-statistic (testtype == "Teststatistic") or 1 - p-value that must be exceeded in order to implement a split (default from CTREE = 0.95)

minbucket

CTREE parameter. Minimum sum of weights in a terminal node (default from CTREE = 7)

testtype

CTREE parameter. Which distribution to use. Options are "Bonferroni", "MonteCarlo", "Univariate" and "Teststatistic"

teststat

CTREE parameter. Specifies which test statistic to use when doing hypothesis testing. Options are "quad" and "max"

nresample

CTREE parameter. Amount of resampling to do when MonteCarlo is selected as test type (default from CTREE = 9999)

Value

The mean absolute prediction error (MAPE), in percentage terms, of the model run

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
ML_data <- 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") %>% 
   tstools::transform_data_to_ts_object() %>% 
   decompose_ts_object_for_ML(filter_date_features = T) %>% 
   dplyr::mutate(col_of_interest = col_of_interest - dplyr::lag(col_of_interest)) %>% 
   dplyr::filter(!is.na(col_of_interest))
ctree_fit(
   ML_data = ML_data, 
   minsplit = 20, 
   mincriterion = 0.975, 
   minbucket = 5, 
   testtype = "Univariate", 
   teststat = "quad", 
   nresample = 9999
)

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