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 = '11' > 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] 1.085 1.053 1.077 1.058 1.057 1.076 1.070 1.062 1.073 1.061 [11] 1.094 1.067 1.086 1.276 1.326 1.349 1.520 1.628 1.577 1.698 [21] 1.814 1.968 2.041 2.278 2.328 2.500 2.563 2.569 2.690 2.819 [31] 2.790 2.956 3.063 3.047 3.029 2.941 3.022 2.879 3.022 3.028 [41] 3.091 2.987 3.010 3.007 3.191 3.299 3.273 2.820 2.150 1.486 [51] 0.812 0.257 0.062 -0.158 -0.218 -0.302 -0.642 -0.653 -0.637 -0.641 [61] -0.645 > y [1] 1.83 1.72 1.73 1.72 1.77 1.61 1.47 1.30 1.38 1.43 1.39 1.60 1.84 1.87 1.92 [16] 1.08 2.33 2.48 2.57 2.66 2.77 2.75 2.75 2.81 2.82 2.89 3.05 3.10 3.07 3.26 [31] 3.40 3.61 3.63 3.48 3.46 3.45 3.32 3.52 3.21 2.97 3.12 3.50 3.73 4.26 3.52 [46] 3.94 3.95 2.52 2.85 1.41 1.95 1.68 1.53 1.44 1.16 1.20 1.10 1.29 1.03 1.05 [61] 1.07 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:11) + Lags(, 1:11) Model 2: ~ Lags(, 1:11) Res.Df Df F Pr(>F) 1 27 2 38 -11 1.7746 0.1096 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:11) + Lags(, 1:11) Model 2: ~ Lags(, 1:11) Res.Df Df F Pr(>F) 1 27 2 38 -11 1.5085 0.1857 > postscript(file="/var/www/html/rcomp/tmp/1ygsl1260443651.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.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 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2a4xa1260443651.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/32xr71260443651.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/4sdpt1260443651.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/5a8is1260443651.tab") > > system("convert tmp/1ygsl1260443651.ps tmp/1ygsl1260443651.png") > system("convert tmp/2a4xa1260443651.ps tmp/2a4xa1260443651.png") > system("convert tmp/32xr71260443651.ps tmp/32xr71260443651.png") > > > proc.time() user system elapsed 0.956 0.492 1.114