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(100.00,99.95,102.07,102.02,102.63,102.88,103.01,104.33,105.21,104.73,104.17,103.69,104.33,105.21,105.31,105.54,106.70,106.60,105.01,104.33,104.17,103.42,102.33,101.82,103.57,103.90,104.58,105.03,105.67,105.69,105.72,105.84,105.79,105.39,105.97,106.50,107.13,109.36,109.36,108.42,107.94,108.10,108.40,110.55,111.81,112.55,111.66,111.38,113.10,115.18,121.07,123.07,123.40,122.92,122.39,123.55,124.97,124.87,123.27,121.96,122.49,125.68,126.76,126.44,125.35,126.01,127.45,130.58,133.09,133.34,132.84,133.80) > x <- c(100.00,99.97,101.03,101.00,101.30,101.43,101.49,102.14,102.58,102.34,102.07,101.83,102.14,102.58,102.63,102.74,103.32,103.27,102.48,102.14,102.07,101.69,101.15,100.90,101.77,101.93,102.27,102.49,102.80,102.82,102.83,102.89,102.87,102.67,102.96,103.22,103.53,104.63,104.63,104.17,103.93,104.01,104.16,105.22,105.85,106.21,105.77,105.63,106.49,107.51,110.43,111.42,111.58,111.34,111.08,111.66,112.36,112.31,111.52,110.87,111.13,112.71,113.25,113.09,112.55,112.87,113.59,115.14,116.38,116.50,116.25,116.73) > 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] -0.03 1.06 -0.03 0.30 0.13 0.06 0.65 0.44 -0.24 -0.27 -0.24 0.31 [13] 0.44 0.05 0.11 0.58 -0.05 -0.79 -0.34 -0.07 -0.38 -0.54 -0.25 0.87 [25] 0.16 0.34 0.22 0.31 0.02 0.01 0.06 -0.02 -0.20 0.29 0.26 0.31 [37] 1.10 0.00 -0.46 -0.24 0.08 0.15 1.06 0.63 0.36 -0.44 -0.14 0.86 [49] 1.02 2.92 0.99 0.16 -0.24 -0.26 0.58 0.70 -0.05 -0.79 -0.65 0.26 [61] 1.58 0.54 -0.16 -0.54 0.32 0.72 1.55 1.24 0.12 -0.25 0.48 > y [1] -0.05 2.12 -0.05 0.61 0.25 0.13 1.32 0.88 -0.48 -0.56 -0.48 0.64 [13] 0.88 0.10 0.23 1.16 -0.10 -1.59 -0.68 -0.16 -0.75 -1.09 -0.51 1.75 [25] 0.33 0.68 0.45 0.64 0.02 0.03 0.12 -0.05 -0.40 0.58 0.53 0.63 [37] 2.23 0.00 -0.94 -0.48 0.16 0.30 2.15 1.26 0.74 -0.89 -0.28 1.72 [49] 2.08 5.89 2.00 0.33 -0.48 -0.53 1.16 1.42 -0.10 -1.60 -1.31 0.53 [61] 3.19 1.08 -0.32 -1.09 0.66 1.44 3.13 2.51 0.25 -0.50 0.96 > (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 67 2 68 -1 2.4952 0.1189 > (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 67 2 68 -1 2.6905 0.1056 > postscript(file="/var/www/html/rcomp/tmp/10p1l1260532449.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 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 0.362 0.406 0.445 0.478 0.509 0.545 0.584 0.623 0.662 0.701 0.738 0.782 0.835 -2 -1 0 1 2 3 4 5 6 7 8 9 10 0.891 0.948 1.000 0.948 0.891 0.834 0.782 0.738 0.701 0.662 0.623 0.584 0.545 11 12 13 14 15 0.509 0.478 0.445 0.406 0.362 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -0.154 -0.140 0.114 0.185 0.171 -0.107 -0.302 -0.177 0.128 0.300 0.165 -4 -3 -2 -1 0 1 2 3 4 5 6 -0.185 -0.331 -0.087 0.410 1.000 0.410 -0.089 -0.331 -0.185 0.166 0.300 7 8 9 10 11 12 13 14 15 0.129 -0.177 -0.303 -0.107 0.170 0.185 0.114 -0.140 -0.154 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2rwh11260532449.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/3330f1260532449.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/40g4i1260532449.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/5z4c71260532449.tab") > > system("convert tmp/10p1l1260532449.ps tmp/10p1l1260532449.png") > system("convert tmp/2rwh11260532449.ps tmp/2rwh11260532449.png") > system("convert tmp/3330f1260532449.ps tmp/3330f1260532449.png") > > > proc.time() user system elapsed 0.963 0.491 2.400