Learn R Programming

smooth (version 2.4.7)

gum: Generalised Univariate Model

Description

Function constructs Generalised Univariate Model, estimating matrices F, w, vector g and initial parameters.

Usage

gum(data, orders = c(1, 1), lags = c(1, frequency(data)),
  type = c("A", "M"), persistence = NULL, transition = NULL,
  measurement = NULL, initial = c("optimal", "backcasting"),
  ic = c("AICc", "AIC", "BIC", "BICc"), cfType = c("MSE", "MAE", "HAM",
  "MSEh", "TMSE", "GTMSE", "MSCE"), h = 10, holdout = FALSE,
  cumulative = FALSE, intervals = c("none", "parametric",
  "semiparametric", "nonparametric"), level = 0.95,
  intermittent = c("none", "auto", "fixed", "interval", "probability",
  "sba", "logistic"), imodel = "MNN", bounds = c("restricted",
  "admissible", "none"), silent = c("all", "graph", "legend", "output",
  "none"), xreg = NULL, xregDo = c("use", "select"), initialX = NULL,
  updateX = FALSE, persistenceX = NULL, transitionX = NULL, ...)

ges(...)

Arguments

data

Vector or ts object, containing data needed to be forecasted.

orders

Order of the model. Specified as vector of number of states with different lags. For example, orders=c(1,1) means that there are two states: one of the first lag type, the second of the second type.

lags

Defines lags for the corresponding orders. If, for example, orders=c(1,1) and lags are defined as lags=c(1,12), then the model will have two states: the first will have lag 1 and the second will have lag 12. The length of lags must correspond to the length of orders.

type

Type of model. Can either be "A" - additive - or "M" - multiplicative. The latter means that the GUM is fitted on log-transformed data.

persistence

Persistence vector \(g\), containing smoothing parameters. If NULL, then estimated.

transition

Transition matrix \(F\). Can be provided as a vector. Matrix will be formed using the default matrix(transition,nc,nc), where nc is the number of components in state vector. If NULL, then estimated.

measurement

Measurement vector \(w\). If NULL, then 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.

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), TMSE - Trace Mean Squared Error, GTMSE - Geometric Trace Mean Squared Error, MSEh - optimisation using only h-steps ahead error, MSCE - Mean Squared Cumulative 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, aTMSE and aGTMSE. These can be useful in cases of small samples.

Finally, just for fun the absolute and half analogues of multistep estimators are available: MAEh, TMAE, GTMAE, MACE, TMAE, HAMh, THAM, GTHAM, CHAM.

h

Length of forecasting horizon.

holdout

If TRUE, holdout sample of size h is taken from the end of the data.

cumulative

If TRUE, then the cumulative forecast and prediction intervals are produced instead of the normal ones. This is useful for inventory control systems.

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. The former means that parametric intervals are constructed, while the latter is equivalent to none. If the forecasts of the models were combined, then the intervals are combined quantile-wise (Lichtendahl et al., 2013).

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 occurrences; 3. interval, Interval-based model, underlying Croston, 1972 method; 4. probability, Probability-based model, underlying 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. 7. "logistic" - the probability is estimated based on logistic regression model principles.

imodel

Type of ETS model used for the modelling of the time varying probability. Object of the class "iss" can be provided here, and its parameters would be used in iETS model.

bounds

What type of bounds to use in the model estimation. 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, while "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 interactions 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 parameter model can accept a previously estimated GUM model and use all its parameters. FI=TRUE will make the function produce Fisher Information matrix, which then can be used to calculated variances of parameters of the model. You can also pass two parameters to the optimiser: 1. maxeval - maximum number of evaluations to carry on; 2. xtol_rel - the precision of the optimiser. The default values used in es() are maxeval=5000 and xtol_rel=1e-8. You can read more about these parameters in the documentation of nloptr function.

Value

Object of class "smooth" is returned. It contains:

  • model - name of the estimated model.

  • timeElapsed - time elapsed for the construction of the model.

  • states - matrix of fuzzy components of GUM, where rows correspond to time and cols to states.

  • initialType - Type of the initial values used.

  • initial - initial values of state vector (extracted from states).

  • nParam - table with the number of estimated / provided parameters. If a previous model was reused, then its initials are reused and the number of provided parameters will take this into account.

  • measurement - matrix w.

  • transition - matrix F.

  • persistence - persistence vector. This is the place, where smoothing parameters live.

  • fitted - fitted values.

  • forecast - point forecast.

  • 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 - the residuals of the estimated model.

  • errors - matrix of 1 to h steps ahead errors.

  • s2 - variance of the residuals (taking degrees of freedom into account).

  • intervals - type of intervals asked by user.

  • level - confidence level for intervals.

  • cumulative - whether the produced forecast was cumulative or not.

  • actuals - original data.

  • holdout - holdout part of the original data.

  • imodel - model of the class "iss" if intermittent model was estimated. If the model is non-intermittent, then imodel is NULL.

  • 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, BIC and BICc.

  • 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 variable 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.

Details

The function estimates 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} + \epsilon_{t})$$

$$v_{t} = F v_{t-l} + g \epsilon_{t}$$

$$a_{t} = F_{X} a_{t-1} + g_{X} \epsilon_{t} / x_{t}$$

Where \(o_{t}\) is the Bernoulli distributed random variable (in case of normal data equal to 1), \(v_{t}\) is the state vector (defined using orders) and \(l\) is the vector of lags, \(x_t\) is the vector of exogenous parameters. \(w\) is the measurement vector, \(F\) is the transition matrix, \(g\) is the persistence vector, \(a_t\) is the vector of parameters for exogenous variables, \(F_{X}\) is the transitionX matrix and \(g_{X}\) is the persistenceX matrix. Finally, \(\epsilon_{t}\) is the error term.

References

  • Svetunkov I. (2017). Statistical models underlying functions of 'smooth' package for R. Working Paper of Department of Management Science, Lancaster University 2017:1, 1-52.

  • 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.

  • Lichtendahl Kenneth C., Jr., Grushka-Cockayne Yael, Winkler Robert L., (2013) Is It Better to Average Probabilities or Quantiles? Management Science 59(7):1594-1611. DOI: [10.1287/mnsc.1120.1667](https://doi.org/10.1287/mnsc.1120.1667)

See Also

ets, es, ces, sim.es

Examples

Run this code
# NOT RUN {
# Something simple:
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,bounds="a",intervals="p")

# A more complicated model with seasonality
# }
# NOT RUN {
ourModel <- gum(rnorm(118,100,3),orders=c(2,1),lags=c(1,4),h=18,holdout=TRUE)
# }
# NOT RUN {
# Redo previous model on a new data and produce prediction intervals
# }
# NOT RUN {
gum(rnorm(118,100,3),model=ourModel,h=18,intervals="sp")
# }
# NOT RUN {
# Produce something crazy with optimal initials (not recommended)
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1,1,1),lags=c(1,3,5),h=18,holdout=TRUE,initial="o")
# }
# NOT RUN {
# Simpler model estiamted using trace forecast error cost function and its analytical analogue
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,bounds="n",cfType="TMSE")
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,bounds="n",cfType="aTMSE")
# }
# NOT RUN {
# Introduce exogenous variables
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,xreg=c(1:118))
# }
# NOT RUN {
# Ask for their update
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,xreg=c(1:118),updateX=TRUE)
# }
# NOT RUN {
# Do the same but now let's shrink parameters...
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,xreg=c(1:118),updateX=TRUE,cfType="TMSE")
ourModel <- gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,cfType="aTMSE")
# }
# NOT RUN {
# Or select the most appropriate one
# }
# NOT RUN {
gum(rnorm(118,100,3),orders=c(1),lags=c(1),h=18,holdout=TRUE,xreg=c(1:118),xregDo="s")

summary(ourModel)
forecast(ourModel)
plot(forecast(ourModel))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab