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 adviced 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)
## Time elapsed: 0.03 seconds
## Model estimated: ARIMA(0,1,1)
## Matrix of MA terms:
## Lag 1
## MA(1) -0.793
## Initial values were produced using backcasting.
## 2 parameters were estimated in the process
## Residuals standard deviation: 2117.713
## Cost function type: MSE; Cost function value: 4406715
##
## Information criteria:
## AIC AICc BIC
## 2089.699 2089.807 2095.189
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.83
## Matrix of MA terms:
## Lag 1 Lag 12
## MA(1) -0.814 -0.369
## Initial values were produced using backcasting.
## 4 parameters were estimated in the process
## Residuals standard deviation: 1936.126
## Cost function type: MSE; Cost function value: 3618199
##
## Information criteria:
## AIC AICc BIC
## 2071.027 2071.390 2082.007
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)
## Estimation progress: 0%1%1%2%3%3%4%5%5%6%9%9%10%12%12%13%14%17%17%18%19%19%20%20%22%22%22%23%25%26%27%28%34%50%51%51%52%53%53%53%54%55%55%56%56%59%59%60%61%67%83%100%... Done!
## Time elapsed: 3.56 seconds
## Model estimated: SARIMA(0,1,2)[1](0,0,3)[12]
## Matrix of MA terms:
## Lag 1 Lag 12
## MA(1) -0.594 0.392
## MA(2) -0.277 0.631
## MA(3) 0.000 0.049
## Initial values were produced using backcasting.
## 6 parameters were estimated in the process
## Residuals standard deviation: 1832.683
## Cost function type: MSE; Cost function value: 3183490
##
## Information criteria:
## AIC AICc BIC
## 2060.307 2061.085 2076.777
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")
## Estimation progress: 0%1%1%2%3%3%9%9%10%12%12%13%14%14%17%34%50%51%51%52%53%53%59%59%60%61%61%67%83%100%... Done!
## Time elapsed: 3.02 seconds
## Model estimated: SARIMA(0,0,3)[1](3,1,3)[12]
## Matrix of AR terms:
## Lag 12
## AR(1) -0.316
## AR(2) -0.437
## AR(3) 0.031
## Matrix of MA terms:
## Lag 1 Lag 12
## MA(1) 0.099 -0.687
## MA(2) 0.130 0.731
## MA(3) 0.222 -0.955
## Initial values were produced using backcasting.
## 10 parameters were estimated in the process
## Residuals standard deviation: 290.19
## Cost function type: MSE; Cost function value: 76413
##
## Information criteria:
## AIC AICc BIC
## 1540.833 1543.101 1567.654
auto.ssarima(M3$N1683$x, h=18, initial="optimal")
## Estimation progress: 0%1%1%2%3%9%17%34%50%67%83%100%... Done!
## Time elapsed: 3.97 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: 169346
##
## Information criteria:
## AIC AICc BIC
## 1622.778 1624.233 1644.235
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.
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)
## Estimation progress: 0%1%1%2%2%2%3%4%5%5%6%6%7%7%8%9%17%17%25%26%27%28%34%50%67%83%100%... Done!
we can then reuse it:
ssarima(M3$N2457$x, model=ourModel, h=18, holdout=FALSE, xreg=x, updateX=TRUE, intervals=TRUE)
## 50%100%Done!
## Time elapsed: 0.35 seconds
## Model estimated: SARIMA(0,0,2)[1](1,0,0)[12] with constant
## Matrix of AR terms:
## Lag 12
## AR(1) 0.113
## Matrix of MA terms:
## Lag 1
## MA(1) 0.112
## MA(2) 0.103
## Constant value is: 1488.106
## Initial values were provided by user.
## 17 parameters were estimated in the process
## Residuals standard deviation: 2235.635
## Xreg coefficients were estimated in a crazy style
## Cost function type: MSE; Cost function value: 4259218
##
## Information criteria:
## AIC AICc BIC
## 2115.784 2122.094 2162.448
## 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.02 seconds
## Model estimated: ARIMA(0,1,1)
## Matrix of MA terms:
## Lag 1
## MA(1) -0.793
## Initial values were produced using backcasting.
## 2 parameters were estimated in the process
## Residuals standard deviation: 2117.713
## Cost function type: MSE; Cost function value: 4406715
##
## Information criteria:
## AIC AICc BIC
## 2089.699 2089.807 2095.189
## 95% parametric prediction intervals were constructed