This package contains several convenient wrappers for tswge, useful for Dr. Sadler’s time series class

Installation

git clone https://github.com/josephsdavid/tswgewrapped.git
R CMD INSTALL tswgewrapped

or

devtools::install_github("josephsdavid/tswgewrapped")

or

install.packages("remotes")
remotes::install_github("josephsdavid/tswgewrapped")

Usage

Currently we have wrappers for arma, arima, aruma, sigplusnoise generators and forecasters

Time series generation and forecasting

the generate(type, ...) function generates time series, while the fcst(type, ...) function forecasts

library(tswgewrapped)

armats 

Time series transformtion

We can also transform seasonal and arima time series with the difference(type, x, n) function:

no_more_seasons 

Note that difference can accept either strings or plain words as the type argument, and accepts “arima”, “Arima”, “ARIMA”, “Aruma”, “ARUMA”, “aruma”, “seasonal”, “Seasonal” as possible values. It is also important to note that when transforming arima data more than one time (n > 1), it will output the plots for each transformation step. This is on purpose! Part of good, consistent time series analysis is to examine these plots.

Model Identification

A lot of times, it is good to not only look at the aic, but also the BIC, of your data when identifying the ARMA order of a model. For this we have the aicbic() function, which runs both aic5 and bic5 with the same arguments, returning results in the form of a list, where [[1]] is aic and [[2]] is bic (hence the name aicbic).

aicbic(no_more_seasons)
aicbic(no_more_wandering, p = 0:13, q = 0:5)

Model assessment

We can calculate the ASE of a model with the ase function:

sznback 

We can also use the assess function as a convenient wrapper for ASE, which backcasts the forecast and calculates the ASE all in one go

assess(aruma, sznlts, s = 12, phi = -.9, n.ahead = 20)

Bringing it all together

Here we present an example workflow for time series analysis, from model identification to forecasting:

examplets <- generate(aruma, n = 500, s = 12, d = 3, phi = c(.2,.4,-.2), theta = c(-.6))

First we examine our data with either plotts.sample.wge or individual tswge plotting functions:

plotts.sample.wge(examplets)

#> or

plotts.wge(examplets)
parzen.wge(examplets)
acf(examplets)

Next we have multiple tools to identify the order of the model: using Tiao-Tay overfitting and using Box-Jenkins-esque methods. For overfitting, we simply do est.ar.wge with a high value:

estim <- est.ar.wge(examplets, p = 20)

However first we likely want to look for the arima order. We can do this the box jenkins method quickly with difference

difference(arima, examplets, 5)

Since this recursively transforms, we can watch until the wandering component goes away, and set that value to be our order. We can also eliminate the seasonal component first too, with a fun guess and check technique

lapply(1:20, difference, x = examplets, type = seasonal)

and pick which seasonal component best fits. These qualitative combined with the quantitative Tiao-Tsay method of overfitting make up a complete, thourough, and well founded framework for determining the nonstationary orders of a time series, with a hopefully terse enough syntax that they will not tax the analyst more than they already are. After applying either of these graphical methods to determine one, it is probably wise to overfit using the other, and then double check by doing assessing the other component qualitatively and overfit the first. Once the order is found, we can then quickly assess the ARMA order:

library(magrittr)
szns % difference(arima, x = ., n = int_order) %>% 
    difference(seasonal, x = ., n = szns) -> transts

aics 

Next we can forecast ahead with our forecast function:

fcst(aruma, examplets, phi = pqs$phi, 
    theta = pqs$theta, s = szns, d = int_order, n.ahead = 20)

Finally we can assess our forecast with the assess (ASE) function

assess(type = aruma, x = examplets, phi = pqs$phi, 
    theta = pqs$theta, s = szns, d = int_order, n.ahead = 20)

Random time series generation:

Generate a random time series to test yourself with playground(n)

xs <- playground(400)

Univariate Time Series Model Comparison

Check out the vignette ‘ModelCompareUnivariate’

  • Supports comparig the performance of multiple univariate models (ARMA, ARIMA and Seasonal ARIMA)
  • Suppport for simple forecasts and plotting
  • Support for Batch ASE calculations and plotting
  • Statistical Comparison of models (when using batch ASE method)
  • Boxplot of model comparison (ASE values)
  • Tabular metrics for manual anaysis (if needed)

Multivariate Time Series Model EDA

Vignete pending

  • Supports plotting of realizations
  • Supports scatterplot matrix to check for correlations between variables and independence of dependent variables (assumnption of MLR model with correlated errors)
  • Support for plotting and analyzing cross-correlation data (CCF function)
  • Support for lag plots (pending)

Multivariate Time Series Model (VAR) Model Building

Check out the vignette ‘ModelBuildMultivariateVAR’

  • VAR models are prone to overfitting if we use a lot of exogenous variables with a large lag order.
  • This class supports building multiple VAR models at the same time and provides recommendations for which features to keep in the final model.
  • User can then choose to keep all original variables or use the recommended model alternative.
  • The output from this class works well with the ModelCompareMultivariateVAR class and all the original and recommended models can be compared with each other using this class

Multivariate Time Series Model (VAR) Comparison

Check out the vignette ‘ModelCompareMultivariateVAR’

  • Supports comparing the performance of multiple multivariate VAR models
  • Suppport for simple forecasts and plotting
  • Support for Batch ASE calculations and plotting
  • Statistical Comparison of models (when using batch ASE method)
  • Boxplot of model comparison (ASE values)
  • Tabular metrics for manual anaysis (if needed)

Time Series with nnfor::mlp (Neural Network) Model Building

Check out the vignette ‘ModelCompareNNforCaret’

  • Builds the model with the caret framework.
  • Suppport for predefined or random grid search
  • Supports parallel processing using multiple cores to speed up the grid search
  • Support for sliding ASE while building models

Time Series with nnfor::mlp (Neural Network) Model Comparison

Check out the vignette ‘ModelCompareNNforCaret’

  • Supports comparing the performance of multiple nnfor::mlp() submodels built by caret
  • Does not suppport simple forecasts and plotting yet (planned for the future)
  • Support for Batch ASE calculations and plotting
  • Statistical Comparison of models (when using batch ASE method)
  • Boxplot of model comparison (ASE values)
  • Tabular metrics for manual anaysis (if needed)