R version 2.9.0 (2009-04-17) Copyright (C) 2009 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. 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(14.36,14.62,13.51,14.95,16.72,16.33,15.21,16.69,15.81,16.02,16.7,15.99,17.68,18.89,18.72,21.14,20.97,23.75,23.05,23.45,21.74,19.37,21.1,21.2,22.67,22.24,23.78,23.27,25.74,26.1,27.49,31.41,28.79,26.76,26.41,27.05,29.43,32.1,36.84,34.22,36.53,40.99,45.97,43.6,47.84,51.47,51.31,48.47,48.28,46.56,43.83,51.17,49.59,49.11,49.97,50.07,53.3,57.08,68.54,71.62,67.64,64.79,80.97,88.42,110.22,99,95.95,107.94,97.82,111.64,114.73,117.58,99.19,90.19,59.74,44.51,23.94,21.29,20.77,25.07,32.95,40.05,44.59,40.28,41.19,38.14,41.85,43.76,50.16,52.94,47.69,51.52,58.69,50.44,45.72,43.24,51.49,50.43,58.73,65.12,64.13) > x <- c(54.64,52.39,52.51,52.92,55.22,55.41,57.02,58.55,57.49,55.52,57.84,58.69,59.74,60.7,60.74,64.32,66.9,70.93,75.89,80.6,81.39,81.33,77.04,79.54,81.93,80.79,81.98,85.94,86.6,87.42,93.14,95.76,99.75,97.71,94.99,96.41,96.28,100.14,99.9,102.87,107.37,115.68,124.33,128.44,130.19,148.4,169.14,153.98,163.13,165.4,166.35,173.73,174.23,177.04,170.78,174.01,183.76,201.95,205.38,197.36,196.53,179.94,174.84,179.86,172.77,162.56,178.4,190.83,201.07,198.95,190.46,186.27,187.96,174.99,164.1,131.48,116.14,103.43,96.87,93.68,96.49,105.22,110.11,118.47,122.15,137.35,134.83,138.34,141.98,149.45,154.68,145.98,156.33,176.28,159.08,151.18,162.63,174.2,180.51,185.31,186.33) > par8 = '5' > par7 = '0' > par6 = '1' > par5 = '0.0' > par4 = '12' > par3 = '0' > par2 = '1' > par1 = '0.0' > #'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] -0.0420504818 0.0022878942 0.0077777116 0.0425438673 0.0034348764 [6] 0.0286420006 0.0264790066 -0.0182700704 -0.0348677034 0.0409372617 [11] 0.0145887767 0.0177324582 0.0159418853 0.0006587616 0.0572681653 [16] 0.0393283423 0.0584945081 0.0675914482 0.0602137261 0.0097537658 [21] -0.0007374632 -0.0541901847 0.0319352723 0.0296051844 -0.0140120287 [26] 0.0146221196 0.0471740633 0.0076504372 0.0094242739 0.0633796481 [31] 0.0277413237 0.0408219945 -0.0206631478 -0.0282322851 0.0148383078 [36] -0.0013493178 0.0393085940 -0.0023995212 0.0292963695 0.0428147583 [41] 0.0745469450 0.0721115626 0.0325225483 0.0135330527 0.1309164088 [46] 0.1308154436 -0.0939040505 0.0577247051 0.0138193536 0.0057272199 [51] 0.0434083674 0.0028738955 0.0159994303 -0.0359995173 0.0187365903 [56] 0.0545177896 0.0943895836 0.0168417798 -0.0398324495 -0.0042143808 [61] -0.0881916294 -0.0287521920 0.0283075005 -0.0402175403 -0.0609140658 [66] 0.0929810558 0.0673547592 0.0522701268 -0.0105995693 -0.0436113381 [71] -0.0222449647 0.0090319402 -0.0715003448 -0.0642528313 -0.2216212493 [76] -0.1240583889 -0.1159013046 -0.0655251820 -0.0334851541 0.0295546567 [81] 0.0866140203 0.0454264698 0.0731798978 0.0305900337 0.1172826148 [86] -0.0185176869 0.0256996975 0.0259717794 0.0512756861 0.0343965780 [91] -0.0578888407 0.0684995316 0.1201044824 -0.1026664196 -0.0509360405 [96] 0.0730065021 0.0687263825 0.0355821135 0.0262439205 0.0054891969 > y [1] 0.017943891 -0.078960302 0.101281148 0.111894308 -0.023601701 [6] -0.071050801 0.092856631 -0.054167086 0.013195290 0.041570778 [11] -0.043445193 0.100470530 0.066198624 -0.009040210 0.121574509 [16] -0.008074136 0.124489686 -0.029916761 0.017204725 -0.075716613 [21] -0.115428404 0.085547563 0.004728141 0.067041283 -0.019149995 [26] 0.066952422 -0.021679914 0.100881225 0.013889112 0.051886988 [31] 0.133304011 -0.087098209 -0.073119869 -0.013165509 0.023944279 [36] 0.084327557 0.086841468 0.137728181 -0.073773943 0.065323572 [41] 0.115194294 0.114660875 -0.052931859 0.092804959 0.073137004 [46] -0.003113449 -0.056940615 -0.003927654 -0.036275593 -0.060423289 [51] 0.154834908 -0.031364222 -0.009726520 0.017360145 0.001999201 [56] 0.062514305 0.068517461 0.182963724 0.043956848 -0.057174841 [61] -0.043048254 0.222927445 0.088019473 0.220380180 -0.107358518 [66] -0.031292628 0.117748295 -0.098446462 0.132150354 0.027302133 [71] 0.024537411 -0.170081750 -0.095118647 -0.411916743 -0.294287930 [76] -0.620163183 -0.117313221 -0.024727841 0.188162274 0.273319349 [81] 0.195137413 0.107380945 -0.101654551 0.022340441 -0.076931908 [86] 0.092828197 0.044628361 0.136497738 0.053941300 -0.104437464 [91] 0.077248349 0.130299273 -0.151484843 -0.098248672 -0.055769846 [96] 0.174621621 -0.020801378 0.152364433 0.103281052 -0.015319449 > (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 84 2 89 -5 1.9012 0.1027 > (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 84 2 89 -5 7.6546 5.732e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/1c0si1292786215.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 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 0.392 0.433 0.474 0.516 0.549 0.572 0.591 0.606 0.619 0.637 0.666 0.691 0.715 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 0.744 0.778 0.810 0.838 0.854 0.830 0.784 0.731 0.675 0.608 0.539 0.476 0.417 9 10 11 12 13 14 15 16 17 0.358 0.308 0.262 0.221 0.186 0.165 0.148 0.135 0.124 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 0.048 0.076 0.158 0.175 0.116 0.087 -0.054 -0.105 -0.145 0.000 -0.022 -5 -4 -3 -2 -1 0 1 2 3 4 5 -0.087 -0.170 0.041 0.016 0.309 0.390 0.554 0.289 0.193 0.247 0.065 6 7 8 9 10 11 12 13 14 15 16 -0.105 -0.174 -0.090 -0.153 -0.047 -0.108 -0.053 -0.179 -0.076 0.029 -0.072 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2c0si1292786215.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/rcomp/tmp/34ra31292786215.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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/rcomp/tmp/4q9qq1292786215.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/rcomp/tmp/5ta7w1292786215.tab") > > try(system("convert tmp/1c0si1292786215.ps tmp/1c0si1292786215.png",intern=TRUE)) character(0) > try(system("convert tmp/2c0si1292786215.ps tmp/2c0si1292786215.png",intern=TRUE)) character(0) > try(system("convert tmp/34ra31292786215.ps tmp/34ra31292786215.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.970 0.513 2.212