Wednesday, November 7, 2012

Granger Causality Testing in R

Today just gets better and better!

I had an email this morning from Christoph Pfeiffer, who follows this blog. Christoph has put together some nice R code that implements the Toda-Yamamoto method for testing for Granger causality in the context of non-stationary time-series data.

Given the ongoing interest in the various posts I have had (here, here, here & here) on testing for Granger causality, I'm sure that Christoph's code will be of great interest to a lot of readers.

Thanks for sharing this with us, Christoph.


© 2012, David E. Giles

4 comments:

  1. For what it's worth, it easier and more flexible to carry out the analysis in R using the VAR package and its causality tests. The EViews analysis can be matched exactly by using exogen option for the lag 7 variables. The only tricky bit is making sure that a proper matching sample is used. When the bootstrapping or voc.=vcovHC options are used, Granger causality is rejected for both variables at any reasonable significance level.

    ReplyDelete
  2. Dear Mr. Giles,

    The number of parameters to be tested in the Wald-test has the same number as the lags. So if we create an even and an odd sequence in the R-code it will be quite automatic.

    Like:
    waldtest1<-wald.test(b=coef(V$varresult[[1]]), Sigma=vcov(V$varresult[[1]]), Terms=c(seq(2, by=2, length=lag)))
    waldtest2<-wald.test(b=coef(V$varresult[[2]]), Sigma=vcov(V$varresult[[2]]), Terms=c(seq(1, by=2, length=lag)))

    I guess it needs a supervision but worked well for me.

    Best Regards,
    János

    ReplyDelete

Note: Only a member of this blog may post a comment.