The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
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:
The simplest call for the es()
function is:
## Forming the pool of models based on... ANN , AAN , Estimation progress: 33 %44 %56 %67 %78 %89 %100 %... Done!
## Time elapsed: 0.2 seconds
## Model estimated using es() function: ETS(AMdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 237.8418
## Persistence vector g:
## alpha beta
## 0.8791 0.3899
## Damping parameter: 0.8236
## Sample size: 138
## Number of estimated parameters: 6
## Number of degrees of freedom: 132
## Information criteria:
## AIC AICc BIC BICc
## 487.6836 488.3248 505.2471 506.8268
##
## Forecast errors:
## ME: 2.757; MAE: 2.92; RMSE: 3.592
## sCE: 14.556%; Asymmetry: 87.1%; sMAE: 1.285%; sMSE: 0.025%
## MASE: 2.452; RMSSE: 2.341; rMAE: 0.942; rRMSE: 0.937
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:
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:
The same model can be reused for different purposes, for example to produce forecasts based on newly available data:
## Time elapsed: 0 seconds
## Model estimated using es() function: ETS(AMdN)
## With provided initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 255.6153
## Persistence vector g:
## alpha beta
## 0.8791 0.3899
## Damping parameter: 0.8236
## Sample size: 150
## Number of estimated parameters: 1
## Number of degrees of freedom: 149
## Information criteria:
## AIC AICc BIC BICc
## 513.2307 513.2577 516.2413 516.3090
We can also extract the type of model in order to reuse it later:
## [1] "AMdN"
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:
## Time Series:
## Start = 1
## End = 138
## Frequency = 1
## [1] 200.1 199.5 199.4 198.9 199.0 200.2 198.6 200.0 200.3 201.2 201.6 201.5
## [13] 201.5 203.5 204.9 207.1 210.5 210.5 209.8 208.8 209.5 213.2 213.7 215.1
## [25] 218.7 219.8 220.5 223.8 222.8 223.8 221.7 222.3 220.8 219.4 220.1 220.6
## [37] 218.9 217.8 217.7 215.0 215.3 215.9 216.7 216.7 217.7 218.7 222.9 224.9
## [49] 222.2 220.7 220.0 218.7 217.0 215.9 215.8 214.1 212.3 213.9 214.6 213.6
## [61] 212.1 211.4 213.1 212.9 213.3 211.5 212.3 213.0 211.0 210.7 210.1 211.4
## [73] 210.0 209.7 208.8 208.8 208.8 210.6 211.9 212.8 212.5 214.8 215.3 217.5
## [85] 218.8 220.7 222.2 226.7 228.4 233.2 235.7 237.1 240.6 243.8 245.3 246.0
## [97] 246.3 247.7 247.6 247.8 249.4 249.0 249.9 250.5 251.5 249.0 247.6 248.8
## [109] 250.4 250.7 253.0 253.7 255.0 256.2 256.0 257.4 260.4 260.0 261.3 260.4
## [121] 261.6 260.8 259.8 259.0 258.9 257.4 257.7 257.9 257.4 257.3 257.6 258.9
## [133] 257.8 257.7 257.2 257.5 256.8 257.5
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)
## Time elapsed: 0.02 seconds
## Model estimated using es() function: ETS(AMdN)
## With provided initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 255.2442
## Persistence vector g:
## alpha beta
## 0.9649 0.2931
## Damping parameter: 0.8694
## Sample size: 150
## Number of estimated parameters: 4
## Number of degrees of freedom: 146
## Information criteria:
## AIC AICc BIC BICc
## 518.4884 518.7642 530.5309 531.2220
# Provided persistence
es(BJsales, model=modelType(ourModel),
h=12, holdout=FALSE,
persistence=ourModel$persistence)
## Time elapsed: 0.02 seconds
## Model estimated using es() function: ETS(AMdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 255.5961
## Persistence vector g:
## alpha beta
## 0.8791 0.3899
## Damping parameter: 0.8228
## Sample size: 150
## Number of estimated parameters: 4
## Number of degrees of freedom: 146
## Information criteria:
## AIC AICc BIC BICc
## 519.1921 519.4680 531.2347 531.9258
or provide some arbitrary values:
## Time elapsed: 0.03 seconds
## Model estimated using es() function: ETS(AMdN)
## With provided initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 255.3623
## Persistence vector g:
## alpha beta
## 0.9989 0.2616
## Damping parameter: 0.886
## Sample size: 150
## Number of estimated parameters: 5
## Number of degrees of freedom: 145
## Information criteria:
## AIC AICc BIC BICc
## 520.7246 521.1412 535.7777 536.8216
Using some other parameters may lead to completely different model and forecasts (see discussion of the additional parameters in the online textbook about ADAM):
## Time elapsed: 0.1 seconds
## Model estimated using es() function: ETS(ANN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: MSEh; Loss function value: 117.0916
## Persistence vector g:
## alpha
## 1.6067
##
## Sample size: 138
## Number of estimated parameters: 2
## Number of degrees of freedom: 136
## Information criteria:
## AIC AICc BIC BICc
## 1052.915 1053.004 1058.770 1058.988
##
## Forecast errors:
## ME: 2.086; MAE: 2.784; RMSE: 3.183
## sCE: 11.013%; Asymmetry: 66.4%; sMAE: 1.225%; sMSE: 0.02%
## MASE: 2.337; RMSSE: 2.075; rMAE: 0.898; rRMSE: 0.831
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:
## Time elapsed: 0.22 seconds
## Model estimated: ETS(CCN)
## Loss function type: likelihood
##
## Number of models combined: 10
## Sample size: 138
## Average number of estimated parameters: 6.3675
## Average number of degrees of freedom: 131.6325
##
## Forecast errors:
## ME: 2.787; MAE: 2.945; RMSE: 3.624
## sCE: 14.714%; sMAE: 1.296%; sMSE: 0.025%
## MASE: 2.472; RMSSE: 2.362; rMAE: 0.95; rRMSE: 0.946
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)
## Time elapsed: 0.1 seconds
## Model estimated using es() function: ETS(AAdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 238.029
## Persistence vector g:
## alpha beta
## 0.8626 0.4138
## Damping parameter: 0.8159
## Sample size: 138
## Number of estimated parameters: 6
## Number of degrees of freedom: 132
## Information criteria:
## AIC AICc BIC BICc
## 488.0580 488.6992 505.6215 507.2013
##
## Forecast errors:
## ME: 2.745; MAE: 2.91; RMSE: 3.578
## sCE: 14.488%; Asymmetry: 87%; sMAE: 1.28%; sMSE: 0.025%
## MASE: 2.443; RMSSE: 2.332; rMAE: 0.939; rRMSE: 0.934
# Combine the pool of models
es(BJsales, model=c("CCC","ANN","AAN","AAdN","MNN","MAN","MAdN"),
h=12, holdout=TRUE)
## Time elapsed: 0.1 seconds
## Model estimated: ETS(CCN)
## Loss function type: likelihood
##
## Number of models combined: 6
## Sample size: 138
## Average number of estimated parameters: 6.678
## Average number of degrees of freedom: 131.322
##
## Forecast errors:
## ME: 2.789; MAE: 2.947; RMSE: 3.626
## sCE: 14.723%; sMAE: 1.296%; sMSE: 0.025%
## MASE: 2.474; RMSSE: 2.364; rMAE: 0.951; rRMSE: 0.946
Now we introduce explanatory variable in ETS:
and fit an ETSX model with the exogenous variable first:
## Time elapsed: 0.86 seconds
## Model estimated using es() function: ETSX(AMdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 237.4933
## Persistence vector g (excluding xreg):
## alpha beta
## 0.9495 0.2914
## Damping parameter: 0.8762
## Sample size: 138
## Number of estimated parameters: 7
## Number of degrees of freedom: 131
## Information criteria:
## AIC AICc BIC BICc
## 488.9866 489.8482 509.4774 511.5999
##
## Forecast errors:
## ME: 2.875; MAE: 2.999; RMSE: 3.701
## sCE: 15.175%; Asymmetry: 89.9%; sMAE: 1.319%; sMSE: 0.027%
## MASE: 2.517; RMSSE: 2.412; rMAE: 0.967; rRMSE: 0.966
If we want to check if lagged x can be used for forecasting purposes,
we can use xregExpander()
function from
greybox
package:
## Time elapsed: 1.47 seconds
## Model estimated using es() function: ETSX(AMdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 236.8469
## Persistence vector g (excluding xreg):
## alpha beta
## 0.8910 0.3343
## Damping parameter: 0.873
## Sample size: 138
## Number of estimated parameters: 9
## Number of degrees of freedom: 129
## Information criteria:
## AIC AICc BIC BICc
## 491.6939 493.1001 518.0392 521.5037
##
## Forecast errors:
## ME: 2.666; MAE: 2.943; RMSE: 3.557
## sCE: 14.075%; Asymmetry: 80.7%; sMAE: 1.295%; sMSE: 0.024%
## MASE: 2.471; RMSSE: 2.319; rMAE: 0.949; rRMSE: 0.928
We can also construct a model with selected exogenous (based on IC):
## Time elapsed: 1.02 seconds
## Model estimated using es() function: ETS(AMdN)
## With optimal initialisation
## Distribution assumed in the model: Normal
## Loss function type: likelihood; Loss function value: 237.8418
## Persistence vector g:
## alpha beta
## 0.8791 0.3899
## Damping parameter: 0.8236
## Sample size: 138
## Number of estimated parameters: 6
## Number of degrees of freedom: 132
## Information criteria:
## AIC AICc BIC BICc
## 487.6836 488.3248 505.2471 506.8268
##
## Forecast errors:
## ME: 2.757; MAE: 2.92; RMSE: 3.592
## sCE: 14.556%; Asymmetry: 87.1%; sMAE: 1.285%; sMSE: 0.025%
## MASE: 2.452; RMSSE: 2.341; rMAE: 0.942; rRMSE: 0.937
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:
This command has taken the data, split it into in-sample and holdout and produced the forecast of appropriate length to the holdout.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.