# sma: Simple Moving Average In config-i1/smooth: Forecasting Using State Space Models

## Description

Function constructs state space simple moving average of predefined order

## Usage

 1 2 3 4 sma(y, order = NULL, ic = c("AICc", "AIC", "BIC", "BICc"), h = 10, holdout = FALSE, cumulative = FALSE, interval = c("none", "parametric", "likelihood", "semiparametric", "nonparametric"), level = 0.95, silent = c("all", "graph", "legend", "output", "none"), ...) 

## Arguments

 y 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. cumulative If TRUE, then the cumulative forecast and prediction interval are produced instead of the normal ones. This is useful for inventory control systems. interval Type of interval to construct. This can be: "none", aka "n" - do not produce prediction interval. "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. This type of interval relies on unbiased estimate of in-sample error variance, which divides the sume of squared errors by T-k rather than just T. "likelihood", "l" - these are the same as "p", but relies on the biased estimate of variance from the likelihood (division by T, not by T-k). "semiparametric", "sp" - interval based on covariance matrix of 1 to h steps ahead errors and assumption of normal / log-normal distribution (depending on error type). "nonparametric", "np" - interval 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 interval are constructed, while the latter is equivalent to none. If the forecasts of the models were combined, then the interval are combined quantile-wise (Lichtendahl et al., 2013). 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.

## 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} ∑_{j=1}^n y_{t-j}

which is AR(n) process, that can be modelled using:

y_{t} = w' v_{t-1} + ε_{t}

v_{t} = F v_{t-1} + g ε_{t}

Where v_{t} is a state vector.

For some more information about the model and its implementation, see the vignette: vignette("sma","smooth")

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

• measurement - measurement vector of the model.

• order - order of moving average.

• initial - Initial state vector values.

• initialType - Type of initial values used.

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

• fitted - the fitted values.

• forecast - the point forecast.

• lower - the lower bound of prediction interval. When interval=FALSE then NA is returned.

• upper - the higher bound of prediction interval. When interval=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).

• interval - type of interval asked by user.

• level - confidence level for interval.

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

• y - the original data.

• holdout - the holdout part of the original data.

• ICs - values of information criteria of the model. Includes AIC, AICc, BIC and BICc.

• logLik - log-likelihood of the function.

• lossValue - Cost function value.

• loss - Type of loss function used in the estimation.

• accuracy - vector of accuracy measures for the holdout sample. Includes: MPE, MAPE, SMAPE, MASE, sMAE, RelMAE, sMSE and Bias coefficient (based on complex numbers). This is available only when holdout=TRUE.

## Author(s)

Ivan Svetunkov, ivan@svetunkov.ru

## References

• Svetunkov I. (2015 - Inf) "smooth" package for R - series of posts about the underlying models and how to use them: https://forecasting.svetunkov.ru/en/tag/smooth/.

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

• Svetunkov, I., & Petropoulos, F. (2017). Old dog, new tricks: a modelling view of simple moving averages. International Journal of Production Research, 7543(January), 1-14. doi: 10.1080/00207543.2017.1380326

## See Also

filter, es, ssarima

## Examples

 1 2 3 4 5 6 7 8 9 # SMA of specific order ourModel <- sma(rnorm(118,100,3),order=12,h=18,holdout=TRUE,interval="p") # SMA of arbitrary order ourModel <- sma(rnorm(118,100,3),h=18,holdout=TRUE,interval="sp") summary(ourModel) forecast(ourModel) plot(forecast(ourModel)) 

config-i1/smooth documentation built on June 16, 2021, 2:13 p.m.