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(10800,10642,10269,10189,9876,10164,9906,10003,10564,10221,10052,10512,10573,10821,10167,10901,10896,10934,11059,10513,10270,10399,10740,10263,9883,10204,10201,10416,10557,10166,10066,10117,9973,10360,10133,10667,10883,10794,11212,11242,11483,11106,11019,10767,10577,10859,10575,10680,10926,11781,11241,12347,12699,12214,12066,12085,11894,11793,15567,16135) > x <- c(17823.2,17872,17420.4,16704.4,15991.2,15583.6,19123.5,17838.7,17209.4,18586.5,16258.1,15141.6,19202.1,17746.5,19090.1,18040.3,17515.5,17751.8,21072.4,17170,19439.5,19795.4,17574.9,16165.4,19464.6,19932.1,19961.2,17343.4,18924.2,18574.1,21350.6,18594.6,19832.1,20844.4,19640.2,17735.4,19813.6,22160,20664.3,17877.4,20906.5,21164.1,21374.4,22952.3,21343.5,23899.3,22392.9,18274.1,22786.7,22321.5,17842.2,16373.5,15933.8,16446.1,17729,16643,16196.7,18252.1,17570.4,15836.8) > par8 = '11' > par7 = '1' > par6 = '1' > par5 = '1' > par4 = '12' > par3 = '1' > 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] -1504.4 1795.2 -333.8 188.4 643.9 -219.3 -2617.6 2898.8 -1021.2 [10] 107.9 -293.0 -761.3 1923.1 -1314.5 -1568.0 2105.6 -586.4 -544.1 [19] 1146.4 -1032.0 656.4 1016.3 -495.3 -1221.0 1878.9 -1524.8 -169.1 [28] 1448.3 607.7 -2566.2 4333.9 -2846.3 1543.5 -302.2 -2214.0 2434.4 [37] -2811.6 -2983.6 1318.2 -3468.8 254.7 1072.6 -2663.9 1162.5 -500.4 [46] 824.7 2385.2 > y [1] 406 -281 814 308 -250 383 -643 -804 472 510 -937 -441 73 651 -519 [16] 146 -429 -225 597 99 258 -568 1011 596 -410 421 -185 100 14 13 [31] -303 -46 -105 -57 -429 30 944 -958 1076 111 -108 -61 271 -1 -383 [46] 4058 463 > (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 13 2 24 -11 2.7342 0.04404 * --- 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 13 2 24 -11 0.5725 0.8196 > postscript(file="/var/www/html/rcomp/tmp/1xr0s1260564574.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.458 0.481 0.321 0.381 0.518 0.372 0.157 0.077 0.038 0.023 0.009 -3 -2 -1 0 1 2 3 4 5 6 7 -0.056 -0.090 -0.098 -0.207 -0.169 -0.085 -0.059 -0.073 -0.042 -0.053 -0.058 8 9 10 11 12 13 14 -0.050 -0.047 -0.100 -0.150 -0.154 -0.152 -0.195 > (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.022 -0.009 -0.074 0.176 -0.350 -0.004 -0.032 -0.127 -0.008 0.074 -0.163 -2 -1 0 1 2 3 4 5 6 7 8 -0.040 0.153 0.027 -0.018 0.153 -0.030 -0.061 0.158 -0.153 0.147 0.051 9 10 11 12 13 -0.085 0.146 -0.159 0.053 0.073 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2xr6u1260564574.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/3tkqh1260564574.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/4vdeb1260564574.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/52vyb1260564574.tab") > system("convert tmp/1xr0s1260564574.ps tmp/1xr0s1260564574.png") > system("convert tmp/2xr6u1260564574.ps tmp/2xr6u1260564574.png") > system("convert tmp/3tkqh1260564574.ps tmp/3tkqh1260564574.png") > > > proc.time() user system elapsed 0.962 0.503 5.834