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(106370,109375,116476,123297,114813,117925,126466,131235,120546,123791,129813,133463,122987,125418,130199,133016,121454,122044,128313,131556,120027,123001,130111,132524,123742,124931,133646,136557,127509,128945,137191,139716,129083,131604,139413,143125,133948,137116,144864,149277,138796,143258,150034,154708,144888,148762,156500,161088,152772,158011,163318,169969,162269,165765,170600,174681,166364,170240,176150,182056,172218,177856,182253,188090,176863,183273,187969,194650,183036,189516,193805,200499,188142,193732,197126,205140,191751,196700,199784,207360,196101,200824,205743,212489,200810,203683,207286,210910) > x <- c(102.1,103.2,103.7,106.2,107.7,109.9,111.7,114.9,116,118.3,120.4,126,128.1,130.1,130.8,133.6,134.2,135.5,136.2,139.1,139,139.6,138.7,140.9,141.3,141.8,142,144.5,144.6,145.5,146.8,149.5,149.9,150.1,150.9,152.8,153.1,154,154.9,156.9,158.4,159.7,160.2,163.2,163.7,164.4,163.7,165.5,165.6,166.8,167.5,170.6,170.9,172,171.8,173.9,174,173.8,173.9,176,176.6,178.2,179.2,181.3,181.8,182.9,183.8,186.3,187.4,189.2,189.7,191.9,192.6,193.7,194.2,197.6,199.3,201.4,203,206.3,207.1,209.8,211.1,215.3,217.4,215.5,210.9,212.6) > par8 = '2' > par7 = '1' > par6 = '1' > par5 = '1' > par4 = '4' > 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/ > #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] 1.100000e+00 1.300000e+00 7.000000e-01 -4.000000e-01 1.000000e-01 [6] 3.000000e-01 2.400000e+00 1.000000e+00 -3.000000e-01 -1.400000e+00 [11] -2.800000e+00 -1.500000e+00 -7.000000e-01 -2.842171e-14 1.000000e-01 [16] -7.000000e-01 -7.000000e-01 -1.600000e+00 -7.000000e-01 5.000000e-01 [21] -1.000000e-01 1.100000e+00 3.000000e-01 -3.000000e-01 4.000000e-01 [26] 1.100000e+00 2.000000e-01 3.000000e-01 -7.000000e-01 -5.000000e-01 [31] -8.000000e-01 -1.000000e-01 7.000000e-01 1.000000e-01 1.000000e-01 [36] 1.200000e+00 4.000000e-01 -4.000000e-01 1.000000e+00 -1.000000e+00 [41] -6.000000e-01 -1.200000e+00 -1.200000e+00 -4.000000e-01 5.000000e-01 [46] 1.400000e+00 1.300000e+00 2.000000e-01 -1.000000e-01 -9.000000e-01 [51] -1.000000e+00 -2.000000e-01 -1.300000e+00 3.000000e-01 0.000000e+00 [56] 5.000000e-01 1.800000e+00 9.000000e-01 2.842171e-14 -1.000000e-01 [61] -5.000000e-01 -1.000000e-01 4.000000e-01 6.000000e-01 7.000000e-01 [66] -4.000000e-01 -3.000000e-01 -4.000000e-01 -7.000000e-01 0.000000e+00 [71] 1.200000e+00 1.000000e+00 1.000000e+00 1.100000e+00 -1.000000e-01 [76] -9.000000e-01 6.000000e-01 -3.000000e-01 9.000000e-01 1.300000e+00 [81] -4.600000e+00 -5.900000e+00 -2.500000e+00 > y [1] 107 1440 -2052 -2205 133 -2519 -1119 213 -814 -1241 -833 -1086 [13] -1841 1488 426 33 2384 841 -830 2747 -1785 1605 498 -266 [25] 247 -469 -386 -1585 1085 -437 1187 1456 647 -61 701 -1304 [37] 1294 -972 261 661 -588 962 -86 1504 1365 -2431 2063 616 [49] -1743 -472 -2570 -617 380 1075 1825 -1521 1762 -1513 -69 -1389 [61] 772 299 844 -387 70 -407 13 -743 -890 -895 1320 -1032 [73] -641 -310 -438 2130 -226 1835 -830 -420 -1850 -1316 -3122 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:2) + Lags(, 1:2) Model 2: ~ Lags(, 1:2) Res.Df Df F Pr(>F) 1 76 2 78 -2 2.8705 0.06283 . --- 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:2) + Lags(, 1:2) Model 2: ~ Lags(, 1:2) Res.Df Df F Pr(>F) 1 76 2 78 -2 2.0487 0.1360 > postscript(file="/var/www/html/rcomp/tmp/1r5ef1260376766.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 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 0.519 0.540 0.561 0.583 0.613 0.633 0.655 0.680 0.713 0.735 0.760 0.789 0.827 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 0.857 0.888 0.918 0.956 0.919 0.882 0.844 0.813 0.772 0.734 0.695 0.666 0.627 10 11 12 13 14 15 16 0.591 0.554 0.528 0.491 0.459 0.425 0.400 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 0.048 0.065 -0.007 -0.026 -0.083 -0.032 -0.056 0.005 0.035 0.029 -0.059 -5 -4 -3 -2 -1 0 1 2 3 4 5 -0.091 -0.202 -0.120 -0.078 0.147 0.204 0.115 0.199 0.018 0.005 -0.037 6 7 8 9 10 11 12 13 14 15 16 -0.037 0.031 0.086 0.044 0.057 -0.081 0.064 0.073 0.058 0.058 0.022 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2h6en1260376766.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/3enz11260376766.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/4i9nj1260376766.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/5lkd61260376766.tab") > > system("convert tmp/1r5ef1260376766.ps tmp/1r5ef1260376766.png") > system("convert tmp/2h6en1260376766.ps tmp/2h6en1260376766.png") > system("convert tmp/3enz11260376766.ps tmp/3enz11260376766.png") > > > proc.time() user system elapsed 0.955 0.493 2.639