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 = '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] 99.00 98.97 100.03 100.00 100.30 100.43 100.49 101.14 101.58 101.34 [11] 101.07 100.83 101.14 101.58 101.63 101.74 102.32 102.27 101.48 101.14 [21] 101.07 100.69 100.15 99.90 100.77 100.93 101.27 101.49 101.80 101.82 [31] 101.83 101.89 101.87 101.67 101.96 102.22 102.53 103.63 103.63 103.17 [41] 102.93 103.01 103.16 104.22 104.85 105.21 104.77 104.63 105.49 106.51 [51] 109.43 110.42 110.58 110.34 110.08 110.66 111.36 111.31 110.52 109.87 [61] 110.13 111.71 112.25 112.09 111.55 111.87 112.59 114.14 115.38 115.50 [71] 115.25 115.73 > y [1] 99.00 98.95 101.07 101.02 101.63 101.88 102.01 103.33 104.21 103.73 [11] 103.17 102.69 103.33 104.21 104.31 104.54 105.70 105.60 104.01 103.33 [21] 103.17 102.42 101.33 100.82 102.57 102.90 103.58 104.03 104.67 104.69 [31] 104.72 104.84 104.79 104.39 104.97 105.50 106.13 108.36 108.36 107.42 [41] 106.94 107.10 107.40 109.55 110.81 111.55 110.66 110.38 112.10 114.18 [51] 120.07 122.07 122.40 121.92 121.39 122.55 123.97 123.87 122.27 120.96 [61] 121.49 124.68 125.76 125.44 124.35 125.01 126.45 129.58 132.09 132.34 [71] 131.84 132.80 > (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 68 2 69 -1 0.7959 0.3755 > (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 68 2 69 -1 0.884 0.3504 > postscript(file="/var/www/html/rcomp/tmp/17rv41260532084.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 -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 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2ta3c1260532084.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/3zviu1260532084.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/4tupv1260532084.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/5902q1260532085.tab") > > system("convert tmp/17rv41260532084.ps tmp/17rv41260532084.png") > system("convert tmp/2ta3c1260532084.ps tmp/2ta3c1260532084.png") > system("convert tmp/3zviu1260532084.ps tmp/3zviu1260532084.png") > > > proc.time() user system elapsed 0.923 0.479 1.096