ModelCompareUnivariate: R6 class ModelCompareUnivariate

Description Super class Methods Examples

Description

R6 class ModelCompareUnivariate

R6 class ModelCompareUnivariate

Super class

tswgewrapped::ModelCompareBase -> ModelCompareUnivariate

Methods

Public methods

Inherited methods

Method new()

Initialize an object to compare several Univatiate Time Series Models

Usage
ModelCompareUnivariate$new(
  data = NA,
  var_interest = NA,
  mdl_list,
  n.ahead = NA,
  batch_size = NA,
  step_n.ahead = TRUE,
  verbose = 0
)
Arguments
data

A Univariate Time Series Realization

var_interest

If data is a dataframe with multiple columns, then what is the output variable of interest

mdl_list

A named list of all models (see format below)

n.ahead

The number of observations used to calculate ASE or forecast ahead

batch_size

If any of the models used sliding ase method, then this number indicates the batch size to use

step_n.ahead

If using sliding window, should batches be incremented by n.ahead (Default = TRUE)

verbose

How much to print during the model building and other processes (Default = 0)

Returns

A new 'ModelCompareUnivariate' object.


Method get_data_var_interest()

Returns the dependent variable data only

Usage
ModelCompareUnivariate$get_data_var_interest()
Returns

The dependent variable data only


Method plot_multiple_realizations()

Creates multiple realization of each model. Useful to check model appropriateness.

Usage
ModelCompareUnivariate$plot_multiple_realizations(
  n.realizations = 4,
  lag.max = 25,
  seed = NA,
  plot = c("all"),
  scales = "free_y"
)
Arguments
n.realizations

Number of realization to create (Default: 4)

lag.max

lag.max to plot for ACF (Default: 25)

seed

The seed to use for generating realizations

plot

A vector of options to plot (Default = c("all")) Other options: 'realization', 'acf', 'spectrum'

scales

The scales argument to be passed to ggplot facet_wrap layer (Default = 'free_y') Other appropriate options: 'fixed'


Method evaluate_residuals()

For the models for which the residuals have been provided, this method will check whetehr the residuals are white noise or not. (1) Plots the residuals and the ACF values (2) Performs the Ljung-Box test for K = 24 and K = 48

Usage
ModelCompareUnivariate$evaluate_residuals(lag.max = 50)
Arguments
lag.max

The maximum lag to plot for the ACF

Returns

A dataframe containing the results of the 2 Ljung-Box tests


Method summarize_build()

Not applicable for the Univariate Compare, since we are passing already build models

Usage
ModelCompareUnivariate$summarize_build()

Method clone()

The objects of this class are cloneable with this method.

Usage
ModelCompareUnivariate$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
library(tswge)
data("airlog")

# Woodward Gray Airline Model
phi_wg = c(-0.36, -0.05, -0.14, -0.11, 0.04, 0.09, -0.02, 0.02, 0.17, 0.03, -0.10, -0.38)
d_wg = 1
s_wg = 12

# Parzen Model
phi_pz = c(0.74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.38, -0.2812)
s_pz = 12

# Box Model
d_bx = 1
s_bx = 12  
theta_bx =  c(0.40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.60, -0.24)

models = list("Woodward Gray Model A" = list(phi = phi_wg, d = d_wg, s = s_wg, sliding_ase = FALSE),
              "Woodward Gray Model B" = list(phi = phi_wg, d = d_wg, s = s_wg, sliding_ase = TRUE),
              "Parzen Model A" = list(phi = phi_pz, s = s_pz, sliding_ase = FALSE),
              "Parzen Model B" = list(phi = phi_pz, s = s_pz, sliding_ase = TRUE),
              "Box Model A" = list(theta = theta_bx, d = d_bx, s = s_bx, sliding_ase = FALSE),
              "Box Model B" = list(theta = theta_bx, d = d_bx, s = s_bx, sliding_ase = TRUE)
              )
              
mdl_compare = ModelCompareUnivariate$new(data = airlog, mdl_list = models,
                                         n.ahead = 36, batch_size = 72)
# Plots the historgam of the ASE values for each model.
# This is especially useful when models using a sliding window for ASE calculations. 
mdl_compare$plot_boxplot_ases()

# The following method gives 2 plots
# (1) Plots the forecasts for each model along with the realization.
# (2) Plots the upper and lower limits for each model along with the realization.
# In both cases, this marks each batch using a background color for ease of comparison.
# only_sliding = TRUE will only plot forecsts for models using sliding ASE  calculations.
mdl_compare$plot_batch_forecasts(only_sliding = TRUE)

# This method statistically compares all the models that use a sliding window ASE calculation
mdl_compare$statistical_compare()  

ASEs = mdl_compare$get_tabular_metrics(ases = TRUE)
print(ASEs)

# This method returns the metrics (ASE values) or forecasts for each model
# 'only_sliding' If set to TRUE, only the models that use a sliding window 
#                ASE calculation will be returned
# 'ases' If set to TRUE, this method will return the ASE value(s) 
#        Single value for models that don't use sliding ASEs and 
#        Multiple values (one per batch) for models that use sliding window
#        ASE calculations
#        If set to FALSE, this function will return the model forecasts and 
#        upper and lower confidence intervals. 
forecasts = mdl_compare$get_tabular_metrics(ases = FALSE)
print(forecasts)

josephsdavid/tswgewrapped documentation built on July 31, 2020, 9:36 a.m.