lecture 11
play

Lecture 11 Fitting ARIMA Models 10/10/2018 1 Model Fitting - PowerPoint PPT Presentation

Lecture 11 Fitting ARIMA Models 10/10/2018 1 Model Fitting Fitting ARIMA For an (, , ) model Requires that the data be stationary after differencing Handling is straight forward, just difference the


  1. Lecture 11 Fitting ARIMA Models 10/10/2018 1

  2. Model Fitting

  3. Fitting ARIMA For an 𝐡𝑆𝐽𝑁𝐡(π‘ž, 𝑒, π‘Ÿ) model β€’ Requires that the data be stationary after differencing β€’ Handling 𝑒 is straight forward, just difference the original data 𝑒 times (leaving π‘œ βˆ’ 𝑒 observations) 𝑧 β€² β€’ After differencing, fit an 𝐡𝑆𝑁𝐡(π‘ž, π‘Ÿ) model to 𝑧 β€² 𝑒 . β€’ To keep things simple we’ll assume π‘₯ 𝑒 𝑗𝑗𝑒 ∼ π’ͺ(0, 𝜏 2 π‘₯ ) 2 𝑒 = Ξ” 𝑒 𝑧 𝑒

  4. In general, the vector 𝐳 = (𝑧 1 , 𝑧 2 , … , 𝑧 𝑒 ) β€² will have a multivariate normal distribution with mean {𝝂} 𝑗 = 𝐹(𝑧 𝑗 ) = 𝐹(𝑧 𝑒 ) and covariance 𝚻 where {𝚻} π‘—π‘˜ = 𝛿(𝑗 βˆ’ π‘˜) . 2(𝐳 βˆ’ 𝝂) β€² Ξ£ βˆ’1 (𝐳 βˆ’ 𝝂)) (2𝜌) 𝑒/2 det (𝚻) 1/2 Γ— exp (βˆ’1 MLE - Stationarity & iid normal errors normal. The joint density of 𝐳 is given by 𝑔 𝐳 (𝐳) = 1 3 If both of these conditions are met, then the time series 𝑧 𝑒 will also be

  5. MLE - Stationarity & iid normal errors normal. The joint density of 𝐳 is given by 𝑔 𝐳 (𝐳) = 1 3 If both of these conditions are met, then the time series 𝑧 𝑒 will also be In general, the vector 𝐳 = (𝑧 1 , 𝑧 2 , … , 𝑧 𝑒 ) β€² will have a multivariate normal distribution with mean {𝝂} 𝑗 = 𝐹(𝑧 𝑗 ) = 𝐹(𝑧 𝑒 ) and covariance 𝚻 where {𝚻} π‘—π‘˜ = 𝛿(𝑗 βˆ’ π‘˜) . 2(𝐳 βˆ’ 𝝂) β€² Ξ£ βˆ’1 (𝐳 βˆ’ 𝝂)) (2𝜌) 𝑒/2 det (𝚻) 1/2 Γ— exp (βˆ’1

  6. AR

  7. Fitting 𝐡𝑆(1) π‘₯ π‘₯ . the MLE estimate for πœ€ , 𝜚 , and 𝜏 2 but that does not make it easy to write down a (simplified) closed form for Using these properties it is possible to write the distribution of 𝐳 as a MVN π‘₯ 𝜏 2 1 βˆ’ 𝜚 2 𝜏 2 π‘Š 𝑏𝑠(𝑧 𝑒 ) = 1 βˆ’ 𝜚 πœ€ 𝐹(𝑧 𝑒 ) = π‘₯ , we know We need to estimate three parameters: πœ€ , 𝜚 , and 𝜏 2 4 𝑧 𝑒 = πœ€ + 𝜚 𝑧 π‘’βˆ’1 + π‘₯ 𝑒 𝛿 β„Ž = 1 βˆ’ 𝜚 2 𝜚 |β„Ž|

  8. Conditional Density 𝑔 𝑧 𝑒 |𝑧 π‘’βˆ’1 (𝑧 𝑒 ) = ) π‘₯ 𝜏 2 2 exp (βˆ’1 π‘₯ √2𝜌 𝜏 2 1 π‘₯ ) We can also rewrite the density as follows, π‘₯ 𝜏 2 where, 5 𝑔 𝐳 = 𝑔 𝑧 𝑒 , 𝑧 π‘’βˆ’1 , …, 𝑧 2 , 𝑧 1 = 𝑔 𝑧 𝑒 | 𝑧 π‘’βˆ’1 , …, 𝑧 2 , 𝑧 1 𝑔 𝑧 π‘’βˆ’1 |𝑧 π‘’βˆ’2 , …, 𝑧 2 , 𝑧 1 β‹― 𝑔 𝑧 2 |𝑧 1 𝑔 𝑧 1 = 𝑔 𝑧 𝑒 | 𝑧 π‘’βˆ’1 𝑔 𝑧 π‘’βˆ’1 |𝑧 π‘’βˆ’2 β‹― 𝑔 𝑧 2 |𝑧 1 𝑔 𝑧 1 𝑧 1 ∼ π’ͺ (πœ€, 1 βˆ’ 𝜚 2 ) 𝑧 𝑒 |𝑧 π‘’βˆ’1 ∼ π’ͺ (πœ€ + 𝜚 𝑧 π‘’βˆ’1 , 𝜏 2 (𝑧 𝑒 βˆ’ πœ€ + 𝜚 𝑧 π‘’βˆ’1 ) 2

  9. Log likelihood of AR(1) 𝜏 2 𝑗=2 βˆ‘ π‘œ π‘₯ 𝜏 2 1 + 𝑗=2 βˆ‘ π‘œ π‘₯ 𝜏 2 1 π‘₯ 2((π‘œ βˆ’ 1) log 2𝜌 + (π‘œ βˆ’ 1) log 𝜏 2 6 β„“(πœ€, 𝜚, 𝜏 2 1 log 𝑔 𝑧 𝑗 |𝑧 π‘—βˆ’1 𝑗=2 βˆ‘ 𝑒 𝜏 2 π‘₯ log 𝑔 𝑧 𝑒 |𝑧 π‘’βˆ’1 (𝑧 𝑒 ) = βˆ’ 1 2 ( log 2𝜌 + log 𝜏 2 π‘₯ + (𝑧 𝑒 βˆ’ πœ€ + 𝜚 𝑧 π‘’βˆ’1 ) 2 ) π‘₯ ) = log 𝑔 𝐳 = log 𝑔 𝑧 1 + = βˆ’ 1 π‘₯ βˆ’ log (1 βˆ’ 𝜚 2 ) + (1 βˆ’ 𝜚 2 ) 2 ( log 2𝜌 + log 𝜏 2 (𝑧 1 βˆ’ πœ€) 2 ) βˆ’ 1 π‘₯ + (𝑧 𝑗 βˆ’ πœ€ + 𝜚 𝑧 π‘—βˆ’1 ) 2 ) = βˆ’ 1 2 (π‘œ log 2𝜌 + π‘œ log 𝜏 2 π‘₯ βˆ’ log (1 βˆ’ 𝜚 2 ) ((1 βˆ’ 𝜚 2 )(𝑧 1 βˆ’ πœ€) 2 + (𝑧 𝑗 βˆ’ πœ€ + 𝜚 𝑧 π‘—βˆ’1 ) 2 ))

  10. AR(1) Example with 𝜚 = 0.75 , πœ€ = 0.5 , and 𝜏 2 7 π‘₯ = 1 , ar1 4 2 0 βˆ’2 0 100 200 300 400 500 0.6 0.6 0.4 0.4 PACF ACF 0.2 0.2 0.0 0.0 0 5 10 15 20 25 0 5 10 15 20 25 Lag Lag

  11. Arima MAE BIC=1433.35 ## ## Training set error measures: ## ME RMSE MPE ## AIC=1420.71 MAPE MASE ## Training set 0.005333274 0.9950158 0.7997576 -984.9413 1178.615 0.9246146 ## ACF1 ## Training set -0.04437489 AICc=1420.76 log likelihood=-707.35 ar1_arima = forecast:: Arima (ar1, order = c (1,0,0)) ar1 summary (ar1_arima) ## Series: ar1 ## ARIMA(1,0,0) with non-zero mean ## ## Coefficients: ## mean ## sigma^2 estimated as 0.994: ## 0.7312 1.8934 ## s.e. 0.0309 0.1646 ## 8

  12. lm ## Signif. codes: 0.07328 7.144 3.25e-12 *** ## lag(y) 0.72817 0.03093 23.539 < 2e-16 *** ## --- 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## (Intercept) ## ## Residual standard error: 0.9949 on 497 degrees of freedom ## (1 observation deleted due to missingness) ## Multiple R-squared: 0.5272, Adjusted R-squared: 0.5262 ## F-statistic: 554.1 on 1 and 497 DF, p-value: < 2.2e-16 0.52347 Estimate Std. Error t value Pr(>|t|) d = data_frame (y = ar1 %>% strip_attrs (), t= seq_along (ar1)) ## summary (ar1_lm) ## ## Call: ## lm(formula = y ~ lag(y), data = d) ## ## Residuals: ## Min 1Q Median 3Q Max ## -3.2772 -0.6880 0.0785 0.6819 2.5704 ## ## Coefficients: 9 ar1_lm = lm (y~ lag (y), data=d)

  13. Bayesian AR(1) Model mu = delta/(1-phi) }” sigma2_w <- 1/tau tau ~ dgamma(0.001,0.001) phi ~ dnorm(0,1) delta ~ dnorm(0,1/1000) # priors } ar1_model = ”model{ y_hat[t] ~ dnorm(delta + phi*y[t-1], 1/sigma2_w) y[t] ~ dnorm(delta + phi*y[t-1], 1/sigma2_w) for (t in 2:length(y)) { y_hat[1] ~ dnorm(delta/(1-phi), (sigma2_w/(1-phi^2))^-1) y[1] ~ dnorm(delta/(1-phi), (sigma2_w/(1-phi^2))^-1) # likelihood 10

  14. Chains 11 0.7 0.6 delta 0.5 0.4 0.3 .variable 0.80 .value delta 0.75 phi phi 0.70 sigma2_w 0.65 1.2 1.1 sigma2_w 1.0 0.9 0.8 0 1000 2000 3000 4000 5000 .iteration

  15. Posteriors 12 delta phi sigma2_w 10 model density ARIMA lm truth 5 0 0.3 0.4 0.5 0.6 0.7 0.8 0.65 0.70 0.75 0.80 0.8 0.9 1.0 1.1 1.2

  16. Predictions 13 4 Model y 2 lm y ARIMA bayes 0 βˆ’2 0 100 200 300 400 500 t

  17. Faceted 14 y lm 4 2 0 Model βˆ’2 y lm y ARIMA bayes ARIMA bayes 4 2 0 βˆ’2 0 100 200 300 400 500 0 100 200 300 400 500 t

  18. Regressing 𝑧 𝑒 on 𝑧 π‘’βˆ’π‘ž , … , 𝑧 π‘’βˆ’1 gets us an approximate solution, but it Fitting AR(p) - Lagged Regression We can rewrite the density as follows, 𝑔(𝐳) = 𝑔(𝑧 𝑒 , 𝑧 π‘’βˆ’1 , … , 𝑧 2 , 𝑧 1 ) = 𝑔(𝑧 π‘œ |𝑧 π‘œβˆ’1 , … , 𝑧 π‘œβˆ’π‘ž ) β‹― 𝑔(𝑧 π‘ž+1 |𝑧 π‘ž , … , 𝑧 1 )𝑔(𝑧 π‘ž , … , 𝑧 1 ) ignores the 𝑔(𝑧 1 , 𝑧 2 , … , 𝑧 π‘ž ) part of the likelihood. How much does this matter (vs. using the full likelihood)? β€’ If π‘ž is near to π‘œ then probably a lot β€’ If π‘ž << π‘œ then probably not much 15

  19. Fitting AR(p) - Lagged Regression We can rewrite the density as follows, 𝑔(𝐳) = 𝑔(𝑧 𝑒 , 𝑧 π‘’βˆ’1 , … , 𝑧 2 , 𝑧 1 ) = 𝑔(𝑧 π‘œ |𝑧 π‘œβˆ’1 , … , 𝑧 π‘œβˆ’π‘ž ) β‹― 𝑔(𝑧 π‘ž+1 |𝑧 π‘ž , … , 𝑧 1 )𝑔(𝑧 π‘ž , … , 𝑧 1 ) ignores the 𝑔(𝑧 1 , 𝑧 2 , … , 𝑧 π‘ž ) part of the likelihood. How much does this matter (vs. using the full likelihood)? β€’ If π‘ž is near to π‘œ then probably a lot β€’ If π‘ž << π‘œ then probably not much 15 Regressing 𝑧 𝑒 on 𝑧 π‘’βˆ’π‘ž , … , 𝑧 π‘’βˆ’1 gets us an approximate solution, but it

  20. Fitting AR(p) - Method of Moments Recall for an AR(p) process, 𝛿(0) = 𝜏 2 𝛿(β„Ž) = 𝜚 1 𝛿(β„Ž βˆ’ 1) + 𝜚 2 𝛿(β„Ž βˆ’ 2) + … 𝜚 π‘ž 𝛿(β„Ž βˆ’ π‘ž) We can rewrite the first equation in terms of 𝜏 2 π‘₯ , 𝜏 2 these are called the Yule-Walker equations. 16 π‘₯ + 𝜚 1 𝛿(1) + 𝜚 2 𝛿(2) + … + 𝜚 π‘ž 𝛿(π‘ž) π‘₯ = 𝛿(0) βˆ’ 𝜚 1 𝛿(1) βˆ’ 𝜚 2 𝛿(2) βˆ’ … βˆ’ 𝜚 π‘ž 𝛿(π‘ž)

  21. 𝜹 π‘ž which π‘₯ = 𝛿(0) βˆ’ Yule-Walker Μ‚ Μ‚ can plug in and solve for 𝝔 and 𝜏 2 π‘₯ , Μ‚ 𝝔 = Μ‚ 𝚫 π‘ž βˆ’1 𝜹 π‘ž = (𝛿(1), 𝛿(2), … , 𝛿(π‘ž)) β€² 𝜏 2 Μ‚ 𝜹 π‘ž β€² Μ‚ 𝚫 βˆ’1 π‘ž Μ‚ 𝜹 π‘ž If we estimate the covariance structure from the data we obtain π‘žΓ—1 These equations can be rewritten into matrix notation as follows 1Γ—1 𝚫 π‘ž π‘žΓ—π‘ž 𝝔 π‘žΓ—1 = 𝜹 π‘ž π‘žΓ—1 𝜏 2 π‘₯ 1Γ—1 = 𝛿(0) βˆ’ 𝝔 β€² 𝜹 π‘ž 1Γ—π‘ž 𝜹 πͺ π‘žΓ—1 where 𝚫 πͺ π‘žΓ—π‘ž = {𝛿(π‘˜ βˆ’ 𝑙)} π‘˜,𝑙 𝝔 π‘žΓ—1 = (𝜚 1 , 𝜚 2 , … , 𝜚 π‘ž ) β€² 17

  22. Yule-Walker Μ‚ If we estimate the covariance structure from the data we obtain Μ‚ can plug in and solve for 𝝔 and 𝜏 2 π‘₯ , Μ‚ 𝝔 = Μ‚ 𝚫 π‘ž βˆ’1 𝜹 π‘ž These equations can be rewritten into matrix notation as follows 𝜏 2 Μ‚ 𝜹 π‘ž β€² Μ‚ 𝚫 βˆ’1 π‘ž Μ‚ 𝜹 π‘ž = (𝛿(1), 𝛿(2), … , 𝛿(π‘ž)) β€² π‘žΓ—1 𝜹 π‘ž = (𝜚 1 , 𝜚 2 , … , 𝜚 π‘ž ) β€² 𝚫 π‘ž π‘žΓ—π‘ž 𝝔 π‘žΓ—1 = 𝜹 π‘ž π‘žΓ—1 𝜏 2 π‘₯ 1Γ—1 = 𝛿(0) 1Γ—1 βˆ’ 𝝔 β€² 1Γ—π‘ž 𝜹 πͺ π‘žΓ—1 where 𝚫 πͺ π‘žΓ—π‘ž = {𝛿(π‘˜ βˆ’ 𝑙)} π‘˜,𝑙 𝝔 π‘žΓ—1 17 𝜹 π‘ž which π‘₯ = 𝛿(0) βˆ’

  23. ARMA

Recommend


More recommend