ssarima() - State-Space ARIMA

Ivan Svetunkov

2018-07-03

SSARIMA stands for “State-space ARIMA” or “Several Seasonalities ARIMA”. Both names show what happens in the heart of the function: it constructs ARIMA in a state-space form and allows to model several (actually more than several) seasonalities. ssarima() is a function included in smooth package. This vignette covers ssarima() and auto.ssarima() functions.

As usual, we will use data from Mcomp package, so it is advised to install it.

Let’s load the necessary packages:

require(smooth)
require(Mcomp)

The default call constructs ARIMA(0,1,1):

ssarima(M3$N2457$x, h=18, silent=FALSE)
## Time elapsed: 0.02 seconds
## Model estimated: ARIMA(0,1,1)
## Matrix of MA terms:
##        Lag 1
## MA(1) -0.794
## Initial values were produced using backcasting.
## 2 parameters were estimated in the process
## Residuals standard deviation: 2116.361
## Cost function type: MSE; Cost function value: 4401089.934
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2089.553 2089.660 2095.042 2095.297

Some more complicated model can be defined using parameter orders the following way:

ssarima(M3$N2457$x, orders=list(ar=c(0,1),i=c(1,0),ma=c(1,1)),lags=c(1,12),h=18)
## Time elapsed: 0.1 seconds
## Model estimated: SARIMA(0,1,1)[1](1,0,1)[12]
## Matrix of AR terms:
##       Lag 12
## AR(1)  0.786
## Matrix of MA terms:
##        Lag 1 Lag 12
## MA(1) -0.815 -0.319
## Initial values were produced using backcasting.
## 4 parameters were estimated in the process
## Residuals standard deviation: 1935.435
## Cost function type: MSE; Cost function value: 3615617.652
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2070.945 2071.308 2081.925 2082.787

This would construct us seasonal ARIMA(0,1,1)(1,0,1)\(_{12}\).

We could try selecting orders manually, but this can also be done automatically via auto.ssarima() function:

auto.ssarima(M3$N2457$x, h=18)
## Time elapsed: 2.61 seconds
## Model estimated: SARIMA(0,1,2)[1](0,0,2)[12] with drift
## Matrix of MA terms:
##        Lag 1 Lag 12
## MA(1) -0.598  0.436
## MA(2) -0.320  0.534
## Constant value is: 56.093
## Initial values were produced using backcasting.
## 6 parameters were estimated in the process
## Residuals standard deviation: 1806.293
## Cost function type: MSE; Cost function value: 3092467.624
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2056.971 2057.749 2073.441 2075.286

Automatic order selection in SSARIMA with optimised initials does not work well and in general is not recommended. This is partially because of the possible high number of parameters in some models and partially because of potential overfitting of first observations when non-zero order of AR is selected. This problem can be seen on example of another time series (which has complicated seasonality):

auto.ssarima(M3$N1683$x, h=18, initial="backcasting")
## Time elapsed: 1.89 seconds
## Model estimated: SARIMA(0,0,3)[1](3,0,0)[12] with constant
## Matrix of AR terms:
##       Lag 12
## AR(1)  0.162
## AR(2)  0.332
## AR(3)  0.173
## Matrix of MA terms:
##       Lag 1
## MA(1) 0.221
## MA(2) 0.173
## MA(3) 0.235
## Constant value is: 1311.346
## Initial values were produced using backcasting.
## 8 parameters were estimated in the process
## Residuals standard deviation: 390.997
## Cost function type: MSE; Cost function value: 141554.42
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 1603.418 1604.873 1624.875 1628.280
auto.ssarima(M3$N1683$x, h=18, initial="optimal")
## Time elapsed: 3.98 seconds
## Model estimated: ARIMA(0,0,3) with constant
## Matrix of MA terms:
##       Lag 1
## MA(1) 0.356
## MA(2) 0.293
## MA(3) 0.310
## Constant value is: 3786.814
## Initial values were optimised.
## 8 parameters were estimated in the process
## Residuals standard deviation: 427.661
## Cost function type: MSE; Cost function value: 169345.889
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 1622.778 1624.233 1644.235 1647.640

As can be seen from the second graph, ssarima with optimal initial does not select seasonal model and reverts to ARIMA(0,0,3) with constant. In theory this can be due to implemented order selection algorithm, however if we estimate all the model in the pool separately, we will see that this model is optimal for this time series when this type of initials is used.

A power of ssarima() function is that it can estimate SARIMA models with multiple seasonalities. For example, SARIMA(0,1,1)(0,0,1)_6(1,0,1)_12 model can be estimated the following way:

ssarima(M3$N2457$x, orders=list(ar=c(0,0,1),i=c(1,0,0),ma=c(1,1,1)),lags=c(1,6,12),h=18, silent=FALSE)
## Time elapsed: 0.18 seconds
## Model estimated: SARIMA(0,1,1)[1](0,0,1)[6](1,0,1)[12]
## Matrix of AR terms:
##       Lag 12
## AR(1)  0.725
## Matrix of MA terms:
##        Lag 1  Lag 6 Lag 12
## MA(1) -0.789 -0.206 -0.283
## Initial values were produced using backcasting.
## 5 parameters were estimated in the process
## Residuals standard deviation: 1914.178
## Cost function type: MSE; Cost function value: 3504770.012
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2069.364 2069.914 2083.089 2084.394

It probably does not make much sense for this type of data, it would make more sense on high frequency data (for example, taylor series from forecast package). However, keep in mind that multiple seasonal ARIMAs are very slow in estimation and are very capricious. So it is really hard to obtain an appropriate and efficient multiple seasonal ARIMA model.

Now let’s introduce some artificial exogenous variables:

x <- cbind(rnorm(length(M3$N2457$x),50,3),rnorm(length(M3$N2457$x),100,7))

If we save model:

ourModel <- auto.ssarima(M3$N2457$x, h=18, holdout=TRUE, xreg=x, updateX=TRUE)

we can then reuse it:

ssarima(M3$N2457$x, model=ourModel, h=18, holdout=FALSE, xreg=x, updateX=TRUE, intervals=TRUE)
## Time elapsed: 0.25 seconds
## Model estimated: SARIMAX(0,0,2)[1](0,0,2)[12] with constant
## Matrix of MA terms:
##       Lag 1 Lag 12
## MA(1) 0.114  0.101
## MA(2) 0.101  0.100
## Constant value is: 3166.51
## Initial values were provided by user.
## 1 parameter was estimated in the process
## 39 parameters were provided
## Residuals standard deviation: 2474.617
## Xreg coefficients were estimated in a crazy style
## Cost function type: MSE; Cost function value: 6070480.254
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2124.535 2124.570 2127.280 2127.364 
## 95% parametric prediction intervals were constructed

Finally, we can combine several SARIMA models:

ssarima(M3$N2457$x, h=18, holdout=FALSE, intervals=TRUE, combine=TRUE)
## Time elapsed: 0.01 seconds
## Model estimated: ARIMA(0,1,1)
## Matrix of MA terms:
##        Lag 1
## MA(1) -0.794
## Initial values were produced using backcasting.
## 2 parameters were estimated in the process
## Residuals standard deviation: 2116.361
## Cost function type: MSE; Cost function value: 4401089.934
## 
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2089.553 2089.660 2095.042 2095.297 
## 95% parametric prediction intervals were constructed