knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The objective of this vignette is to show how to use the ModelCompareUnivariate object to compare multiple potential models.
library(tswgewrapped) 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, vara = 0.001357009, sliding_ase = FALSE), "Woodward Gray Model B" = list(phi = phi_wg, d = d_wg, s = s_wg, vara = 0.001357009, sliding_ase = TRUE), "Parzen Model A" = list(phi = phi_pz, s = s_pz, vara = 0.002933592, sliding_ase = FALSE), "Parzen Model B" = list(phi = phi_pz, s = s_pz, vara = 0.002933592, sliding_ase = TRUE), "Box Model A" = list(theta = theta_bx, d = d_bx, s = s_bx, vara = 0.001391604, sliding_ase = FALSE), "Box Model B" = list(theta = theta_bx, d = d_bx, s = s_bx, vara = 0.001391604, sliding_ase = TRUE) )
#### With n_step.ahead = TRUE (Default) mdl_compare = ModelCompareUnivariate$new(data = airlog, mdl_list = models, n.ahead = 36, batch_size = 72)
p = mdl_compare$plot_multiple_realizations(n.realizations = 4, seed = 100, plot = "realization", scales = 'fixed')
p = mdl_compare$plot_multiple_realizations(n.realizations = 4, seed = 100, plot = c("acf", "spectrum"), scales = 'fixed')
p = mdl_compare$plot_boxplot_ases()
mdl_compare$statistical_compare()
p = mdl_compare$plot_simple_forecasts(lastn = TRUE, limits = FALSE) p = mdl_compare$plot_simple_forecasts(lastn = TRUE, limits = TRUE) p = mdl_compare$plot_simple_forecasts(lastn = FALSE, limits = FALSE) p = mdl_compare$plot_simple_forecasts(lastn = FALSE, limits = TRUE) p = mdl_compare$plot_simple_forecasts(zoom = 50) ## Zoom into plot
p = mdl_compare$plot_batch_forecasts(only_sliding = TRUE)
ASEs = mdl_compare$get_tabular_metrics(ases = TRUE) print(ASEs)
forecasts = mdl_compare$get_tabular_metrics(ases = FALSE) print(forecasts)
## Add initial set of models (without sliding ASE) models = list("Woodward Gray Model A" = list(phi = phi_wg, d = d_wg, s = s_wg, vara = 0.001357009, sliding_ase = FALSE), "Parzen Model A" = list(phi = phi_pz, s = s_pz, vara = 0.002933592, sliding_ase = FALSE), "Box Model A" = list(theta = theta_bx, d = d_bx, s = s_bx, vara = 0.001391604, sliding_ase = FALSE) ) mdl_compare = ModelCompareUnivariate$new(data = airlog, mdl_list = models, n.ahead = 36)
# Following will give an error because we are trying to add models with the same name again # mdl_compare$add_models(mdl_list = models)
## Add models with Sliding ASE models = list("Woodward Gray Model B" = list(phi = phi_wg, d = d_wg, s = s_wg, vara = 0.001357009, sliding_ase = TRUE), "Parzen Model B" = list(phi = phi_pz, s = s_pz, vara = 0.002933592, sliding_ase = TRUE), "Box Model B" = list(theta = theta_bx, d = d_bx, s = s_bx, vara = 0.001391604, sliding_ase = TRUE) ) # This will give warning for batch size which has not been set. # Internally it will be set to use just 1 batch since nothing has been specified. mdl_compare$add_models(mdl_list = models) # This will give a warning and set only 1 batch # mdl_compare$add_models(mdl_list = models, batch_size = 72) ## This will not give a warning
# If you had forgotten to set the batch size, you can do it after the fact mdl_compare$set_batch_size(72) # Check all functions after data manipulation p = mdl_compare$plot_simple_forecasts(zoom = 72) p = mdl_compare$plot_batch_forecasts(only_sliding = TRUE) p = mdl_compare$plot_batch_ases(only_sliding = TRUE) p = mdl_compare$plot_boxplot_ases() mdl_compare$statistical_compare()
## After comparison, maybe you want to remove some models that are not performing well or you do not want to show in your plots mdl_names = c("Woodward Gray Model A", "Parzen Model A", "Box Model A", "Parzen Model B") # Remove models mdl_compare$remove_models(mdl_names = mdl_names) # Check all functions after data manipulation p = mdl_compare$plot_simple_forecasts() p = mdl_compare$plot_batch_forecasts() p = mdl_compare$plot_batch_ases() p = mdl_compare$plot_boxplot_ases() mdl_compare$statistical_compare()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.