R version 2.8.0 (2008-10-20) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > y <- c(43880,43110,44496,44164,40399,36763,37903,35532,35533,32110,33374,35462,33508,36080,34560,38737,38144,37594,36424,36843,37246,38661,40454,44928,48441,48140,45998,47369,49554,47510,44873,45344,42413,36912,43452,42142,44382,43636,44167,44423,42868,43908,42013,38846,35087,33026,34646,37135,37985,43121,43722,43630,42234,39351,39327,35704,30466,28155,29257,29998,32529,34787,33855,34556,31348,30805,28353,24514,21106,21346,23335,24379,26290,30084,29429,30632,27349,27264,27474,24482,21453,18788,19282,19713,21917,23812,23785,24696,24562,23580,24939,23899,21454,19761,19815,20780,23462,25005,24725,26198,27543,26471,26558,25317,22896,22248,23406,25073,27691,30599,31948,32946,34012,32936,32974,30951,29812,29010,31068,32447,34844,35676,35387,36488,35652,33488,32914,29781,27951) > x <- c(211868,229527,229139,198563,195722,202196,205816,212588,214320,220375,204442,206903,214126,226899,223532,195309,186005,188906,191563,189226,186413,178037,166827,169362,174330,187069,186530,158114,151001,159612,161914,164182,169701,171297,166444,173476,182516,202388,202300,168053,167302,172608,178106,185686,194581,194596,197922,208795,230580,240636,240048,211457,211142,214771,212610,219313,219277,231805,229245,241114,248624,265845,256446,219452,217142,221678,227184,230354,235243,237217,233575,244460,243324,260307,241476,203666,200237,204045,209465,213586,216234,213188,208679,217859,227247,243477,232571,191531,186029,189733,190420,194163,198770,195198,193111,195411,202108,215706,206348,166972,166070,169292,175041,177876,181140,179566,175335,184128,189917,194690,179612,150605,150569,153745,155511,159044,163095,159585,158644,166618,176512,200765,182698,153730,156145,161570,165688,173666,180144) > par8 = '5' > par7 = '1' > par6 = '1' > par5 = '1' > par4 = '12' > par3 = '1' > par2 = '1' > par1 = '1' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2008), Bivariate Granger Causality (v1.0.0) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_grangercausality.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: > library(lmtest) Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from package:base : as.Date.numeric > par1 <- as.numeric(par1) > par2 <- as.numeric(par2) > par3 <- as.numeric(par3) > par4 <- as.numeric(par4) > par5 <- as.numeric(par5) > par6 <- as.numeric(par6) > par7 <- as.numeric(par7) > par8 <- as.numeric(par8) > ox <- x > oy <- y > if (par1 == 0) { + x <- log(x) + } else { + x <- (x ^ par1 - 1) / par1 + } > if (par5 == 0) { + y <- log(y) + } else { + y <- (y ^ par5 - 1) / par5 + } > if (par2 > 0) x <- diff(x,lag=1,difference=par2) > if (par6 > 0) y <- diff(y,lag=1,difference=par6) > if (par3 > 0) x <- diff(x,lag=par4,difference=par3) > if (par7 > 0) y <- diff(y,lag=par4,difference=par7) > x [1] -4886 -2979 2353 -6463 -3573 -963 -9109 -4545 -14431 4723 [11] 74 -2255 -34 2828 -193 2191 5710 -355 4605 8332 [21] 9972 6357 4497 4072 7133 451 -5831 6362 -3305 3196 [31] 5312 3376 -1581 8179 3841 12745 -9816 -500 5656 436 [41] -1677 -7659 -877 -8931 12513 -5886 996 -14275 7165 -8811 [51] -8403 -1995 907 7667 -3533 4925 -10554 -1082 -984 -8646 [61] -238 -9432 -816 -1119 -728 -86 951 -2241 -5020 -867 [71] -1705 10524 -753 7925 -3230 -2073 -104 -4733 -378 1959 [81] -526 2422 -6880 -2691 -2632 1548 1664 4600 -482 5062 [91] -908 -1343 1998 -2144 6493 -908 -8825 -5720 10369 866 [101] -46 -3983 698 787 -1936 3290 -819 4105 19480 -2989 [111] 39 2451 2249 2352 4445 2427 > y [1] 3342 -2906 4509 3172 3086 -2310 2790 402 4838 529 2386 5467 [13] -2873 -622 -2806 2778 -1494 -1467 52 -3334 -6916 4747 -5784 -1273 [25] -445 2673 -1115 -3740 3084 742 -3638 -828 3440 -4920 3799 -1390 [37] 5882 70 -348 159 -3923 1871 -456 -1479 -250 -518 -1748 1681 [49] -2878 -1533 793 -1812 2340 -2428 -216 1830 2551 887 303 -620 [61] 1536 277 502 -75 458 2662 847 379 -2905 -1495 -613 293 [73] -1899 628 -292 3149 -897 1149 1952 584 972 -440 534 478 [85] -352 -253 562 1479 -90 -1272 -201 24 1045 1104 702 -64 [97] 1365 1629 -475 -279 -4 -49 -782 1282 -154 900 -288 -221 [109] -2076 -1638 103 -1902 -1088 -612 -1110 -691 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:5) + Lags(, 1:5) Model 2: ~ Lags(, 1:5) Res.Df Df F Pr(>F) 1 100 2 105 -5 0.3778 0.8629 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:5) + Lags(, 1:5) Model 2: ~ Lags(, 1:5) Res.Df Df F Pr(>F) 1 100 2 105 -5 1.6505 0.1537 > postscript(file="/var/www/html/freestat/rcomp/tmp/1z3wl1291971399.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,1)) > (r <- ccf(ox,oy,main='Cross Correlation Function (raw data)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series ‘X’, by lag -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -0.385 -0.331 -0.313 -0.324 -0.342 -0.377 -0.416 -0.449 -0.490 -0.513 -0.504 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 -0.459 -0.372 -0.296 -0.255 -0.240 -0.226 -0.235 -0.251 -0.263 -0.288 -0.286 4 5 6 7 8 9 10 11 12 13 14 -0.239 -0.145 -0.021 0.079 0.138 0.171 0.193 0.197 0.192 0.183 0.166 15 16 17 18 0.168 0.212 0.292 0.393 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series ‘X’, by lag -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 0.010 0.083 -0.068 0.069 -0.051 0.249 -0.055 -0.089 -0.016 0.003 -0.053 -6 -5 -4 -3 -2 -1 0 1 2 3 4 -0.027 -0.074 -0.067 -0.160 -0.066 -0.017 -0.369 -0.009 -0.166 0.000 -0.271 5 6 7 8 9 10 11 12 13 14 15 -0.109 0.042 -0.034 0.027 -0.026 0.195 -0.127 0.217 -0.091 0.207 -0.156 16 17 0.247 0.083 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/freestat/rcomp/tmp/2suvn1291971399.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,1)) > acf(ox,lag.max=round(length(x)/2),main='ACF of x (raw)') > acf(x,lag.max=round(length(x)/2),main='ACF of x (transformed and differenced)') > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/freestat/rcomp/tmp/3suvn1291971399.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,1)) > acf(oy,lag.max=round(length(y)/2),main='ACF of y (raw)') > acf(y,lag.max=round(length(y)/2),main='ACF of y (transformed and differenced)') > par(op) > dev.off() null device 1 > > #Note: the /var/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Granger Causality Test: Y = f(X)',5,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Model',header=TRUE) > a<-table.element(a,'Res.DF',header=TRUE) > a<-table.element(a,'Diff. DF',header=TRUE) > a<-table.element(a,'F',header=TRUE) > a<-table.element(a,'p-value',header=TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Complete model',header=TRUE) > a<-table.element(a,gyx$Res.Df[1]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Reduced model',header=TRUE) > a<-table.element(a,gyx$Res.Df[2]) > a<-table.element(a,gyx$Df[2]) > a<-table.element(a,gyx$F[2]) > a<-table.element(a,gyx$Pr[2]) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/html/freestat/rcomp/tmp/46mbw1291971399.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Granger Causality Test: X = f(Y)',5,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Model',header=TRUE) > a<-table.element(a,'Res.DF',header=TRUE) > a<-table.element(a,'Diff. DF',header=TRUE) > a<-table.element(a,'F',header=TRUE) > a<-table.element(a,'p-value',header=TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Complete model',header=TRUE) > a<-table.element(a,gxy$Res.Df[1]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Reduced model',header=TRUE) > a<-table.element(a,gxy$Res.Df[2]) > a<-table.element(a,gxy$Df[2]) > a<-table.element(a,gxy$F[2]) > a<-table.element(a,gxy$Pr[2]) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/html/freestat/rcomp/tmp/594r21291971399.tab") > > try(system("convert tmp/1z3wl1291971399.ps tmp/1z3wl1291971399.png",intern=TRUE)) character(0) > try(system("convert tmp/2suvn1291971399.ps tmp/2suvn1291971399.png",intern=TRUE)) character(0) > try(system("convert tmp/3suvn1291971399.ps tmp/3suvn1291971399.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.433 0.661 1.583