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 = '11' > 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] -0.0254 -0.0294 -0.0180 -0.0072 -0.0366 -0.0460 -0.0140 -0.0265 0.0454 [10] 0.0210 -0.0717 0.0590 0.1047 0.0606 0.0795 -0.0217 0.0004 0.0193 [19] -0.0223 -0.0779 -0.0030 -0.0148 0.0114 -0.0457 -0.0331 -0.0274 0.0094 [28] -0.0297 0.0092 0.0005 -0.0274 -0.0168 -0.0075 0.0214 -0.0332 -0.0270 [37] 0.0116 0.0084 -0.0127 -0.0034 0.0120 -0.0499 -0.0251 -0.0082 0.0165 [46] -0.0247 -0.0070 0.0229 0.0241 0.0036 -0.0255 0.0128 0.0529 0.0244 [55] 0.0263 -0.0187 0.0105 0.0289 -0.0417 > y [1] -0.77 2.17 -2.22 2.30 -3.54 -1.60 -2.60 -9.35 1.43 2.78 0.77 10.24 [13] 19.68 10.43 4.82 -2.19 -3.95 -0.75 -4.97 1.38 0.71 4.87 -0.66 2.06 [25] -5.13 -0.77 7.71 -2.21 -1.33 -2.54 -5.44 2.36 -1.04 -1.74 -3.71 -1.46 [37] -0.66 -0.46 -1.83 -1.59 -2.41 0.89 -2.63 -0.19 -0.96 0.77 -0.99 -1.54 [49] -1.99 -0.08 -1.23 -2.53 3.15 3.47 -0.01 -2.28 -0.92 3.51 -3.05 > (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 25 2 36 -11 2.1798 0.05178 . --- 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:11) + Lags(, 1:11) Model 2: ~ Lags(, 1:11) Res.Df Df F Pr(>F) 1 25 2 36 -11 2.6533 0.02099 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/1kayj1260535116.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.138 0.036 -0.036 -0.111 -0.054 0.076 -0.078 -0.215 -0.025 0.098 -0.017 -3 -2 -1 0 1 2 3 4 5 6 7 0.033 -0.084 0.272 0.592 0.349 0.227 0.246 -0.072 -0.071 -0.228 -0.283 8 9 10 11 12 13 14 -0.108 -0.118 -0.143 -0.058 -0.072 -0.081 -0.035 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2fs8c1260535116.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/31v9y1260535116.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/4ebyq1260535116.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/5rat11260535116.tab") > system("convert tmp/1kayj1260535116.ps tmp/1kayj1260535116.png") > system("convert tmp/2fs8c1260535116.ps tmp/2fs8c1260535116.png") > system("convert tmp/31v9y1260535116.ps tmp/31v9y1260535116.png") > > > proc.time() user system elapsed 0.966 0.479 1.187