Last active
January 27, 2017 09:31
-
-
Save explodecomputer/16502f14ae04abdd832d to your computer and use it in GitHub Desktop.
Granger causality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lmtest) | |
data(ChickEgg) | |
chickegg <- as.data.frame(ChickEgg) | |
chickegg$Year <- 1:nrow(chickegg) + 1929 | |
attach(chickegg) | |
library(forecast) | |
ndiffs(chicken, alpha=0.05, test=c("kpss")) | |
ndiffs(egg, alpha=0.05, test=c("kpss")) | |
dchick <- diff(chicken) | |
degg <- diff(egg) | |
plot.ts(dchick) | |
plot.ts(degg) | |
grangertest(dchick ~ degg, order=) | |
Find_Max_CCF<- function(a,b) | |
{ | |
d <- ccf(a, b, plot = FALSE) | |
cor = d$acf[,,1] | |
lag = d$lag[,,1] | |
res = data.frame(cor,lag) | |
res_max = res[which.max(res$cor),] | |
return(res_max) | |
} | |
Find_Max_CCF(dchick, degg) | |
library(vars) | |
data(Canada) | |
var.2c <- VAR(Canada, p = 2, type = "const") | |
a <- causality(var.2c, cause = "e") | |
name | |
#use a robust HC variance-covariance matrix for the Granger test: | |
causality(var.2c, cause = "e", vcov.=vcovHC(var.2c)) | |
#use a wild-bootstrap procedure to for the Granger test | |
causality(var.2c, cause = "e", boot=TRUE, boot.runs=1000)## End(Not run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
I have a question, can we have Nonlinear Granger causality Codes according to this?