R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: i686-pc-linux-gnu (32-bit) 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(2.64,2.49,2.79,2.54,2.42,2.39,2.42,2.30,2.46,2.43,2.50,2.34,2.38,2.52,2.38,2.37,2.53,2.53,2.49,2.57,2.34,2.63,2.55,2.56,2.31,2.21,2.06,2.00,1.67,1.62,1.49,1.28,1.24,0.85,0.42,0.22,0.15,-0.06,-0.18,-0.46,-0.70,-1.09,-1.33,-1.41,-1.56,-1.56,-1.41,-1.39,-1.25,-1.23,-1.12,-0.98,-0.64,-0.41,-0.41,-0.23,-0.25,-0.40,-0.37,-0.37,-0.42,-0.33,-0.35,-0.23,-0.17,-0.17,0.05,0.10,0.26,0.68,0.91,1.15,1.21,1.23,1.36,1.39,1.50,1.54,1.55,1.52,1.68,1.52,1.60,1.50,1.62,1.88,1.93,1.86,1.65,1.86,1.88,1.98,2.04,2.14,2.00,1.89,1.76,1.64,1.62,1.69,1.63,1.53,1.54,1.50,1.33,1.26,1.18,1.27,1.27,1.09,0.94,0.88,0.94,0.87,0.81,0.65,0.52,0.33,0.12,-0.12,-0.30) > x <- c(14.20,18.40,16.60,14.60,17.70,9.90,5.50,13.60,5.90,3.90,6.20,6.30,3.70,6.30,3.70,5.60,8.70,10.10,13.10,10.20,2.40,5.90,4.30,6.40,5.10,7.60,5.00,6.20,2.90,2.90,-5.60,-12.70,-13.00,-15.00,-23.80,-24.00,-23.30,-35.50,-36.80,-57.10,-69.60,-83.50,-78.30,-72.30,-70.70,-56.00,-49.20,-48.40,-51.90,-51.90,-51.40,-36.90,-30.00,-17.90,-28.20,-22.80,-32.90,-50.10,-31.60,-43.90,-40.70,-36.40,-31.10,-28.80,-10.20,2.70,6.40,10.80,19.80,23.00,15.20,23.20,41.70,43.40,38.70,35.60,27.00,15.30,29.70,26.00,33.50,32.60,23.40,27.30,14.90,12.90,23.10,15.10,13.80,16.90,15.00,16.70,13.50,16.30,22.40,16.30,11.40,14.90,0.10,17.90,17.30,12.20,9.80,5.10,6.80,5.20,-2.70,2.00,-2.30,4.10,6.20,-7.10,-7.10,-9.70,-17.60,-19.60,-33.10,-47.90,-51.60,-61.90,-64.50) > par8 = '2' > par7 = '0' > par6 = '0' > par5 = '1' > par4 = '1' > par3 = '0' > par2 = '0' > par1 = '1' > par8 <- '2' > par7 <- '0' > par6 <- '0' > par5 <- '1' > par4 <- '1' > par3 <- '0' > par2 <- '0' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 () > #Author: root > #To cite this work: Wessa P., (2013), Bivariate Granger Causality (v1.0.3) 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 > # > library(lmtest) Loading required package: zoo Attaching package: 'zoo' The following object is masked from 'package:base': as.Date, 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] 13.2 17.4 15.6 13.6 16.7 8.9 4.5 12.6 4.9 2.9 5.2 5.3 [13] 2.7 5.3 2.7 4.6 7.7 9.1 12.1 9.2 1.4 4.9 3.3 5.4 [25] 4.1 6.6 4.0 5.2 1.9 1.9 -6.6 -13.7 -14.0 -16.0 -24.8 -25.0 [37] -24.3 -36.5 -37.8 -58.1 -70.6 -84.5 -79.3 -73.3 -71.7 -57.0 -50.2 -49.4 [49] -52.9 -52.9 -52.4 -37.9 -31.0 -18.9 -29.2 -23.8 -33.9 -51.1 -32.6 -44.9 [61] -41.7 -37.4 -32.1 -29.8 -11.2 1.7 5.4 9.8 18.8 22.0 14.2 22.2 [73] 40.7 42.4 37.7 34.6 26.0 14.3 28.7 25.0 32.5 31.6 22.4 26.3 [85] 13.9 11.9 22.1 14.1 12.8 15.9 14.0 15.7 12.5 15.3 21.4 15.3 [97] 10.4 13.9 -0.9 16.9 16.3 11.2 8.8 4.1 5.8 4.2 -3.7 1.0 [109] -3.3 3.1 5.2 -8.1 -8.1 -10.7 -18.6 -20.6 -34.1 -48.9 -52.6 -62.9 [121] -65.5 > y [1] 1.64 1.49 1.79 1.54 1.42 1.39 1.42 1.30 1.46 1.43 1.50 1.34 [13] 1.38 1.52 1.38 1.37 1.53 1.53 1.49 1.57 1.34 1.63 1.55 1.56 [25] 1.31 1.21 1.06 1.00 0.67 0.62 0.49 0.28 0.24 -0.15 -0.58 -0.78 [37] -0.85 -1.06 -1.18 -1.46 -1.70 -2.09 -2.33 -2.41 -2.56 -2.56 -2.41 -2.39 [49] -2.25 -2.23 -2.12 -1.98 -1.64 -1.41 -1.41 -1.23 -1.25 -1.40 -1.37 -1.37 [61] -1.42 -1.33 -1.35 -1.23 -1.17 -1.17 -0.95 -0.90 -0.74 -0.32 -0.09 0.15 [73] 0.21 0.23 0.36 0.39 0.50 0.54 0.55 0.52 0.68 0.52 0.60 0.50 [85] 0.62 0.88 0.93 0.86 0.65 0.86 0.88 0.98 1.04 1.14 1.00 0.89 [97] 0.76 0.64 0.62 0.69 0.63 0.53 0.54 0.50 0.33 0.26 0.18 0.27 [109] 0.27 0.09 -0.06 -0.12 -0.06 -0.13 -0.19 -0.35 -0.48 -0.67 -0.88 -1.12 [121] -1.30 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: y ~ Lags(y, 1:2) + Lags(x, 1:2) Model 2: y ~ Lags(y, 1:2) Res.Df Df F Pr(>F) 1 114 2 116 -2 8.3042 0.0004298 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: x ~ Lags(x, 1:2) + Lags(y, 1:2) Model 2: x ~ Lags(x, 1:2) Res.Df Df F Pr(>F) 1 114 2 116 -2 3.3837 0.03736 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/wessaorg/rcomp/tmp/1vp2e1378698019.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 0.352 0.384 0.417 0.456 0.493 0.531 0.567 0.602 0.640 0.678 0.710 -6 -5 -4 -3 -2 -1 0 1 2 3 4 0.741 0.765 0.787 0.804 0.813 0.814 0.807 0.761 0.708 0.652 0.594 5 6 7 8 9 10 11 12 13 14 15 0.537 0.482 0.425 0.366 0.308 0.248 0.186 0.128 0.073 0.015 -0.044 16 17 -0.108 -0.172 > (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.352 0.384 0.417 0.456 0.493 0.531 0.567 0.602 0.640 0.678 0.710 -6 -5 -4 -3 -2 -1 0 1 2 3 4 0.741 0.765 0.787 0.804 0.813 0.814 0.807 0.761 0.708 0.652 0.594 5 6 7 8 9 10 11 12 13 14 15 0.537 0.482 0.425 0.366 0.308 0.248 0.186 0.128 0.073 0.015 -0.044 16 17 -0.108 -0.172 > par(op) > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/2t7961378698019.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/wessaorg/rcomp/tmp/3dk601378698019.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/4ltnb1378698019.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/wessaorg/rcomp/tmp/5unpf1378698019.tab") > > try(system("convert tmp/1vp2e1378698019.ps tmp/1vp2e1378698019.png",intern=TRUE)) character(0) > try(system("convert tmp/2t7961378698019.ps tmp/2t7961378698019.png",intern=TRUE)) character(0) > try(system("convert tmp/3dk601378698019.ps tmp/3dk601378698019.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.749 0.582 3.328