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(2.83,2.72,2.73,2.72,2.77,2.61,2.47,2.30,2.38,2.43,2.39,2.60,2.84,2.87,2.92,2.08,3.33,3.48,3.57,3.66,3.77,3.75,3.75,3.81,3.82,3.89,4.05,4.10,4.07,4.26,4.40,4.61,4.63,4.48,4.46,4.45,4.32,4.52,4.21,3.97,4.12,4.50,4.73,5.26,4.52,4.94,4.95,3.52,3.85,2.41,2.95,2.68,2.53,2.44,2.16,2.20,2.10,2.29,2.03,2.05,2.07) > x <- c(2.085,2.053,2.077,2.058,2.057,2.076,2.07,2.062,2.073,2.061,2.094,2.067,2.086,2.276,2.326,2.349,2.52,2.628,2.577,2.698,2.814,2.968,3.041,3.278,3.328,3.5,3.563,3.569,3.69,3.819,3.79,3.956,4.063,4.047,4.029,3.941,4.022,3.879,4.022,4.028,4.091,3.987,4.01,4.007,4.191,4.299,4.273,3.82,3.15,2.486,1.812,1.257,1.062,0.842,0.782,0.698,0.358,0.347,0.363,0.359,0.355) > par8 = '4' > par7 = '0' > par6 = '2' > par5 = '1' > par4 = '12' > par3 = '0' > par2 = '2' > 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.056 -0.043 0.018 0.020 -0.025 -0.002 0.019 -0.023 0.045 -0.060 [11] 0.046 0.171 -0.140 -0.027 0.148 -0.063 -0.159 0.172 -0.005 0.038 [21] -0.081 0.164 -0.187 0.122 -0.109 -0.057 0.115 0.008 -0.158 0.195 [31] -0.059 -0.123 -0.002 -0.070 0.169 -0.224 0.286 -0.137 0.057 -0.167 [41] 0.127 -0.026 0.187 -0.076 -0.134 -0.427 -0.217 0.006 -0.010 0.119 [51] 0.360 -0.025 0.160 -0.024 -0.256 0.329 0.027 -0.020 0.000 > y [1] 1.200000e-01 -2.000000e-02 6.000000e-02 -2.100000e-01 2.000000e-02 [6] -3.000000e-02 2.500000e-01 -3.000000e-02 -9.000000e-02 2.500000e-01 [11] 3.000000e-02 -2.100000e-01 2.000000e-02 -8.900000e-01 2.090000e+00 [16] -1.100000e+00 -6.000000e-02 4.440892e-16 2.000000e-02 -1.300000e-01 [21] 2.000000e-02 6.000000e-02 -5.000000e-02 6.000000e-02 9.000000e-02 [26] -1.100000e-01 -8.000000e-02 2.200000e-01 -5.000000e-02 7.000000e-02 [31] -1.900000e-01 -1.700000e-01 1.300000e-01 1.000000e-02 -1.200000e-01 [36] 3.300000e-01 -5.100000e-01 7.000000e-02 3.900000e-01 2.300000e-01 [41] -1.500000e-01 3.000000e-01 -1.270000e+00 1.160000e+00 -4.100000e-01 [46] -1.440000e+00 1.760000e+00 -1.770000e+00 1.980000e+00 -8.100000e-01 [51] 1.200000e-01 6.000000e-02 -1.900000e-01 3.200000e-01 -1.400000e-01 [56] 2.900000e-01 -4.500000e-01 2.800000e-01 0.000000e+00 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:4) + Lags(, 1:4) Model 2: ~ Lags(, 1:4) Res.Df Df F Pr(>F) 1 46 2 50 -4 0.4219 0.792 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:4) + Lags(, 1:4) Model 2: ~ Lags(, 1:4) Res.Df Df F Pr(>F) 1 46 2 50 -4 1.5424 0.2058 > postscript(file="/var/www/html/rcomp/tmp/19pa81260447204.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.098 -0.063 -0.010 0.051 0.129 0.213 0.303 0.395 0.486 0.571 0.657 -3 -2 -1 0 1 2 3 4 5 6 7 0.738 0.809 0.874 0.922 0.899 0.850 0.778 0.693 0.583 0.472 0.363 8 9 10 11 12 13 14 0.259 0.168 0.074 -0.008 -0.108 -0.167 -0.238 > (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.247 -0.291 0.286 -0.228 0.188 -0.133 0.048 -0.065 0.107 -0.079 0.003 -3 -2 -1 0 1 2 3 4 5 6 7 0.043 -0.100 0.021 0.016 0.075 -0.007 0.027 0.131 -0.069 -0.212 0.287 8 9 10 11 12 13 14 -0.405 0.374 -0.183 -0.080 0.206 -0.062 -0.095 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/272lb1260447204.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/3z9ww1260447204.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/442lx1260447204.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/57t7q1260447204.tab") > > system("convert tmp/19pa81260447204.ps tmp/19pa81260447204.png") > system("convert tmp/272lb1260447204.ps tmp/272lb1260447204.png") > system("convert tmp/3z9ww1260447204.ps tmp/3z9ww1260447204.png") > > > proc.time() user system elapsed 0.907 0.457 1.121