Learn R Programming

smooth (version 1.9.0)

es: Exponential Smoothing in SSOE state-space model

Description

Function constructs ETS model and returns forecast, fitted values, errors and matrix of states.

Usage

es(data, model = "ZZZ", persistence = NULL, phi = NULL,
  initial = c("optimal", "backcasting"), initialSeason = NULL,
  ic = c("AICc", "AIC", "BIC"), cfType = c("MSE", "MAE", "HAM", "MLSTFE",
  "MSTFE", "MSEh"), h = 10, holdout = FALSE, intervals = c("none",
  "parametric", "semiparametric", "nonparametric"), level = 0.95,
  intermittent = c("none", "auto", "fixed", "croston", "tsb", "sba"),
  bounds = c("usual", "admissible", "none"), silent = c("none", "all",
  "graph", "legend", "output"), xreg = NULL, xregDo = c("use", "select"),
  initialX = NULL, updateX = FALSE, persistenceX = NULL,
  transitionX = NULL, ...)

Arguments

data
Vector or ts object, containing data needed to be forecasted.
model
The type of ETS model. Can consist of 3 or 4 chars: ANN, AAN, AAdN, AAA, AAdA, MAdM etc. ZZZ means that the model will be selected based on the chosen information criteria type. Models pool can be restricted with additive only components. This is done via model="XXX". For example, making selection between models with none / additive / damped additive trend component only (i.e. excluding multiplicative trend) can be done with model="ZXZ". Furthermore, selection between multiplicative models (excluding additive components) is regulated using model="YYY". This can be useful for positive data with low values (for example, slow moving products). Finally, if model="CCC", then all the models are estimated and combination of their forecasts using AIC weights is produced (Kolassa, 2011). This can also be regulated. For example, model="CCN" will combine forecasts of all non-seasonal models and model="CXY" will combine forecasts of all the models with non-multiplicative trend and non-additive seasonality with either additive or multiplicative error. not sure why anyone whould need this thing, but it is available.

The parameter model can also be a vector of names of models for a finer tuning (pool of models). For example, model=c("ANN","AAA") will estimate only two models and select the best of them.

Also model can accept a previously estimated ES model and use all its parameters.

Keep in mind that model selection with "Z" components uses Branch and Bound algorithm and may skip some models that could have slightly smaller information criteria.

persistence
Persistence vector \(g\), containing smoothing parameters. If NULL, then estimated.
phi
Value of damping parameter. If NULL then it is estimated.
initial
Can be either character or a vector of initial states. If it is character, then it can be "optimal", meaning that the initial states are optimised, or "backcasting", meaning that the initials are produced using backcasting procedure (advised for data with high frequency). If character, then initialSeason will be estimated in the way defined by initial.
initialSeason
Vector of initial values for seasonal components. If NULL, they are estimated during optimisation.
ic
The information criterion used in the model selection procedure.
cfType
Type of Cost Function used in optimization. cfType can be: MSE (Mean Squared Error), MAE (Mean Absolute Error), HAM (Half Absolute Moment), MLSTFE - Mean Log Squared Trace Forecast Error, MSTFE - Mean Squared Trace Forecast Error and MSEh - optimisation using only h-steps ahead error. If cfType!="MSE", then likelihood and model selection is done based on equivalent MSE. Model selection in this cases becomes not optimal.

There are also available analytical approximations for multistep functions: aMSEh, aMSTFE and aMLSTFE. These can be useful in cases of small samples.

h
Length of forecasting horizon.
holdout
If TRUE, holdout sample of size h is taken from the end of the data.
intervals
Type of intervals to construct. This can be:

  • none, aka n - do not produce prediction intervals.
  • parametric, p - use state-space structure of ETS. In case of mixed models this is done using simulations, which may take longer time than for the pure additive and pure multiplicative models.
  • semiparametric, sp - intervals based on covariance matrix of 1 to h steps ahead errors and assumption of normal / log-normal distribution (depending on error type).
  • nonparametric, np - intervals based on values from a quantile regression on error matrix (see Taylor and Bunn, 1999). The model used in this process is e[j] = a j^b, where j=1,..,h.

The parameter also accepts TRUE and FALSE. Former means that parametric intervals are constructed, while latter is equivalent to none.

level
Confidence level. Defines width of prediction interval.
intermittent
Defines type of intermittent model used. Can be: 1. none, meaning that the data should be considered as non-intermittent; 2. fixed, taking into account constant Bernoulli distribution of demand occurancies; 3. croston, based on Croston, 1972 method with SBA correction; 4. tsb, based on Teunter et al., 2011 method. 5. auto - automatic selection of intermittency type based on information criteria. The first letter can be used instead. 6. "sba" - Syntetos-Boylan Approximation for Croston's method (bias correction) discussed in Syntetos and Boylan, 2005.
bounds
What type of bounds to use for smoothing parameters ("admissible" or "usual"). The first letter can be used instead of the whole word.
silent
If silent="none", then nothing is silent, everything is printed out and drawn. silent="all" means that nothing is produced or drawn (except for warnings). In case of silent="graph", no graph is produced. If silent="legend", then legend of the graph is skipped. And finally silent="output" means that nothing is printed out in the console, but the graph is produced. silent also accepts TRUE and FALSE. In this case silent=TRUE is equivalent to silent="all", while silent=FALSE is equivalent to silent="none". The parameter also accepts first letter of words ("n", "a", "g", "l", "o").
xreg
Vector (either numeric or time series) or matrix (or data.frame) of exogenous variables that should be included in the model. If matrix included than columns should contain variables and rows - observations. Note that xreg should have number of observations equal either to in-sample or to the whole series. If the number of observations in xreg is equal to in-sample, then values for the holdout sample are produced using es function.
xregDo
Variable defines what to do with the provided xreg: "use" means that all of the data should be used, whilie "select" means that a selection using ic should be done. "combine" will be available at some point in future...
initialX
Vector of initial parameters for exogenous variables. Ignored if xreg is NULL.
updateX
If TRUE, transition matrix for exogenous variables is estimated, introducing non-linear interractions between parameters. Prerequisite - non-NULL xreg.
persistenceX
Persistence vector \(g_X\), containing smoothing parameters for exogenous variables. If NULL, then estimated. Prerequisite - non-NULL xreg.
transitionX
Transition matrix \(F_x\) for exogenous variables. Can be provided as a vector. Matrix will be formed using the default matrix(transition,nc,nc), where nc is number of components in state vector. If NULL, then estimated. Prerequisite - non-NULL xreg.
...
Other non-documented parameters. For example FI=TRUE will make the function also produce Fisher Information matrix, which then can be used to calculated variances of smoothing parameters and initial states of the model. Parameters C, CLower and CUpper can be passed via ellipsis as well. In this case they will be used for optimisation. C sets the initial values before the optimisation, CLower and CUpper define lower and upper bounds for the search inside of the specified bounds. These values should have exactly the length equal to the number of parameters to estimate.

Value

Object of class "smooth" is returned. It contains the list of the following values for clasical ETS models:
  • model - type of constructed model.
  • formula - mathematical formula, describing interations between components of es() and exogenous variables.
  • timeElapsed - time elapsed for the construction of the model.
  • states - matrix of the components of ETS.
  • persistence - persistence vector. This is the place, where smoothing parameters live.
  • phi - value of damping parameter.
  • initialType - Type of initial values used.
  • initial - intial values of the state vector (non-seasonal).
  • initialSeason - intial values of the seasonal part of state vector.
  • nParam - number of estimated parameters.
  • fitted - fitted values of ETS.
  • forecast - point forecast of ETS.
  • lower - lower bound of prediction interval. When intervals="none" then NA is returned.
  • upper - higher bound of prediction interval. When intervals="none" then NA is returned.
  • residuals - residuals of the estimated model.
  • errors - trace forecast in-sample errors, returned as a matrix. In the case of trace forecasts this is the matrix used in optimisation. In non-trace estimations it is returned just for the information.
  • s2 - variance of the residuals (taking degrees of freedom into account).
  • intervals - type of intervals asked by user.
  • level - confidence level for intervals.
  • actuals - original data.
  • holdout - holdout part of the original data.
  • iprob - fitted and forecasted values of the probability of demand occurrence.
  • intermittent - type of intermittent model fitted to the data.
  • xreg - provided vector or matrix of exogenous variables. If xregDo="s", then this value will contain only selected exogenous variables.
  • updateX - boolean, defining, if the states of exogenous variables were estimated as well.
  • initialX - initial values for parameters of exogenous variables.
  • persistenceX - persistence vector g for exogenous variables.
  • transitionX - transition matrix F for exogenous variables.
  • ICs - values of information criteria of the model. Includes AIC, AICc and BIC.
  • logLik - log-likelihood of the function.
  • cf - cost function value.
  • cfType - type of cost function used in the estimation.
  • FI - Fisher Information. Equal to NULL if FI=FALSE or when FI is not provided at all.
  • accuracy - vector of accuracy measures for the holdout sample. In case of non-intermittent data includes: MPE, MAPE, SMAPE, MASE, sMAE, RelMAE, sMSE and Bias coefficient (based on complex numbers). In case of intermittent data the set of errors will be: sMSE, sPIS, sCE (scaled cumulative error) and Bias coefficient. This is available only when holdout=TRUE.
If combination of forecasts is produced (using model="CCC"), then a shorter list of values is returned:
  • model,
  • timeElapsed,
  • initialType,
  • fitted,
  • forecast,
  • lower,
  • upper,
  • residuals,
  • s2 - variance of additive error of combined one-step-ahead forecasts,
  • intervals,
  • level,
  • actuals,
  • holdout,
  • iprob,
  • intermittent,
  • ICs - combined ic,
  • ICw - ic weights used in the combination,
  • cfType,
  • xreg,
  • accuracy.

Details

Function estimates ETS in a form of the Single Source of Error State-space model of the following type: \(y_[t] = o_[t] (w(v_[t-l]) + x_t a_[t-1] + r(v_[t-l]) \epsilon_[t])\) \(v_[t] = f(v_[t-l]) + g(v_[t-l]) \epsilon_[t]\) \(a_[t] = F_[X] a_[t-1] + g_[X] \epsilon_[t] / x_[t]\) Where \(o_[t]\) is Bernoulli distributed random variable (in case of normal data it equals to 1 for all observations), \(v_[t]\) is a state vector and \(l\) is a vector of lags, \(x_t\) vector of exogenous parameters. w(.) is measurement function, r(.) is an error function, f(.) is transition function and g(.) is persistence function. For the details see Hyndman et al.(2008).

References

  • Snyder, R. D., 1985. Recursive Estimation of Dynamic Linear Models. Journal of the Royal Statistical Society, Series B (Methodological) 47 (2), 272-276.
  • Hyndman, R.J., Koehler, A.B., Ord, J.K., and Snyder, R.D. (2008) Forecasting with exponential smoothing: the state space approach, Springer-Verlag. http://www.exponentialsmoothing.net.
  • Teunter R., Syntetos A., Babai Z. (2011). Intermittent demand: Linking forecasting to inventory obsolescence. European Journal of Operational Research, 214, 606-615.
  • Croston, J. (1972) Forecasting and stock control for intermittent demands. Operational Research Quarterly, 23(3), 289-303.
  • Syntetos, A., Boylan J. (2005) The accuracy of intermittent demand estimates. International Journal of Forecasting, 21(2), 303-314.
  • Kolassa, S. (2011) Combining exponential smoothing forecasts using Akaike weights. International Journal of Forecasting, 27, pp 238 - 251.
  • Taylor, J.W. and Bunn, D.W. (1999) A Quantile Regression Approach to Generating Prediction Intervals. Management Science, Vol 45, No 2, pp 225-237.

See Also

ets, forecast, ts, sim.es

Examples

Run this code

library(Mcomp)

# See how holdout and trace parameters influence the forecast
es(M3$N1245$x,model="AAdN",h=8,holdout=FALSE,cfType="MSE")
## Not run: es(M3$N2568$x,model="MAM",h=18,holdout=TRUE,cfType="MSTFE")

# Model selection example
es(M3$N1245$x,model="ZZN",ic="AIC",h=8,holdout=FALSE,bounds="a")

# Model selection. Compare AICc of these two models:
## Not run: ------------------------------------
# es(M3$N1683$x,"ZZZ",h=10,holdout=TRUE)
# es(M3$N1683$x,"MAdM",h=10,holdout=TRUE)
## ---------------------------------------------

# Model selection, excluding multiplicative trend
## Not run: es(M3$N1245$x,model="ZXZ",h=8,holdout=TRUE)

# Combination example
## Not run: es(M3$N1245$x,model="CCN",h=8,holdout=TRUE)

# Model selection using a specified pool of models
ourModel <- es(M3$N1587$x,model=c("ANN","AAM","AMdA"),h=18)

# Redo previous model and produce prediction intervals
es(M3$N1587$x,model=ourModel,h=18,intervals="p")

# Semiparametric intervals example
## Not run: es(M3$N1587$x,h=18,holdout=TRUE,intervals="sp")

# Exogenous variables in ETS example
## Not run: ------------------------------------
# x <- cbind(c(rep(0,25),1,rep(0,43)),c(rep(0,10),1,rep(0,58)))
# y <- ts(c(M3$N1457$x,M3$N1457$xx),frequency=12)
# es(y,h=18,holdout=TRUE,xreg=x,cfType="aMSTFE",intervals="np")
# ourModel <- es(ts(c(M3$N1457$x,M3$N1457$xx),frequency=12),h=18,holdout=TRUE,xreg=x,updateX=TRUE)
## ---------------------------------------------

# This will be the same model as in previous line but estimated on new portion of data
## Not run: es(ts(c(M3$N1457$x,M3$N1457$xx),frequency=12),model=ourModel,h=18,holdout=FALSE)

# Intermittent data example
x <- rpois(100,0.2)
# Croston's method with the best ETS for demand sizes
es(x,"ZZN",intermittent="croston")
# TSB based on iETS(M,N,N)
es(x,"MNN",intermittent="tsb")
# Constant probability based on iETS(M,N,N)
es(x,"MNN",intermittent="fixed")
# Best type of intermittent model based on iETS(Z,Z,N)
ourModel <- es(x,"ZZN",intermittent="auto")

summary(ourModel)
forecast(ourModel)
plot(forecast(ourModel))

Run the code above in your browser using DataLab