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(0.8833,0.87,0.8758,0.8858,0.917,0.9554,0.9922,0.9778,0.9808,0.9811,1.0014,1.0183,1.0622,1.0773,1.0807,1.0848,1.1582,1.1663,1.1372,1.1139,1.1222,1.1692,1.1702,1.2286,1.2613,1.2646,1.2262,1.1985,1.2007,1.2138,1.2266,1.2176,1.2218,1.249,1.2991,1.3408,1.3119,1.3014,1.3201,1.2938,1.2694,1.2165,1.2037,1.2292,1.2256,1.2015,1.1786,1.1856,1.2103,1.1938,1.202,1.2271,1.277,1.265,1.2684,1.2811,1.2727,1.2611,1.2881,1.3213) > x <- c(902.2,891.9,874,930.9,944.2,935.9,937.1,885.1,892.4,987.3,946.3,799.6,875.4,846.2,880.6,885.7,868.9,882.5,789.6,773.3,804.3,817.8,836.7,721.8,760.8,841.4,1045.6,949.2,850.1,957.4,851.8,913.9,888,973.8,927.6,833,879.5,797.3,834.5,735.1,835,892.8,697.2,821.1,732.7,797.6,866.3,826.3,778.6,779.2,951,692.3,841.4,857.3,760.7,841.2,810.3,1007.4,931.3,931.2) > par8 = '3' > par7 = '0' > par6 = '1' > par5 = '1' > par4 = '12' > par3 = '0' > 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#output/ > #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] -10.3 -17.9 56.9 13.3 -8.3 1.2 -52.0 7.3 94.9 -41.0 [11] -146.7 75.8 -29.2 34.4 5.1 -16.8 13.6 -92.9 -16.3 31.0 [21] 13.5 18.9 -114.9 39.0 80.6 204.2 -96.4 -99.1 107.3 -105.6 [31] 62.1 -25.9 85.8 -46.2 -94.6 46.5 -82.2 37.2 -99.4 99.9 [41] 57.8 -195.6 123.9 -88.4 64.9 68.7 -40.0 -47.7 0.6 171.8 [51] -258.7 149.1 15.9 -96.6 80.5 -30.9 197.1 -76.1 -0.1 > y [1] -0.0133 0.0058 0.0100 0.0312 0.0384 0.0368 -0.0144 0.0030 0.0003 [10] 0.0203 0.0169 0.0439 0.0151 0.0034 0.0041 0.0734 0.0081 -0.0291 [19] -0.0233 0.0083 0.0470 0.0010 0.0584 0.0327 0.0033 -0.0384 -0.0277 [28] 0.0022 0.0131 0.0128 -0.0090 0.0042 0.0272 0.0501 0.0417 -0.0289 [37] -0.0105 0.0187 -0.0263 -0.0244 -0.0529 -0.0128 0.0255 -0.0036 -0.0241 [46] -0.0229 0.0070 0.0247 -0.0165 0.0082 0.0251 0.0499 -0.0120 0.0034 [55] 0.0127 -0.0084 -0.0116 0.0270 0.0332 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:3) + Lags(, 1:3) Model 2: ~ Lags(, 1:3) Res.Df Df F Pr(>F) 1 49 2 52 -3 1.4438 0.2414 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:3) + Lags(, 1:3) Model 2: ~ Lags(, 1:3) Res.Df Df F Pr(>F) 1 49 2 52 -3 0.452 0.717 > postscript(file="/var/www/html/rcomp/tmp/1pq3b1260549969.ps",horizontal=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 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -0.163 -0.150 -0.138 -0.147 -0.155 -0.079 -0.126 -0.144 -0.177 -0.229 -0.230 -3 -2 -1 0 1 2 3 4 5 6 7 -0.249 -0.225 -0.272 -0.275 -0.254 -0.244 -0.246 -0.245 -0.213 -0.210 -0.200 8 9 10 11 12 13 14 -0.161 -0.115 -0.041 -0.033 -0.065 -0.063 -0.069 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 0.046 -0.041 0.028 -0.005 -0.158 0.222 0.060 0.090 -0.039 -0.131 0.040 -3 -2 -1 0 1 2 3 4 5 6 7 0.043 0.208 -0.186 -0.101 0.046 0.021 0.102 -0.109 0.114 -0.026 -0.240 8 9 10 11 12 13 14 0.008 0.093 0.203 -0.145 0.020 -0.030 -0.115 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2sjhq1260549969.ps",horizontal=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/3eqw51260549969.ps",horizontal=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/4j9mz1260549969.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/5bsap1260549969.tab") > > system("convert tmp/1pq3b1260549969.ps tmp/1pq3b1260549969.png") > system("convert tmp/2sjhq1260549969.ps tmp/2sjhq1260549969.png") > system("convert tmp/3eqw51260549969.ps tmp/3eqw51260549969.png") > > > proc.time() user system elapsed 0.947 0.503 2.108