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(117.09,116.77,119.39,122.49,124.08,118.29,112.94,113.79,114.43,118.70,120.36,118.27,118.34,117.82,117.65,118.18,121.02,124.78,131.16,130.14,131.75,134.73,135.35,140.32,136.35,131.60,128.90,133.89,138.25,146.23,144.76,149.30,156.80,159.08,165.12,163.14,153.43,151.01,154.72,154.58,155.63,161.67,163.51,162.91,164.80,164.98,154.54,148.60,149.19,150.61) > x <- c(87.00,96.30,107.10,115.20,106.10,89.50,91.30,97.60,100.70,104.60,94.70,101.80,102.50,105.30,110.30,109.80,117.30,118.80,131.30,125.90,133.10,147.00,145.80,164.40,149.80,137.70,151.70,156.80,180.00,180.40,170.40,191.60,199.50,218.20,217.50,205.00,194.00,199.30,219.30,211.10,215.20,240.20,242.20,240.70,255.40,253.00,218.20,203.70,205.60,215.60) > par8 = '1' > 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] 9.3 10.8 8.1 -9.1 -16.6 1.8 6.3 3.1 3.9 -9.9 7.1 0.7 [13] 2.8 5.0 -0.5 7.5 1.5 12.5 -5.4 7.2 13.9 -1.2 18.6 -14.6 [25] -12.1 14.0 5.1 23.2 0.4 -10.0 21.2 7.9 18.7 -0.7 -12.5 -11.0 [37] 5.3 20.0 -8.2 4.1 25.0 2.0 -1.5 14.7 -2.4 -34.8 -14.5 1.9 [49] 10.0 > y [1] -0.32 2.62 3.10 1.59 -5.79 -5.35 0.85 0.64 4.27 1.66 [11] -2.09 0.07 -0.52 -0.17 0.53 2.84 3.76 6.38 -1.02 1.61 [21] 2.98 0.62 4.97 -3.97 -4.75 -2.70 4.99 4.36 7.98 -1.47 [31] 4.54 7.50 2.28 6.04 -1.98 -9.71 -2.42 3.71 -0.14 1.05 [41] 6.04 1.84 -0.60 1.89 0.18 -10.44 -5.94 0.59 1.42 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:1) + Lags(, 1:1) Model 2: ~ Lags(, 1:1) Res.Df Df F Pr(>F) 1 45 2 46 -1 12.541 0.0009397 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:1) + Lags(, 1:1) Model 2: ~ Lags(, 1:1) Res.Df Df F Pr(>F) 1 45 2 46 -1 0.8646 0.3574 > postscript(file="/var/www/html/rcomp/tmp/18l5s1261304805.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 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0.223 0.294 0.364 0.413 0.461 0.525 0.596 0.662 0.717 0.771 0.824 0.880 0.943 0 1 2 3 4 5 6 7 8 9 10 11 12 0.979 0.930 0.886 0.858 0.825 0.771 0.709 0.651 0.601 0.559 0.517 0.449 0.370 13 0.297 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -0.128 0.086 0.263 0.036 -0.067 -0.143 0.039 0.074 -0.228 -0.171 -0.089 -2 -1 0 1 2 3 4 5 6 7 8 -0.068 0.540 0.684 -0.041 -0.216 -0.023 0.035 -0.063 -0.062 -0.163 -0.151 9 10 11 12 13 0.139 0.401 0.235 -0.057 -0.071 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2haj51261304805.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/3skjl1261304805.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/4ik1n1261304805.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/5yt2y1261304805.tab") > > try(system("convert tmp/18l5s1261304805.ps tmp/18l5s1261304805.png",intern=TRUE)) character(0) > try(system("convert tmp/2haj51261304805.ps tmp/2haj51261304805.png",intern=TRUE)) character(0) > try(system("convert tmp/3skjl1261304805.ps tmp/3skjl1261304805.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.895 0.468 1.826