hybridModel: Hybrid time series modeling

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/hybridModel.R

Description

Create a hybrid time series model with two to five component models.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
hybridModel(
  y,
  models = "aefnst",
  lambda = NULL,
  a.args = NULL,
  e.args = NULL,
  n.args = NULL,
  s.args = NULL,
  t.args = NULL,
  z.args = NULL,
  weights = c("equal", "insample.errors", "cv.errors"),
  errorMethod = c("RMSE", "MAE", "MASE"),
  rolling = FALSE,
  cvHorizon = frequency(y),
  windowSize = 84,
  horizonAverage = FALSE,
  parallel = FALSE,
  num.cores = 2L,
  verbose = TRUE
)

Arguments

y

A numeric vector or time series.

models

A character string of up to seven characters indicating which contributing models to use: a (auto.arima), e (ets), f (thetam), n (nnetar), s (stlm), t (tbats), and z (snaive).

lambda

Box-Cox transformation parameter. Ignored if NULL. Otherwise, data transformed before model is estimated.

a.args

an optional list of arguments to pass to auto.arima. See details.

e.args

an optional list of arguments to pass to ets. See details.

n.args

an optional list of arguments to pass to nnetar. See details.

s.args

an optional list of arguments to pass to stlm. See details.

t.args

an optional list of arguments to pass to tbats. See details.

z.args

an optional list of arguments to pass to snaive. See details.

weights

method for weighting the forecasts of the various contributing models. Defaults to equal, which has shown to be robust and better in many cases than giving more weight to models with better in-sample performance. Cross validated errors–implemented with link{cvts} should produce the best forecast, but the model estimation is also the slowest. Note that extra arguments passed in a.args, e.args, n.args, s.args, and t.args are not used during cross validation. See further explanation in cvts. Weights utilizing in-sample errors are also available but not recommended.

errorMethod

method of measuring accuracy to use if weights are not to be equal. Root mean square error (RMSE), mean absolute error (MAE) and mean absolute scaled error (MASE) are supported.

rolling

If weights = "cv.errors", this controls the use of rolling cross validation in cvts()

cvHorizon

If weights = "cv.errors", this controls which forecast to horizon to use for the error calculations.

windowSize

length of the window to build each model, only used when weights = "cv.errors".

horizonAverage

If weights = "cv.errors", setting this to TRUE will average all forecast horizons up to cvHorizon for calculating the errors instead of using the single horizon given in cvHorizon.

parallel

a boolean indicating if parallel processing should be used between models. Parallelization will still occur within individual models that support it and can be controlled using a.args and t.args.

num.cores

If parallel=TRUE, how many cores to use.

verbose

Should the status of which model is being fit/cross validated be printed to the terminal?

Details

The hybridModel function fits multiple individual model specifications to allow easy creation of ensemble forecasts. While default settings for the individual component models work quite well in most cases, fine control can be exerted by passing detailed arguments to the component models in the a.args, e.args, n.args, s.args, and t.args lists. Note that if xreg is passed to the a.args, n.args, or s.args component models it must now be passed as a matrix. In "forecastHybrid" versions earlier than 4.0.15 it would instead be passed in as a dataframe, but for consistency with "forecast" v8.5 we now require a matrix with colnames

Characteristics of the input series can cause problems for certain types of models and parameters. For example, stlm models require that the input series be seasonal; furthermore, the data must include at least two seasons of data (i.e. length(y) >= 2 * frequency(y)) for the decomposition to succeed. If this is not the case, hybridModel() will remove the stlm model so an error does not occur. Similarly, nnetar models require that length(y) >= 2 * frequency(y), so these models will be removed if the condition is not satisfied. The ets model does not handle a series well with a seasonal period longer than 24 and will ignore the seasonality. In this case, hybridModel() will also drop the ets model from the ensemble.

Value

An object of class hybridModel. The individual component models are stored inside of the object and can be accessed for all the regular manipulations available in the forecast package.

Author(s)

David Shaub

See Also

forecast.hybridModel, auto.arima, ets, thetam, nnetar, stlm, tbats

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## Not run: 

# Fit an auto.arima, ets, thetam, nnetar, stlm, and tbats model
# on the time series with equal weights
mod1 <- hybridModel(AirPassengers)
plot(forecast(mod1))

# Use an auto.arima, ets, and tbats model with weights
# set by the MASE in-sample errors
mod2 <- hybridModel(AirPassengers, models = "aet",
weights = "insample.errors", errorMethod = "MASE")

# Pass additional arguments to auto.arima() to control its fit
mod3 <- hybridModel(AirPassengers, models = "aens",
a.args = list(max.p = 7, max.q = 7, approximation = FALSE))

# View the component auto.arima() and stlm() models
mod3$auto.arima
mod3$stlm

## End(Not run)

forecastHybrid documentation built on Aug. 28, 2020, 9:08 a.m.