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(133.91,133.14,135.31,133.09,135.39,131.85,130.25,127.65,118.30,119.73,122.51,123.28,133.52,153.20,163.63,168.45,166.26,162.31,161.56,156.59,157.97,158.68,163.55,162.89,164.95,159.82,159.05,166.76,164.55,163.22,160.68,155.24,157.60,156.56,154.82,151.11,149.65,148.99,148.53,146.70,145.11,142.70,143.59,140.96,140.77,139.81,140.58,139.59,138.05,136.06,135.98,134.75,132.22,135.37,138.84,138.83,136.55,135.63,139.14,136.09) > x <- c(1.4816,1.4562,1.4268,1.4088,1.4016,1.3650,1.3190,1.3050,1.2785,1.3239,1.3449,1.2732,1.3322,1.4369,1.4975,1.5770,1.5553,1.5557,1.5750,1.5527,1.4748,1.4718,1.4570,1.4684,1.4227,1.3896,1.3622,1.3716,1.3419,1.3511,1.3516,1.3242,1.3074,1.2999,1.3213,1.2881,1.2611,1.2727,1.2811,1.2684,1.2650,1.2770,1.2271,1.2020,1.1938,1.2103,1.1856,1.1786,1.2015,1.2256,1.2292,1.2037,1.2165,1.2694,1.2938,1.3201,1.3014,1.3119,1.3408,1.2991) > par8 = '3' > par7 = '0' > par6 = '0' > par5 = '1' > par4 = '12' > par3 = '0' > par2 = '0' > 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] 0.4816 0.4562 0.4268 0.4088 0.4016 0.3650 0.3190 0.3050 0.2785 0.3239 [11] 0.3449 0.2732 0.3322 0.4369 0.4975 0.5770 0.5553 0.5557 0.5750 0.5527 [21] 0.4748 0.4718 0.4570 0.4684 0.4227 0.3896 0.3622 0.3716 0.3419 0.3511 [31] 0.3516 0.3242 0.3074 0.2999 0.3213 0.2881 0.2611 0.2727 0.2811 0.2684 [41] 0.2650 0.2770 0.2271 0.2020 0.1938 0.2103 0.1856 0.1786 0.2015 0.2256 [51] 0.2292 0.2037 0.2165 0.2694 0.2938 0.3201 0.3014 0.3119 0.3408 0.2991 > y [1] 132.91 132.14 134.31 132.09 134.39 130.85 129.25 126.65 117.30 118.73 [11] 121.51 122.28 132.52 152.20 162.63 167.45 165.26 161.31 160.56 155.59 [21] 156.97 157.68 162.55 161.89 163.95 158.82 158.05 165.76 163.55 162.22 [31] 159.68 154.24 156.60 155.56 153.82 150.11 148.65 147.99 147.53 145.70 [41] 144.11 141.70 142.59 139.96 139.77 138.81 139.58 138.59 137.05 135.06 [51] 134.98 133.75 131.22 134.37 137.84 137.83 135.55 134.63 138.14 135.09 > (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 50 2 53 -3 1.931 0.1366 > (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 50 2 53 -3 3.2243 0.03025 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/13iha1260534687.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.454 0.482 0.475 0.451 0.436 0.421 0.400 0.402 0.424 0.449 0.466 -3 -2 -1 0 1 2 3 4 5 6 7 0.484 0.501 0.520 0.518 0.470 0.386 0.272 0.132 -0.001 -0.131 -0.247 8 9 10 11 12 13 14 -0.337 -0.419 -0.483 -0.528 -0.577 -0.610 -0.619 > (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.454 0.482 0.475 0.451 0.436 0.421 0.400 0.402 0.424 0.449 0.466 -3 -2 -1 0 1 2 3 4 5 6 7 0.484 0.501 0.520 0.518 0.470 0.386 0.272 0.132 -0.001 -0.131 -0.247 8 9 10 11 12 13 14 -0.337 -0.419 -0.483 -0.528 -0.577 -0.610 -0.619 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/24pes1260534687.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/3jz4y1260534687.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/4wenl1260534687.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/5uwh21260534688.tab") > system("convert tmp/13iha1260534687.ps tmp/13iha1260534687.png") > system("convert tmp/24pes1260534687.ps tmp/24pes1260534687.png") > system("convert tmp/3jz4y1260534687.ps tmp/3jz4y1260534687.png") > > > proc.time() user system elapsed 0.953 0.496 4.459