Learn R Programming

smooth (version 1.9.0)

sma: Simple Moving Average

Description

Function constructs State-Space simple moving average of predefined order

Usage

sma(data, order = NULL, ic = c("AICc", "AIC", "BIC"), h = 10,
  holdout = FALSE, intervals = c("none", "parametric", "semiparametric",
  "nonparametric"), level = 0.95, silent = c("none", "all", "graph",
  "legend", "output"), ...)

Arguments

data
Vector or ts object, containing data needed to be forecasted.
order
Order of simple moving average. If NULL, then it is selected automatically using information criteria.
ic
The information criterion used in the model selection procedure.
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.
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").
...
Other non-documented parameters. For example parameter model can accept a previously estimated SMA model and use its parameters.

Value

Object of class "smooth" is returned. It contains the list of the following values:
  • model - the name of the estimated model.
  • timeElapsed - time elapsed for the construction of the model.
  • states - the matrix of the fuzzy components of ssarima, where rows correspond to time and cols to states.
  • transition - matrix F.
  • persistence - the persistence vector. This is the place, where smoothing parameters live.
  • order - order of moving average.
  • initialType - Type of initial values used.
  • nParam - number of estimated parameters.
  • fitted - the fitted values of ETS.
  • forecast - the point forecast of ETS.
  • lower - the lower bound of prediction interval. When intervals=FALSE then NA is returned.
  • upper - the higher bound of prediction interval. When intervals=FALSE then NA is returned.
  • residuals - the residuals of the estimated model.
  • errors - The 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.
  • actuals - the original data.
  • holdout - the holdout part of the original data.
  • 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.
  • 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 constructs AR model in the Single Source of Error State-space form based on the idea that: \(y_{t} = \frac{1}{n} \sum_{j=1}^n y_{t-j}\) which is AR(n) process, that can be modelled using: \(y_{t} = w' v_{t-1} + \epsilon_{t}\) \(v_{t} = F v_{t-1} + g \epsilon_{t}\) Where \(v_{t}\) is a state vector.

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.

See Also

ma, es, ssarima

Examples

Run this code

# SMA of specific order
ourModel <- sma(rnorm(118,100,3),order=12,h=18,holdout=TRUE,intervals="p")

# SMA of arbitrary order
ourModel <- sma(rnorm(118,100,3),h=18,holdout=TRUE,intervals="sp")

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

Run the code above in your browser using DataLab