sma {smooth} | R Documentation |
Simple Moving Average
Description
Function constructs state space simple moving average of predefined order
Usage
sma(y, order = NULL, ic = c("AICc", "AIC", "BIC", "BICc"), h = 10,
holdout = FALSE, silent = TRUE, fast = TRUE, ...)
sma_old(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 |
ic |
The information criterion used in the model selection procedure. |
h |
Length of forecasting horizon. |
holdout |
If |
silent |
If |
fast |
if |
... |
Other non-documented parameters. For example parameter
|
cumulative |
If |
interval |
Type of interval to construct. This can be:
The parameter also accepts |
level |
Confidence level. Defines width of prediction interval. |
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.
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, whererows
correspond to time andcols
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. Wheninterval=FALSE
then NA is returned. -
upper
- the higher bound of prediction interval. Wheninterval=FALSE
then NA is returned. -
residuals
- the residuals of the estimated model. -
errors
- The matrix of 1 to h steps ahead errors. Only returned when the multistep losses are used and semiparametric interval is needed. -
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 whenholdout=TRUE
.
Author(s)
Ivan Svetunkov, ivan@svetunkov.ru
References
Svetunkov I. (2023) Smooth forecasting with the smooth package in R. arXiv:2301.01790. doi:10.48550/arXiv.2301.01790.
Svetunkov I. (2015 - Inf) "smooth" package for R - series of posts about the underlying models and how to use them: https://openforecast.org/category/r-en/smooth/.
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
Examples
# SMA of specific order
ourModel <- sma(rnorm(118,100,3), order=12, h=18, holdout=TRUE)
# SMA of arbitrary order
ourModel <- sma(rnorm(118,100,3), h=18, holdout=TRUE)
plot(forecast(ourModel, h=18, interval="empirical"))