ARIMA 建模的步驟 Stationize: 檢測序列的平穩性,對不平穩的序列,差分轉換為平穩序列。 Tentative identification: 由資料的 acf, pacf 辨識適合的 ARMA模式, 選出數個可能模式。 Estimation: 對遴選模式估計參數 Diagnostic Checking: 由各種診斷法來檢視模式的適合性,挑選出一模式,視為用於預測的模式 Forecasting: 以最終模式預測未來值 應隨時做模式的更新。
Make a Stationary series 如果手中的時序資料不是 stationary,以一次差分轉換,使成為一 stationary series,必要時用多次差分。 利用檢定確認它是一 平穩序列
Tentative identification 由樣本的acf 及pacf 的走勢及變化來辨識ARMA模式中的 p,q值 選出數個候選模式 模式應力求簡單 Model acf Pacf MA(q) 時差 q 之後切斷 指數或正弦函數式漸漸消失 AR(p) 時差 p 之後切斷 ARMA(p,q)
Estimation 原則上用 least square estimate 估計的係數必滿足 平穩性及可逆性之條件 ARMA 係數的估計有時需以遞迴的數值法得解,有可能遇到不收歛情況
例 : 一平穩序列,分別以 AR(1), MA(1), 及 ARMA(1,1) 配適: PACF ACF Autocorrelations Lag Correlation 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 - 1.00000 | |********************| 1 -.43773 | |*********| . | 0.100000 2 0.05214 | . |* . | 0.117610 3 -.00119 | . | . | 0.117841 4 -.07136 | . *| . | 5 -.00389 0.118273 6 -.09027 | . **| . | 0.118274 7 0.08643 | . |** . | 0.118961 8 -.04553 0.119587 9 0.08755 0.119760 10 -.13564 | . ***| . | 0.120399 11 0.18628 | . |****. | 0.121917 12 -.24375 | *****| . | 0.124731 Partial Autocorrelations Lag Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 1 -0.43773 | *********| . | 2 -0.17253 | .***| . | 3 -0.06368 | . *| . | 4 -0.11413 | . **| . | 5 -0.11104 | . **| . | 6 -0.19625 | ****| . | 7 -0.07274 | . *| . | 8 -0.08091 | . **| . | 9 0.02756 | . |* . | 10 -0.14766 | .***| . | 11 0.07253 | . |* . | 12 -0.20707 | ****| .
No mean term in this model. 以 AR(1) 配適: Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag AR1,1 -0.44383 0.09084 -4.89 <.0001 1 Variance Estimate 1.185361 Std Error Estimate 1.088743 AIC 301.7874 SBC 304.3926 Number of Residuals 100 Model for variable Zt No mean term in this model. Autoregressive Factors Factor 1: 1 + 0.44383 B**(1)
以 MA(1) 配適: Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 0.64635 0.07778 8.31 <.0001 1 Model for variable Zt No mean term in this model. Variance Estimate 1.11113 Std Error Estimate 1.054101 AIC 295.3204 SBC 297.9256 Number of Residuals 100 Moving Average Factors Factor 1: 1 - 0.64635 B**(1)
以 ARMA(1,1) 配適: Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 1.00000 0.01565 63.89 <.0001 1 AR1,1 0.37117 0.09579 3.87 0.0002 Model for variable Zt No mean term in this model. Variance Estimate 1.01438 Std Error Estimate 1.007164 AIC 287.1952 SBC 292.4055 Number of Residuals 100 Autoregressive Factors Factor 1: 1 - 0.37117 B**(1) Moving Average Factors Factor 1: 1 - 1 B**(1)
Diagnostic Checking 一個適合的模式:係數顯著、殘差為 white noise 殘差為 white noise 之檢測: 1、autocorrelation check for residual (chi-square test) H0 :ρ1= ρ2= …=ρk=0 (在 SAS 中每六個檢定一次) p-value < 0.05 ,結論為其中至少有一個不為 0 2、觀察殘差的 ACF, PACF 係數的檢測: 1、顯著性 t-test p-value < 0.05 ,結論為係數不為 0 2、共線性狀況 檢查係數的相關係數
AICk = n ln(SSEk) – n ln(n) + 2k SBCk = n ln(SSEk) – n ln(n) + ln(n) k AIC, SBC 模式判定值 AICk = n ln(SSEk) – n ln(n) + 2k SBCk = n ln(SSEk) – n ln(n) + ln(n) k 此處 SSE 為誤差平方值, k 為估計參數個數 ,判定值愈小,模式愈佳。 Standard Error 標準誤 標準誤小,預測誤差小,預測區間窄 預測式的選取 先選數個模式,檢測它們的適合性,再由適合的模式中比較AIC, SBC,及相關的適合現象,最後選一最理想的做為預測式。原則上,預測式愈簡單愈好。
例題: 一、以 AR(1) 配適: 另由殘差的 ACF PACF 顯示 無自相關 二、以 MA(1) 配適: Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 6.43 5 0.2663 -0.076 -0.163 -0.020 -0.105 -0.096 -0.088 12 10.35 11 0.4991 0.060 0.023 0.029 -0.062 0.062 -0.147 18 17.83 17 0.3997 0.093 -0.067 0.064 0.077 -0.141 0.135 24 24.79 23 0.3613 0.101 -0.164 0.075 -0.015 0.017 另由殘差的 ACF PACF 顯示 無自相關 二、以 MA(1) 配適: Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 8.15 5 0.1484 0.067 0.061 -0.051 -0.151 -0.141 12 13.10 11 0.2870 0.003 -0.039 0.018 -0.107 0.043 -0.167 18 19.11 17 0.3225 0.093 -0.053 0.081 0.097 -0.074 0.129 24 24.51 23 0.3761 0.035 -0.078 -0.169 0.022 -0.073 0.004 另由殘差的 ACF PACF 顯示 無自相關
三、以 ARMA(1,1) 配適: 另由殘差的 ACF PACF 顯示 無自相關 共線性現象微弱 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 4.61 4 0.3297 -0.079 0.158 0.057 -0.037 -0.021 -0.088 12 12.81 10 0.2343 0.051 -0.044 0.042 -0.127 0.090 -0.203 18 21.03 16 0.1773 0.126 -0.099 0.062 -0.124 0.123 24 26.35 22 0.2371 0.006 -0.055 -0.158 0.059 -0.093 0.027 另由殘差的 ACF PACF 顯示 無自相關 Correlations of Parameter Estimates Parameter MA1,1 AR1,1 1.000 0.117 共線性現象微弱
在此三模式中,MA(1) 最適合資料,選定預測式為 Yt = εt – 0.646 εt-1 , S = 1.054 三模式比較 參數顯著性 Is residual white noise? Std Error AIC, SBC Model_1 AR(1) 顯著 Yes 1.089 302, 304 Model_2 MA(1) 1.054 295, 298 Model_3 ARMA(1,1) 顯著,但有一估計值為 1,不滿足可逆性 1.007 287, 292 在此三模式中,MA(1) 最適合資料,選定預測式為 Yt = εt – 0.646 εt-1 , S = 1.054
Case Study – DVD weekly sale series 原始資料序列 Step 1、平穩性檢測 Step 2、遴選模式及診斷 Step 3、預測
Step 1.1、平穩性檢測 原始資料非平穩序列 Dickey-Fuller Unit Root Tests Type Lags Rho Autocorrelations Lag Covariance Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 Std Error 234.852 1.00000 | |********************| 1 228.692 0.97377 | . |******************* | 0.07 2 219.550 0.93485 | . |******************* | 0.13 3 211.028 0.89856 | . |****************** | 0.16 4 202.545 0.86244 | . |***************** | 0.19 5 193.677 0.82468 | . |**************** | 0.21 6 186.454 0.79392 | . |**************** | 0.23 7 182.484 0.77702 0.25 8 179.699 0.76516 | . |*************** | 0.26 9 176.953 0.75347 0.28 10 174.970 0.74502 | . |*************** | 0.29 Dickey-Fuller Unit Root Tests Type Lags Rho Pr < Rho Tau Pr < Tau F Pr > F Zero Mean 0.4544 0.7937 0.78 0.8800 Single Mean -1.9634 0.7812 -0.84 0.8051 0.87 0.8489 Trend -8.9177 0.5030 -2.18 0.4962 2.49 0.6796 原始資料非平穩序列
Step 1.2、差分一次,平穩性檢測 一次差分資料為平穩序列 Dickey-Fuller Unit Root Tests Type Autocorrelations Lag Covariance Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 Std Error 7.916369 1.00000 | |********************| 1 3.442783 0.43489 | . |********* | 0.079057 2 -0.065133 -.00823 | . | . | 0.092813 3 0.015437 0.00195 0.092817 4 -0.136313 -.01722 5 -1.889516 -.23868 | *****| . | 0.092837 6 -2.656235 -.33554 | *******| . | 0.096597 7 -0.890803 -.11253 | . **| . | 0.103625 8 -0.523478 -.06613 | . *| . | 0.104386 Dickey-Fuller Unit Root Tests Type Lags Rho Pr < Rho Tau Pr < Tau F Pr > F Zero Mean -88.5965 <.0001 -7.76 Single Mean -89.1810 0.0012 -7.78 30.26 0.0010 Trend -89.2742 0.0005 30.13 一次差分資料為平穩序列
Step 2、遴選模式及診斷 (設定平均數為 0) 觀察 ACF, PACF; r1>0 r6>0 acf dies down r11>0 r22>0 pacf dies down PACF Partial Autocorrelations Lag Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 1 0.43489 | . |********* | 2 -0.24339 | *****| . | 3 0.14715 | . |*** | 4 -0.11389 | .**| . | 5 -0.23959 6 -0.14628 | ***| . | 7 0.08505 | . |**. | 8 -0.15793 9 0.03565 | . |* . | 10 -0.05646 | . *| . | 11 0.01943 | . | . | 12 0.06090 儲選模式一:AR(1) or ARMA(1,1)
Step 2.1、模式1 AR(1) AR(1) 配適結果,殘差仍有自相關現象 Autoregressive Factors 1 - 0.44279 B**(1) Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag AR1,1 0.44279 0.07159 6.19 <.0001 1 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 32.93 5 <.0001 0.104 -0.244 0.029 0.107 -0.165 -0.297 12 37.32 11 0.0001 0.058 0.007 -0.073 -0.028 0.069 0.105 18 40.89 17 0.0010 0.063 0.028 0.031 -0.113 -0.037 24 48.93 23 0.0013 0.040 -0.092 -0.054 0.144 -0.091 30 53.69 29 0.0035 0.100 0.116 -0.030 -0.017 -0.006 0.003 AR(1) 配適結果,殘差仍有自相關現象
Step 2.2、模式2 ARMA(1,1) ARMA(1,1) 配適結果,殘差仍有自相關現象,在 k=6 Autoregressive Factors Factor 1: 1 - 0.01541 B**(1) Moving Average Factors Factor 1: 1 + 0.57105 B**(1) Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 18.23 4 0.0011 0.000 -0.006 -0.009 0.045 -0.131 -0.299 12 22.07 10 0.0148 0.054 -0.075 -0.034 -0.032 0.072 0.080 18 27.56 16 0.0356 0.084 0.061 -0.132 0.002 -0.049 24 32.62 22 0.0675 0.039 -0.081 -0.043 0.112 0.031 -0.059 30 36.71 28 0.1253 0.092 0.093 0.015 Autocorrelation Plot of Residuals Lag Covariance Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1 Std Error 6.008539 1.00000 | |********************| 1 0.00067648 0.00011 | . | . | 0.079057 2 -0.038079 -.00634 3 -0.056140 -.00934 0.079060 4 0.269243 0.04481 | . |* . | 0.079067 5 -0.785409 -.13072 | ***| . | 0.079226 6 -1.794893 -.29872 | ******| . | 0.080562 7 0.324296 0.05397 0.087211 ARMA(1,1) 配適結果,殘差仍有自相關現象,在 k=6
Step 2.3、模式3 AR with B,B^6, MA with B Autoregressive Factors Factor 1: 1 + 0.02809 B**(1) + 0.32725 B**(6) Moving Average Factors Factor 1: 1 + 0.569 B**(1) Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 -0.56900 0.10222 -5.57 <.0001 1 AR1,1 -0.02809 0.11684 -0.24 0.8103 AR1,2 -0.32725 0.08051 -4.06 6 Correlations of Parameter Estimates Parameter MA1,1 AR1,1 AR1,2 1.000 0.752 -0.139 -0.010 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 3.38 3 0.3367 0.015 -0.015 -0.025 0.036 -0.134 -0.001 12 7.10 9 0.6270 0.079 -0.085 -0.030 -0.075 0.038 -0.013 18 14.65 15 0.4772 0.134 -0.054 0.041 -0.128 0.028 -0.051 24 20.06 21 0.5176 0.108 -0.052 -0.037 0.083 0.021 -0.077 30 24.78 27 0.5869 0.084 0.087 0.018 -0.059 -0.016 配適結果,殘差無自相關現象,AR1,1 係數不顯著
Step 2.4、模式4 AR with B^6, MA with B Autoregressive Factors Factor 1: 1 + 0.32052 B**(6) Moving Average Factors Factor 1: 1 + 0.55465 B**(1) Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 -0.55465 0.06761 -8.20 <.0001 1 AR1,1 -0.32052 0.08004 -4.00 6 Correlations of Parameter Estimates Parameter MA1,1 AR1,1 1.000 -0.188 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 3.10 4 0.5410 0.008 -0.019 -0.013 0.042 -0.127 0.000 12 6.83 10 0.7411 0.093 -0.078 -0.025 -0.066 0.044 -0.006 18 13.93 16 0.6039 0.135 -0.047 0.048 -0.119 0.035 -0.041 24 19.71 22 0.6010 0.116 -0.044 -0.030 0.094 0.028 -0.072 30 24.57 28 0.6510 0.090 -0.071 0.025 -0.050 -0.008
Step 2.5、模式5 AR with B, MA with B^6 Autoregressive Factors Factor 1: 1 - 0.43226 B**(1) Moving Average Factors Factor 1: 1 - 0.28716 B**(6) Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 0.28716 0.07961 3.61 0.0004 6 AR1,1 0.43226 0.07289 5.93 <.0001 1 Correlations of Parameter Estimates Parameter MA1,1 AR1,1 1.000 -0.118 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 15.30 4 0.0041 0.107 -0.247 0.013 0.032 -0.135 -0.029 12 21.41 10 0.0184 0.110 -0.053 -0.073 -0.051 0.029 0.108 18 25.61 16 0.0598 0.117 -0.007 -0.004 -0.094 -0.031 0.005 24 32.99 22 0.0620 0.101 -0.058 -0.067 0.111 0.018 30 38.56 28 0.0883 0.112 -0.010 -0.017
Step 2.6、模式6 MA(2) with B & B^6 Moving Average Factors Factor 1: Conditional Least Squares Estimation Parameter Estimate Standard Error t Value Approx Pr > |t| Lag MA1,1 -0.61177 0.05499 -11.13 <.0001 1 MA1,2 0.32354 0.05476 5.91 6 Correlations of Parameter Estimates Parameter MA1,1 MA1,2 1.000 0.682 Autocorrelation Check of Residuals To Lag Chi-Square DF Pr > ChiSq Autocorrelations 6 2.24 4 0.6912 0.011 -0.004 -0.001 0.015 -0.107 -0.039 12 5.87 10 0.8263 -0.069 0.006 -0.058 -0.044 0.051 0.091 18 9.52 16 0.8905 0.067 0.034 0.004 0.033 -0.045 24 14.69 22 0.8751 0.057 -0.026 -0.070 0.108 0.046 30 20.07 28 0.8618 0.115 0.081 -0.053 -0.063 -0.011
Step 2.7、Summary 選擇 Model 6為預測式 參數 Is residual white noise? Std Error AIC, SBC Model_1 AR(1) 顯著 No 2.54 753.6, 756.7 Model_2 ARMA(1,1) 2.45 743.9, 753.2 Model_3 AR: B, B^6 MA: B AR_B 不顯著 Yes 2.336 729.5, 741.8 Model_4 AR: B^6 MA: B 2.330 726.7, 732.8 Model_5 AR: B MA: B^6 yes 2.440 741.4, 747.6 Model_6 MA: B,B^6 2.278 719.7, 725.9 選擇 Model 6為預測式
Step 3 預測式 Sample mean = 59.3
預測 – 未來10星期的預測區間 Forecasts for variable y Obs Forecast Std Error 95% Confidence Limits 162 83.1502 2.2797 78.6820 87.6184 163 84.6215 4.3242 76.1463 93.0967 164 84.1300 5.6745 73.0083 95.2517 165 82.7623 6.7602 69.5125 96.0121 166 81.8336 7.6943 66.7531 96.9141 167 81.0599 8.5266 64.3481 97.7718 168 9.0182 63.3846 98.7353 169 9.4843 62.4710 99.6489 170 9.9286 61.6002 100.5197 171 10.3539 60.7667 101.3532