es() - Exponential Smoothing

Ivan Svetunkov

2017-07-02

es() is a part of smooth package. It allows constructing Exponential Smoothing (also known as ETS), selecting the most appropriate one among 30 possible ones, including exogenous variables and many more.

In this vignette we will use data from Mcomp package, so it is advised to install it.

Let’s load the necessary packages:

require(smooth)
require(Mcomp)

You may note that Mcomp depends on forecast package and if you load both forecast and smooth, then you will have a message that forecast() function is masked from the environment. There is nothing to be worried about - smooth uses this function for consistency purposes and has exactly the same original forecast() as in the forecast package. The inclusion of this function in smooth was done only in order not to include forecast in dependencies of the package.

The simplest call of this function is:

es(M3$N2457$x, h=18, holdout=TRUE)
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    40%50%60%70%80%90%100%... Done!
## Time elapsed: 0.85 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.108 0.000 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.414
## Cost function type: MSE; Cost function value: 1268104.714
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1648.418 1649.078 1661.292 
## Forecast errors:
## MPE: 24.1%; Bias: 84.9%; MAPE: 39.3%; SMAPE: 48%
## MASE: 2.883; sMAE: 117.6%; RelMAE: 1.232; sMSE: 234.5%

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. Standard deviation of residuals. The model has multiplicative error term, so as a result the standard deviation is small.
  7. Cost function type and the value of that cost function;
  8. Information criteria for this model;
  9. Forecast errors (because we have set holdout=TRUE).

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

If we need prediction intervals, then we run:

es(M3$N2457$x, h=18, holdout=TRUE, intervals=TRUE)
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    40%50%60%70%80%90%100%... Done!
## Time elapsed: 1.14 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.108 0.000 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.414
## Cost function type: MSE; Cost function value: 1268104.714
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1648.418 1649.078 1661.292 
## 95% parametric prediction intervals were constructed
## 89% of values are in the prediction interval
## Forecast errors:
## MPE: 24.1%; Bias: 84.9%; MAPE: 39.3%; SMAPE: 48%
## MASE: 2.883; sMAE: 117.6%; RelMAE: 1.232; sMSE: 234.5%

Due to multiplicative nature of error term in the model, the intervals are asymmetric. This is the expected behaviour. The other thing to note is that the output now also provides the theoretical width of prediction intervals and its actual coverage.

If we save the model (and let’s say we want it to work silently):

ourModel <- es(M3$N2457$x, h=18, holdout=TRUE, silent="all")

we can then reuse it for different purposes:

es(M3$N2457$x, model=ourModel, h=18, holdout=FALSE, intervals="np", level=0.93)
## Time elapsed: 0.07 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.108 0.000 
## Initial values were provided by user.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.435
## Cost function type: MSE; Cost function value: 1938252.127
## 
## Information criteria:
##      AIC     AICc      BIC 
## 2001.245 2001.795 2014.970 
## 93% nonparametric prediction intervals were constructed

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

modelType(ourModel)
## [1] "MAN"

This handy function, by the way, also works with ets() from forecast package.

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

es(M3$N2457$x, model=modelType(ourModel), h=18, holdout=FALSE, initial=ourModel$initial, silent="graph")
## Time elapsed: 0.02 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.119 0.000 
## Initial values were provided by user.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.435
## Cost function type: MSE; Cost function value: 1937089.528
## 
## Information criteria:
##      AIC     AICc      BIC 
## 2001.176 2001.726 2014.901
es(M3$N2457$x, model=modelType(ourModel), h=18, holdout=FALSE, persistence=ourModel$persistence, silent="graph")
## Time elapsed: 0.02 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.108 0.000 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.435
## Cost function type: MSE; Cost function value: 1937169.382
## 
## Information criteria:
##      AIC     AICc      BIC 
## 2001.181 2001.731 2014.905

or provide some arbitrary values:

es(M3$N2457$x, model=modelType(ourModel), h=18, holdout=FALSE, initial=1500, silent="graph")
## Time elapsed: 0.08 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.117 0.000 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.435
## Cost function type: MSE; Cost function value: 1936550.947
## 
## Information criteria:
##      AIC     AICc      BIC 
## 2001.144 2001.695 2014.869

Using some other parameters may lead to completely different model and forecasts:

es(M3$N2457$x, h=18, holdout=TRUE, cfType="aMSTFE", bounds="a", ic="BIC", intervals=TRUE)
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    100%... Done!
## Time elapsed: 0.23 seconds
## Model estimated: ETS(MNN)
## Persistence vector g:
## alpha 
##  0.08 
## Initial values were optimised.
## 3 parameters were estimated in the process
## Residuals standard deviation: 0.42
## Cost function type: aMSTFE; Cost function value: 246.291
## 
## Information criteria:
##      AIC     AICc      BIC 
## 25551.52 25556.16 25690.55 
## 95% parametric prediction intervals were constructed
## 72% of values are in the prediction interval
## Forecast errors:
## MPE: 33.3%; Bias: 90.4%; MAPE: 43.3%; SMAPE: 56.3%
## MASE: 3.232; sMAE: 131.9%; RelMAE: 1.381; sMSE: 277.6%

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

In order to combine forecasts we need to use “C” letter:

es(M3$N2457$x, model="CCN", h=18, holdout=TRUE, silent="graph")
## Estimation progress:    10%20%30%40%50%60%70%80%90%100%... Done!
## Time elapsed: 0.79 seconds
## Model estimated: ETS(CCN)
## Initial values were optimised.
## Residuals standard deviation: 1408.59
## Cost function type: MSE
## 
## Information criteria:
## Combined AICc 
##      1647.651 
## Forecast errors:
## MPE: 27.8%; Bias: 88.4%; MAPE: 40.5%; SMAPE: 50.8%
## MASE: 3.005; sMAE: 122.6%; RelMAE: 1.284; sMSE: 249.9%

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

es(M3$N2457$x, model=c("ANN","AAN","AAdN","ANA","AAA","AAdA"), h=18, holdout=TRUE, silent="graph")
## Estimation progress:    17%33%50%67%83%100%... Done!
## Time elapsed: 0.5 seconds
## Model estimated: ETS(AAN)
## Persistence vector g:
## alpha  beta 
##     0     0 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 1410.988
## Cost function type: MSE; Cost function value: 1888265.077
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1687.037 1687.697 1699.911 
## Forecast errors:
## MPE: 27.7%; Bias: 88.2%; MAPE: 40.9%; SMAPE: 51.2%
## MASE: 3.022; sMAE: 123.3%; RelMAE: 1.291; sMSE: 251.8%
es(M3$N2457$x, model=c("CCC","ANN","AAN","AAdN","ANA","AAA","AAdA"), h=18, holdout=TRUE, silent="graph")
## Estimation progress:    17%33%50%67%83%100%... Done!
## Time elapsed: 0.51 seconds
## Model estimated: ETS(CCC)
## Initial values were optimised.
## Residuals standard deviation: 1361.192
## Cost function type: MSE
## 
## Information criteria:
## Combined AICc 
##      1688.456 
## Forecast errors:
## MPE: 25.6%; Bias: 86.1%; MAPE: 39.9%; SMAPE: 49.3%
## MASE: 2.939; sMAE: 119.9%; RelMAE: 1.256; sMSE: 241.7%

Now let’s introduce some artificial exogenous variables:

x <- cbind(rnorm(length(M3$N2457$x),50,3),rnorm(length(M3$N2457$x),100,7))

and fit a model with all the exogenous first:

es(M3$N2457$x, model="ZZZ", h=18, holdout=TRUE, xreg=x)
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    100%... Done!
## Time elapsed: 0.38 seconds
## Model estimated: ETSX(MNN)
## Persistence vector g:
## alpha 
##  0.14 
## Initial values were optimised.
## 5 parameters were estimated in the process
## Residuals standard deviation: 0.41
## Xreg coefficients were estimated in a normal style
## Cost function type: MSE; Cost function value: 1241280.429
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1646.345 1647.004 1659.218 
## Forecast errors:
## MPE: 25.5%; Bias: 86.9%; MAPE: 41.4%; SMAPE: 50.7%
## MASE: 2.992; sMAE: 122.1%; RelMAE: 1.278; sMSE: 244.8%

or construct a model with selected exogenous (based on IC):

es(M3$N2457$x, model="ZZZ", h=18, holdout=TRUE, xreg=x, xregDo="select")
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    40%50%60%70%80%90%100%... Done!
## Time elapsed: 0.95 seconds
## Model estimated: ETS(MAN)
## Persistence vector g:
## alpha  beta 
## 0.108 0.000 
## Initial values were optimised.
## 6 parameters were estimated in the process
## Residuals standard deviation: 0.416
## Cost function type: MSE; Cost function value: 1268104.714
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1650.418 1651.352 1665.867 
## Forecast errors:
## MPE: 24.1%; Bias: 84.9%; MAPE: 39.3%; SMAPE: 48%
## MASE: 2.883; sMAE: 117.6%; RelMAE: 1.232; sMSE: 234.5%

or the one with the updated xreg:

ourModel <- es(M3$N2457$x, model="ZZZ", h=18, holdout=TRUE, xreg=x, updateX=TRUE)
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    40%50%60%70%80%90%100%... Done!

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

es(M3$N2457$x, model="ZZZ", h=18, holdout=TRUE, xreg=xregExpander(x), xregDo="select")
## Forming the pool of models based on... ANN, ANA, AAN, Estimation progress:    40%50%60%70%80%90%100%... Done!
## Time elapsed: 2.12 seconds
## Model estimated: ETSX(MAN)
## Persistence vector g:
## alpha  beta 
## 0.094 0.000 
## Initial values were optimised.
## 6 parameters were estimated in the process
## Residuals standard deviation: 0.402
## Xreg coefficients were estimated in a normal style
## Cost function type: MSE; Cost function value: 1182317.991
## 
## Information criteria:
##      AIC     AICc      BIC 
## 1643.624 1644.557 1659.072 
## Forecast errors:
## MPE: 22.5%; Bias: 82%; MAPE: 42.4%; SMAPE: 50.2%
## MASE: 2.952; sMAE: 120.4%; RelMAE: 1.261; sMSE: 231.3%

If we are confused about the type of estimated model, the function formula() will help us:

formula(ourModel)
## [1] "y[t] = l[t-1] * b[t-1] * exp(a1[t-1] * x1[t] + a2[t-1] * x2[t]) * e[t]"