Learn R Programming

TSstudio (version 0.1.5)

ts_backtesting: Evaluation Function for Forecasting Models

Description

Performance evaluation function for forecasting models, by training and testing the performance of each model over a sequence of periods to identify the performance of a model over time (both accuracy and stability)

Usage

ts_backtesting(ts.obj, models = "abehntw", periods = 6,
  error = "MAPE", window_size = 3, h = 3, plot = TRUE,
  a.arg = NULL, b.arg = NULL, e.arg = NULL, h.arg = NULL,
  n.arg = NULL, t.arg = NULL, w.arg = NULL, xreg.h = NULL,
  parallel = FALSE)

Arguments

ts.obj

A univariate time series object of a class "ts"

models

String, define the type of models to use in the training function:

'a' - auto.arima (forecast package)

'b' - Bayesian Structural Time Series (bsts package)

'e' - ets (forecast package)

'h' - hybrid timse series model (forecastHybrid package)

'n' - Neural Network Time Series (forecast package)

't' - tbats (forecast package)

'w' - Holt Winters (stats package)

periods

The number of periods to evaluate the models (with a minimum of 2)

error

The type of error to evaluate by - "MAPE" (default) or "RMSE"

window_size

An integer, the size of the backtesting window

h

Integer, the horizon of the selected forecasting model

plot

Logical, if TRUE desplay a plot with the backtesting progress

a.arg

A list, an optional arguments to pass to the auto.arima function

b.arg

A list, an optional arguments to pass to the bsts function

e.arg

A list, an optional argument to pass to the ets function

h.arg

A list, an optional argument to pass to the hybridModel function

n.arg

A list, an optional argument to pass to the nnetar function

t.arg

A list, an optional arguments to pass to the tbats function

w.arg

A list, an optional arguments to pass to the HoltWinters function

xreg.h

A data.frame or matrix, optional argument, set the futuer values external regressors in case using the 'xreg' argument in one of the models (auto.arima, nnetar, hybrid)

parallel

Logical, if TRUE use parallel option when applicable (auto.arima, hybridModel)

Examples

Run this code
# NOT RUN {
data(USgas)
USgas_backtesting <- ts_backtesting(USgas, 
                                    periods = 6, 
                                    window_size = 24, 
                                    h = 60, 
                                    error = "RMSE")

# Selecting a specific models (auto.arima, ets and nnetar)
USgas_backtesting <- ts_backtesting(USgas, 
                                    models = "aen", 
                                    periods = 6, 
                                    window_size = 24, 
                                    h = 60)
 
# Retrieve the models leaderboard
USgas_backtesting$leaderboard


# Retrieve the best forecast results
USgas_backtesting$leadForecast$mean

# Retrieve the final forecast of the ets model
USgas_backtesting$Forecast_Final$ets$mean

# Retrieve the ets forecast during the first period of testing
USgas_backtesting$period_1$ets$forecast$mean

# Get the final plot of the models performance and the selected forecasting model
USgas_backtesting$summary_plot
# }

Run the code above in your browser using DataLab