Chapter 2. Multivariate Analysis of Stationary Time Series

1,058 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,058
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Chapter 2. Multivariate Analysis of Stationary Time Series

  1. 1. Chapter 2. Multivariate Analysis of Stationary Time Series Cheng-Jun Wang
  2. 2. Contents
  3. 3. w No 2000s C M VE 1990sHistory e r & ng Gr a tion gra tion Inte tegra in Co 1987 Sim R VA 1980
  4. 4. VAR
  5. 5. Matrix Multiplicationhttp://en.wikipedia.org/wiki/Matrix_multiplication
  6. 6. Matrix Addition
  7. 7. R Code 2.1 Simulation of Var (2)-process## Simulate VAR(2)-data ## Obtaining the generated serieslibrary(dse1) vardat <- matrix(varsim$output, nrow = 500, ncol = 2)library(vars) colnames(vardat) <- c("y1", "y2")## Setting the lag-polynomial A(L)Apoly <- array(c(1.0, -0.5, 0.3, 0, ## Plotting the series 0.2, 0.1, 0, -0.2, plot.ts(vardat, main = "", xlab = "") 0.7, 1, 0.5, -0.3) , ## Determining an appropriate lag-order c(3, 2, 2)) infocrit <- VARselect(vardat, lag.max = 3,## Setting Covariance to identity-matrix type = "const")B <- diag(2)## Setting constant term to 5 and 10 ## Estimating the modelTRD <- c(5, 10) varsimest <- VAR(vardat, p = 2, type = "const",## Generating the VAR(2) model season = NULL, exogen = NULL)var2 <- ARMA(A = Apoly, B = B, TREND = TRD) ## Alternatively, selection according to AIC## Simulating 500 observations varsimest <- VAR(vardat, type = "const",varsim <- simulate(var2, sampleT = 500, lag.max = 3, ic = "SC") noise = list(w = matrix(rnorm(1000),nrow = 500, ncol = 2)), rng = list(seed = c(123456))) ## Checking the roots roots <- roots(varsimest)
  8. 8. R Code 2.2 Diagnostic tests of VAR(2)-process∗ ## testing serial correlation ∗ ## class and methods for diganostic tests∗ args(serial.test)∗ ## Portmanteau-Test ∗ class(var2c.serial)∗ var2c.serial <- serial.test(varsimest, lags.pt = 16, ∗ class(var2c.arch)∗ type = "PT.asymptotic")∗ var2c.serial ∗ class(var2c.norm)∗ plot(var2c.serial, names = "y1") ∗ methods(class = "varcheck")∗ plot(var2c.serial, names = "y2")∗ ## testing heteroscedasticity ∗ ## Plot of objects "varcheck"∗ args(arch.test) ∗ args(vars:::plot.varcheck)∗∗ var2c.arch <- arch.test(varsimest, lags.multi = 5, ∗ plot(var2c.serial, names = "y1") multivariate.only = TRUE)∗ var2c.arch ∗ ## Structural stability test∗ ## testing for normality ∗ reccusum <- stability(varsimest,∗ args(normality.test)∗ var2c.norm <- normality.test(varsimest, ∗ type = "OLS-CUSUM")∗ multivariate.only = TRUE) ∗ fluctuation <- stability(varsimest,∗ var2c.norm ∗ type = "fluctuation")
  9. 9. Causality Analysis∗ Granger causality∗ Wald-type instantaneous causality
  10. 10. ∗ ## Causality tests∗ ## Granger and instantaneous causality∗ var.causal <- causality(varsimest, cause = "y2")
  11. 11. Forecasting ∗ ## Forecasting objects of class varest ∗ args(vars:::predict.varest) ∗ predictions <- predict(varsimest, n.ahead = 25, ∗ ci = 0.95) ∗ class(predictions) ∗ args(vars:::plot.varprd) ∗ ## Plot of predictions for y1 ∗ plot(predictions, names = "y1") ∗ ## Fanchart for y2 ∗ args(fanchart) ∗ fanchart(predictions, names = "y2")
  12. 12. Impulse Response Function∗ Causality test falls short of quantifying the impact of the impulse variable on the response variable over time.∗ The impulse response analysis is used to investigate these kinds of dynamic interactions between the endogenous variables and is based upon the Wold moving average representation of a VAR(p)-process.
  13. 13. ## Forecast error variance## Impulse response analysis decomposition∗ irf.y1 <- irf(varsimest, impulse = "y1", ∗ fevd.var2 <- fevd(varsimest,∗ response = "y2", n.ahead = 10,∗ ortho = FALSE, cumulative = n.ahead = 10) FALSE, ∗ args(vars:::plot.varfevd)∗ boot = FALSE, seed = 12345)∗ args(vars:::plot.varirf) ∗ plot(fevd.var2, addbars = 2)∗ plot(irf.y1)∗ irf.y2 <- irf(varsimest, impulse = "y2",∗ response = "y1", n.ahead = 10,∗ ortho = TRUE, cumulative = TRUE,∗ boot = FALSE, seed = 12345)∗ plot(irf.y2)
  14. 14. SVAR∗ An SVAR-model can be used to identify shocks and trace these out by employing IRA and/or FEVD through imposing restrictions on the matrices A and/or B.
  15. 15. SVAR: A-model∗ library(dse1) ∗ ## Obtaining the generated series∗ library(vars) ∗ svardat <- matrix(svarsim$output, nrow = 500, ncol =∗ ## A-model 2) ∗ colnames(svardat) <- c("y1", "y2")∗ Apoly <- array(c(1.0, -0.5, 0.3, 0.8, ∗ ## Estimating the VAR∗ 0.2, 0.1, -0.7, -0.2, ∗ varest <- VAR(svardat, p = 2, type = "none")∗ 0.7, 1, 0.5, -0.3) , ∗ ## Setting up matrices for A-model∗ c(3, 2, 2)) ∗ Amat <- diag(2)∗ ## Setting covariance to identity-matrix ∗ Amat[2, 1] <- NA∗ B <- diag(2) ∗ Amat[1, 2] <- NA∗ ## Generating the VAR(2) model ∗ ## Estimating the SVAR A-type by direct∗ svarA <- ARMA(A = Apoly, B = B) maximisation∗ ## Simulating 500 observations ∗ ## of the log-likelihood∗ svarsim <- simulate(svarA, sampleT = 500, ∗ args(SVAR) ∗ svar.A <- SVAR(varest, estmethod = "direct",∗ rng = list(seed = c(123456))) ∗ Amat = Amat, hessian = TRUE)
  16. 16. SVAR: B-model∗ library(dse1) ∗ ## Simulating 500 observations∗ library(vars) ∗ svarsim <- simulate(svarB, sampleT = 500,∗ ## B-model ∗ rng = list(seed = c(123456))) ∗ svardat <- matrix(svarsim$output, nrow = 500,∗ Apoly <- array(c(1.0, -0.5, 0.3, 0, ncol = 2)∗ 0.2, 0.1, 0, -0.2, ∗ colnames(svardat) <- c("y1", "y2")∗ 0.7, 1, 0.5, -0.3) , ∗ varest <- VAR(svardat, p = 2, type = "none")∗ c(3, 2, 2)) ∗ ## Estimating the SVAR B-type by scoring algorithm∗ ## Setting covariance to identity-matrix ∗ ## Setting up the restriction matrix and vector∗ B <- diag(2) ∗ ## for B-model∗ B[2, 1] <- -0.8 ∗ Bmat <- diag(2)∗ ## Generating the VAR(2) model ∗ Bmat[2, 1] <- NA∗ svarB <- ARMA(A = Apoly, B = B) ∗ svar.B <- SVAR(varest, estmethod = "scoring", ∗ Bmat = Bmat, max.iter = 200)
  17. 17. ## Impulse response analysis of ## FEVD analysis of SVAR B-type SVAR A-type model model∗ args(vars:::irf.svarest) ∗ args(vars:::fevd.svarest)∗ irf.svara <- irf(svar.A, impulse = ∗ fevd.svarb <- fevd(svar.B, n.ahead "y1", response = "y2", boot = = 5) FALSE) ∗ class(fevd.svarb)∗ args(vars:::plot.varirf) ∗ methods(class = "varfevd")∗ plot(irf.svara) ∗ plot(fevd.svarb)
  18. 18. 20121209

×