knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Setup Libraries

## Needed otherwise vignette is not building automatically during devtools::check(), although it works ok standalone
if(!require("lattice")){
  # https://github.com/topepo/caret/issues/411#issuecomment-209973908
  install.packages("lattice", repos = "http://cran.us.r-project.org", dependencies = c("Depends", "Imports", "Suggests"))
}
library(tswgewrapped)

Load Data

file = system.file("extdata", "USeconomic.csv", package = "tswgewrapped", mustWork = TRUE)
data = read.csv(file, header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)
names(data) = gsub("[(|)]", "", colnames(data))

Basic Analysis

Setup Model Configurations

lag.max = 10

models = list("AIC None" = list(select = "aic", trend_type = "none", lag.max = lag.max),
              "AIC Trend"    = list(select = "aic", trend_type = "trend", lag.max = lag.max),
              "AIC Both" = list(select = "aic", trend_type = "both", lag.max = lag.max),
              "BIC None" = list(select = "bic", trend_type = "none", lag.max = lag.max),
              "BIC Trend"    = list(select = "bic", trend_type = "trend", lag.max = lag.max),
              "BIC Both" = list(select = "bic", trend_type = "both", lag.max = lag.max))

var_interest = 'logGNP'

Build Models

mdl_build = ModelBuildMultivariateVAR$new(data = data, var_interest = var_interest,
                                          mdl_list = models, verbose = 1)

Summarize the initial build

mdl_build$summarize_build()

Get recommendations to prevent overfitting

mdl_build$get_recommendations()

Build the recommended models

mdl_build$build_recommended_models()

Get the final models

# Get only user defined models (subset = 'u')
# Other options are ony recommended models (subset = 'r') or all models (subset = 'a') 
models = mdl_build$get_final_models(subset = 'u')
print(names(models))

Advanced Options

Adding Seasonality

lag.max = 10

models = list("AIC Trend"    = list(select = "aic", trend_type = "trend", season = 3, lag.max = lag.max),
              "BIC Trend"    = list(select = "bic", trend_type = "trend", season = 4, lag.max = lag.max)
              )

var_interest = 'logGNP'

Build Models

mdl_build = ModelBuildMultivariateVAR$new(data = data, var_interest = var_interest,
                                          mdl_list = models, verbose = 1)

Summarize the initial build

mdl_build$summarize_build()

Get recommendations to prevent overfitting

mdl_build$get_recommendations()

Build the recommended models

mdl_build$build_recommended_models()

Getting Final Models

# Get only recommended model
models = mdl_build$get_final_models(subset = 'r')
print(names(models))
# Get all models
models = mdl_build$get_final_models(subset = 'a')
print(names(models))


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