# data modelM=c("diff",1,"diff",12)r =Resid(chicken,M)test(r)
Null hypothesis: Residuals are iid noise.
Test Distribution Statistic p-value
Ljung-Box Q Q ~ chisq(20) 236.56 0 *
McLeod-Li Q Q ~ chisq(20) 69.81 0 *
Turning points T (T-110)/5.4 ~ N(0,1) 85 0 *
Diff signs S (S-83)/3.7 ~ N(0,1) 89 0.1088
Rank P (P-6930.5)/361.3 ~ N(0,1) 6323 0.0927
Test stationary
# Augmented Dickey-Fuller Test# H0: X_t is a non-stationary time series# H1: X_t is a stationary time serieslibrary(aTSA)adf.test(r)
Augmented Dickey-Fuller Test
alternative: stationary
Type 1: no drift no trend
lag ADF p.value
[1,] 0 -5.00 0.01
[2,] 1 -5.54 0.01
[3,] 2 -5.42 0.01
[4,] 3 -4.45 0.01
[5,] 4 -4.15 0.01
Type 2: with drift no trend
lag ADF p.value
[1,] 0 -4.98 0.01
[2,] 1 -5.53 0.01
[3,] 2 -5.41 0.01
[4,] 3 -4.43 0.01
[5,] 4 -4.14 0.01
Type 3: with drift and trend
lag ADF p.value
[1,] 0 -5.03 0.01
[2,] 1 -5.58 0.01
[3,] 2 -5.46 0.01
[4,] 3 -4.47 0.01
[5,] 4 -4.17 0.01
----
Note: in fact, p.value = 0.01 means p.value <= 0.01
# Results in stationary data. No differencing is needed.
SARIMA models
# Potential Values# based on the PACF# p = 0, 1, 2# P = 0, 1, 2# based on the ACF# q = 0, 1, 2, 3, 9, 10, 11# Q = 0, 1, 2,# Eliminate Trend and Season# d = 1# D = 1# SARIMA (1,1,1)x(1,1,1)12fit1 =arima(chicken,order =c(1,1,1),seasonal =list(order=c(1,1,1),period=12))test(fit1$residuals)
Null hypothesis: Residuals are iid noise.
Test Distribution Statistic p-value
Ljung-Box Q Q ~ chisq(20) 26.41 0.1526
McLeod-Li Q Q ~ chisq(20) 26.03 0.165
Turning points T (T-118.7)/5.6 ~ N(0,1) 113 0.314
Diff signs S (S-89.5)/3.9 ~ N(0,1) 90 0.8976
Rank P (P-8055)/404.2 ~ N(0,1) 7885 0.674
# Auto fitbestmodel =auto.arima(chicken, trace=TRUE)
Fitting models using approximations to speed things up...
ARIMA(2,1,2)(1,0,1)[12] with drift : Inf
ARIMA(0,1,0) with drift : 512.1327
ARIMA(1,1,0)(1,0,0)[12] with drift : 357.8553
ARIMA(0,1,1)(0,0,1)[12] with drift : 399.0111
ARIMA(0,1,0) : 521.4674
ARIMA(1,1,0) with drift : 380.5252
ARIMA(1,1,0)(2,0,0)[12] with drift : 361.1736
ARIMA(1,1,0)(1,0,1)[12] with drift : Inf
ARIMA(1,1,0)(0,0,1)[12] with drift : 361.7262
ARIMA(1,1,0)(2,0,1)[12] with drift : Inf
ARIMA(0,1,0)(1,0,0)[12] with drift : 496.251
ARIMA(2,1,0)(1,0,0)[12] with drift : 349.6098
ARIMA(2,1,0) with drift : 361.2204
ARIMA(2,1,0)(2,0,0)[12] with drift : 352.9452
ARIMA(2,1,0)(1,0,1)[12] with drift : Inf
ARIMA(2,1,0)(0,0,1)[12] with drift : 347.5637
ARIMA(2,1,0)(0,0,2)[12] with drift : 348.8669
ARIMA(2,1,0)(1,0,2)[12] with drift : Inf
ARIMA(3,1,0)(0,0,1)[12] with drift : 346.8076
ARIMA(3,1,0) with drift : 359.6763
ARIMA(3,1,0)(1,0,1)[12] with drift : Inf
ARIMA(3,1,0)(0,0,2)[12] with drift : 348.5706
ARIMA(3,1,0)(1,0,0)[12] with drift : 350.3946
ARIMA(3,1,0)(1,0,2)[12] with drift : Inf
ARIMA(4,1,0)(0,0,1)[12] with drift : 349.2894
ARIMA(3,1,1)(0,0,1)[12] with drift : 347.6645
ARIMA(2,1,1)(0,0,1)[12] with drift : 346.754
ARIMA(2,1,1) with drift : 359.2506
ARIMA(2,1,1)(1,0,1)[12] with drift : Inf
ARIMA(2,1,1)(0,0,2)[12] with drift : 348.4092
ARIMA(2,1,1)(1,0,0)[12] with drift : 350.2436
ARIMA(2,1,1)(1,0,2)[12] with drift : Inf
ARIMA(1,1,1)(0,0,1)[12] with drift : 354.7731
ARIMA(2,1,2)(0,0,1)[12] with drift : 348.0198
ARIMA(1,1,2)(0,0,1)[12] with drift : 348.7836
ARIMA(3,1,2)(0,0,1)[12] with drift : 349.5839
ARIMA(2,1,1)(0,0,1)[12] : 347.2775
Now re-fitting the best model(s) without approximations...
ARIMA(2,1,1)(0,0,1)[12] with drift : 351.5017
Best model: ARIMA(2,1,1)(0,0,1)[12] with drift
test(bestmodel$residuals)
Null hypothesis: Residuals are iid noise.
Test Distribution Statistic p-value
Ljung-Box Q Q ~ chisq(20) 20.39 0.4339
McLeod-Li Q Q ~ chisq(20) 25.62 0.1789
Turning points T (T-118.7)/5.6 ~ N(0,1) 126 0.1926
Diff signs S (S-89.5)/3.9 ~ N(0,1) 96 0.0942
Rank P (P-8055)/404.2 ~ N(0,1) 8124 0.8644
Fitting models using approximations to speed things up...
ARIMA(2,1,2) with drift : 358.0721
ARIMA(0,1,0) with drift : 507.8724
ARIMA(1,1,0) with drift : 377.5175
ARIMA(0,1,1) with drift : 412.1149
ARIMA(0,1,0) : 517.4894
ARIMA(1,1,2) with drift : 361.6613
ARIMA(2,1,1) with drift : 355.8188
ARIMA(1,1,1) with drift : 368.1617
ARIMA(2,1,0) with drift : 358.1683
ARIMA(3,1,1) with drift : 356.2727
ARIMA(3,1,0) with drift : 356.2762
ARIMA(3,1,2) with drift : Inf
ARIMA(2,1,1) : 359.48
Now re-fitting the best model(s) without approximations...
ARIMA(2,1,1) with drift : 360.3365
Best model: ARIMA(2,1,1) with drift