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:
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.