Learn R Programming

smooth (version 4.3.0)

ssarima: State Space ARIMA

Description

Function constructs State Space ARIMA, estimating AR, MA terms and initial states.

Function selects the best State Space ARIMA based on information criteria, using fancy branch and bound mechanism. The resulting model can be not optimal in IC meaning, but it is usually reasonable.

Function constructs State Space ARIMA, estimating AR, MA terms and initial states.

Usage

ssarima(y, orders = list(ar = c(0), i = c(1), ma = c(1)), lags = c(1),
  constant = FALSE, arma = NULL, model = NULL,
  initial = c("backcasting", "optimal", "two-stage", "complete"),
  loss = c("likelihood", "MSE", "MAE", "HAM", "MSEh", "TMSE", "GTMSE",
  "MSCE"), h = 0, holdout = FALSE, bounds = c("admissible", "usual",
  "none"), silent = TRUE, xreg = NULL, regressors = c("use", "select",
  "adapt"), initialX = NULL, ...)

auto.ssarima(y, orders = list(ar = c(3, 3), i = c(2, 1), ma = c(3, 3)), lags = c(1, frequency(y)), fast = TRUE, constant = NULL, initial = c("backcasting", "optimal", "two-stage", "complete"), loss = c("likelihood", "MSE", "MAE", "HAM", "MSEh", "TMSE", "GTMSE", "MSCE"), ic = c("AICc", "AIC", "BIC", "BICc"), h = 0, holdout = FALSE, bounds = c("admissible", "usual", "none"), silent = TRUE, xreg = NULL, regressors = c("use", "select", "adapt"), ...)

ssarima_old(y, orders = list(ar = c(0), i = c(1), ma = c(1)), lags = c(1), constant = FALSE, AR = NULL, MA = NULL, initial = c("backcasting", "optimal"), ic = c("AICc", "AIC", "BIC", "BICc"), loss = c("likelihood", "MSE", "MAE", "HAM", "MSEh", "TMSE", "GTMSE", "MSCE"), h = 10, holdout = FALSE, bounds = c("admissible", "none"), silent = c("all", "graph", "legend", "output", "none"), xreg = NULL, regressors = c("use", "select"), initialX = NULL, ...)

Arguments

Value

Object of class "adam" is returned with similar elements to the adam function.

Object of class "smooth" is returned. See ssarima for details.

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.

  • AR - the matrix of coefficients of AR terms.

  • I - the matrix of coefficients of I terms.

  • MA - the matrix of coefficients of MA terms.

  • constant - the value of the constant term.

  • initialType - Type of the initial values used.

  • initial - the initial values of the 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.

  • fitted - the fitted values.

  • forecast - the point forecast.

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

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

  • xreg - provided vector or matrix of exogenous variables. If regressors="s", then this value will contain only selected exogenous variables.

  • initialX - initial values for parameters of exogenous variables.

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

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

  • B - the vector of all the estimated parameters.

Details

The model, implemented in this function, is discussed in Svetunkov & Boylan (2019).

The basic ARIMA(p,d,q) used in the function has the following form:

\((1 - B)^d (1 - a_1 B - a_2 B^2 - ... - a_p B^p) y_[t] = (1 + b_1 B + b_2 B^2 + ... + b_q B^q) \epsilon_[t] + c\)

where \(y_[t]\) is the actual values, \(\epsilon_[t]\) is the error term, \(a_i, b_j\) are the parameters for AR and MA respectively and \(c\) is the constant. In case of non-zero differences \(c\) acts as drift.

This model is then transformed into ARIMA in the Single Source of Error State space form (proposed in Snyder, 1985):

\(y_{t} = w' v_{t-l} + \epsilon_{t}\)

\(v_{t} = F v_{t-l} + g_t \epsilon_{t}\)

where \(v_{t}\) is the state vector (defined based on orders) and \(l\) is the vector of lags, \(w_t\) is the measurement vector (with explanatory variables if provided), \(F\) is the transition matrix, \(g_t\) is the persistence vector (which includes explanatory variables if they were used).

Due to the flexibility of the model, multiple seasonalities can be used. For example, something crazy like this can be constructed: SARIMA(1,1,1)(0,1,1)[24](2,0,1)[24*7](0,0,1)[24*30], but the estimation may take a lot of time... If you plan estimating a model with more than one seasonality, it is recommended to use msarima instead.

The model selection for SSARIMA is done by the auto.ssarima function.

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

The function constructs bunch of ARIMAs in Single Source of Error state space form (see ssarima documentation) and selects the best one based on information criterion. The mechanism is described in Svetunkov & Boylan (2019).

Due to the flexibility of the model, multiple seasonalities can be used. For example, something crazy like this can be constructed: SARIMA(1,1,1)(0,1,1)[24](2,0,1)[24*7](0,0,1)[24*30], but the estimation may take a lot of time... It is recommended to use auto.msarima in cases with more than one seasonality and high frequencies.

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

The model, implemented in this function, is discussed in Svetunkov & Boylan (2019).

The basic ARIMA(p,d,q) used in the function has the following form:

\((1 - B)^d (1 - a_1 B - a_2 B^2 - ... - a_p B^p) y_[t] = (1 + b_1 B + b_2 B^2 + ... + b_q B^q) \epsilon_[t] + c\)

where \(y_[t]\) is the actual values, \(\epsilon_[t]\) is the error term, \(a_i, b_j\) are the parameters for AR and MA respectively and \(c\) is the constant. In case of non-zero differences \(c\) acts as drift.

This model is then transformed into ARIMA in the Single Source of Error State space form (proposed in Snyder, 1985):

\(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 based on 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.

Due to the flexibility of the model, multiple seasonalities can be used. For example, something crazy like this can be constructed: SARIMA(1,1,1)(0,1,1)[24](2,0,1)[24*7](0,0,1)[24*30], but the estimation may take some finite time... If you plan estimating a model with more than one seasonality, it is recommended to consider doing it using msarima.

The model selection for SSARIMA is done by the auto.ssarima function.

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

References

  • Svetunkov I. (2023) Smooth forecasting with the smooth package in R. arXiv:2301.01790. tools:::Rd_expr_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., 2023. Smooth Forecasting with the Smooth Package in R. arXiv. tools:::Rd_expr_doi("10.48550/arXiv.2301.01790")

  • 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. tools:::Rd_expr_doi("10.1007/978-3-540-71918-2").

  • Svetunkov, I., 2023. Smooth Forecasting with the Smooth Package in R. arXiv. tools:::Rd_expr_doi("10.48550/arXiv.2301.01790")

  • 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. tools:::Rd_expr_doi("10.1007/978-3-540-71918-2").

  • Svetunkov, I., Boylan, J.E., 2023a. iETS: State Space Model for Intermittent Demand Forecastings. International Journal of Production Economics. 109013. tools:::Rd_expr_doi("10.1016/j.ijpe.2023.109013")

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

  • Svetunkov, I., & Boylan, J. E. (2019). State-space ARIMA for supply-chain forecasting. International Journal of Production Research, 0(0), 1–10. tools:::Rd_expr_doi("10.1080/00207543.2019.1600764")

  • Svetunkov, I., 2023. Smooth Forecasting with the Smooth Package in R. arXiv. tools:::Rd_expr_doi("10.48550/arXiv.2301.01790")

  • 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. tools:::Rd_expr_doi("10.1007/978-3-540-71918-2").

  • Svetunkov, I., & Boylan, J. E. (2019). State-space ARIMA for supply-chain forecasting. International Journal of Production Research, 0(0), 1–10. tools:::Rd_expr_doi("10.1080/00207543.2019.1600764")

See Also

auto.ssarima, auto.msarima, adam, es, ces

es, ces, sim.es, gum, ssarima

auto.ssarima, orders, msarima, auto.msarima, sim.ssarima, adam

Examples

Run this code
# ARIMA(1,1,1) fitted to some data
ourModel <- ssarima(rnorm(118,100,3),orders=list(ar=c(1),i=c(1),ma=c(1)),lags=c(1))

# Model with the same lags and orders, applied to a different data
ssarima(rnorm(118,100,3),orders=orders(ourModel),lags=lags(ourModel))

# The same model applied to a different data
ssarima(rnorm(118,100,3),model=ourModel)

# Example of SARIMA(2,0,0)(1,0,0)[4]
ssarima(rnorm(118,100,3),orders=list(ar=c(2,1)),lags=c(1,4))

# SARIMA(1,1,1)(0,0,1)[4] with different initialisations
ssarima(rnorm(118,100,3),orders=list(ar=c(1),i=c(1),ma=c(1,1)),
        lags=c(1,4),h=18,holdout=TRUE,initial="backcasting")


set.seed(41)
x <- rnorm(118,100,3)

# The best ARIMA for the data
ourModel <- auto.ssarima(x,orders=list(ar=c(2,1),i=c(1,1),ma=c(2,1)),lags=c(1,12),
                                   h=18,holdout=TRUE)

# The other one using optimised states
auto.ssarima(x,orders=list(ar=c(3,2),i=c(2,1),ma=c(3,2)),lags=c(1,12),
                       initial="two",h=18,holdout=TRUE)

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


# ARIMA(1,1,1) fitted to some data
ourModel <- ssarima_old(rnorm(118,100,3),orders=list(ar=c(1),i=c(1),ma=c(1)),lags=c(1),h=18,
                             holdout=TRUE)

# Model with the same lags and orders, applied to a different data
ssarima_old(rnorm(118,100,3),orders=orders(ourModel),lags=lags(ourModel),h=18,holdout=TRUE)

# The same model applied to a different data
ssarima_old(rnorm(118,100,3),model=ourModel,h=18,holdout=TRUE)

# SARIMA(0,1,1) with exogenous variables
ssarima_old(rnorm(118,100,3),orders=list(i=1,ma=1),h=18,holdout=TRUE,xreg=c(1:118))

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

Run the code above in your browser using DataLab