es() - Exponential Smoothing

knitr::opts_chunk$set(fig.width=6, fig.height=4, fig.path='Figs/', fig.show='hold',
                      warning=FALSE, message=FALSE)

es() is a part of smooth package and is a wrapper for the ADAM function with distribution="dnorm". It implements Exponential Smoothing in the ETS form, selecting the most appropriate model among 30 possible ones.

We will use some of the functions of the greybox package in this vignette for demonstrational purposes.

Let's load the necessary packages:

require(smooth)
require(greybox)

The simplest call for the es() function is:

ourModel <- es(BJsales, h=12, holdout=TRUE, silent=FALSE)
ourModel

In this case function uses branch and bound algorithm to form a pool of models to check and after that constructs a model with the lowest information criterion. As we can see, it also produces an output with brief information about the model, which contains:

  1. How much time was elapsed for the model construction;
  2. What type of ETS was selected;
  3. Values of persistence vector (smoothing parameters);
  4. What type of initialisation was used;
  5. How many parameters were estimated (standard deviation is included);
  6. Cost function type and the value of that cost function;
  7. Information criteria for this model;
  8. Forecast errors (because we have set holdout=TRUE).

The function has also produced a graph with actual values, fitted values and point forecasts.

If we need prediction interval, then we can use the forecast() method:

plot(forecast(ourModel, h=12, interval="prediction"))

The same model can be reused for different purposes, for example to produce forecasts based on newly available data:

es(BJsales, model=ourModel, h=12, holdout=FALSE)

We can also extract the type of model in order to reuse it later:

modelType(ourModel)

This handy function also works with ets() from forecast package.

If we need actual values from the model, we can use actuals() method from greybox package:

actuals(ourModel)

We can also use persistence or initials only from the model to construct the other one:

# Provided initials
es(BJsales, model=modelType(ourModel),
   h=12, holdout=FALSE,
   initial=ourModel$initial)
# Provided persistence
es(BJsales, model=modelType(ourModel),
   h=12, holdout=FALSE,
   persistence=ourModel$persistence)

or provide some arbitrary values:

es(BJsales, model=modelType(ourModel),
   h=12, holdout=FALSE,
   initial=200)

Using some other parameters may lead to completely different model and forecasts (see discussion of the additional parameters in the online textbook about ADAM):

es(BJsales, h=12, holdout=TRUE, loss="MSEh", bounds="a", ic="BIC")

You can play around with all the available parameters to see what's their effect on the final model.

In order to combine forecasts we need to use "C" letter:

es(BJsales, model="CCN", h=12, holdout=TRUE)

Model selection from a specified pool and forecasts combination are called using respectively:

# Select the best model in the pool
es(BJsales, model=c("ANN","AAN","AAdN","MNN","MAN","MAdN"),
   h=12, holdout=TRUE)
# Combine the pool of models
es(BJsales, model=c("CCC","ANN","AAN","AAdN","MNN","MAN","MAdN"),
   h=12, holdout=TRUE)

Now we introduce explanatory variable in ETS:

x <- BJsales.lead

and fit an ETSX model with the exogenous variable first:

es(BJsales, model="ZZZ", h=12, holdout=TRUE,
   xreg=x)

If we want to check if lagged x can be used for forecasting purposes, we can use xregExpander() function from greybox package:

es(BJsales, model="ZZZ", h=12, holdout=TRUE,
   xreg=xregExpander(x), regressors="use")

We can also construct a model with selected exogenous (based on IC):

es(BJsales, model="ZZZ", h=12, holdout=TRUE,
   xreg=xregExpander(x), regressors="select")

Finally, if you work with M or M3 data, and need to test a function on a specific time series, you can use the following simplified call:

es(Mcomp::M3$N2457, silent=FALSE)

This command has taken the data, split it into in-sample and holdout and produced the forecast of appropriate length to the holdout.



Try the smooth package in your browser

Any scripts or data that you put into this service are public.

smooth documentation built on Sept. 17, 2023, 9:06 a.m.