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(627,696,825,677,656,785,412,352,839,729,696,641,695,638,762,635,721,854,418,367,824,687,601,676,740,691,683,594,729,731,386,331,707,715,657,653,642,643,718,654,632,731,392,344,792,852,649,629,685,617,715,715,629,916,531,357,917,828,708,858,775,785,1006,789,734,906,532,387,991,841) > x <- c(2350.44,2440.25,2408.64,2472.81,2407.6,2454.62,2448.05,2497.84,2645.64,2756.76,2849.27,2921.44,2981.85,3080.58,3106.22,3119.31,3061.26,3097.31,3161.69,3257.16,3277.01,3295.32,3363.99,3494.17,3667.03,3813.06,3917.96,3895.51,3801.06,3570.12,3701.61,3862.27,3970.1,4138.52,4199.75,4290.89,4443.91,4502.64,4356.98,4591.27,4696.96,4621.4,4562.84,4202.52,4296.49,4435.23,4105.18,4116.68,3844.49,3720.98,3674.4,3857.62,3801.06,3504.37,3032.6,3047.03,2962.34,2197.82,2014.45,1862.83,1905.41,1810.99,1670.07,1864.44,2052.02,2029.6,2070.83,2293.41,2443.27,2513.17) > par8 = '11' > par7 = '0' > par6 = '1' > par5 = '-0.5' > 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/ > #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] 89.81 -31.61 64.17 -65.21 47.02 -6.57 49.79 147.80 111.12 [10] 92.51 72.17 60.41 98.73 25.64 13.09 -58.05 36.05 64.38 [19] 95.47 19.85 18.31 68.67 130.18 172.86 146.03 104.90 -22.45 [28] -94.45 -230.94 131.49 160.66 107.83 168.42 61.23 91.14 153.02 [37] 58.73 -145.66 234.29 105.69 -75.56 -58.56 -360.32 93.97 138.74 [46] -330.05 11.50 -272.19 -123.51 -46.58 183.22 -56.56 -296.69 -471.77 [55] 14.43 -84.69 -764.52 -183.37 -151.62 42.58 -94.42 -140.92 194.37 [64] 187.58 -22.42 41.23 222.58 149.86 69.90 > y [1] 4.062502e-03 6.178742e-03 -7.235182e-03 -1.220637e-03 6.703820e-03 [6] -2.714987e-02 -8.067430e-03 3.755269e-02 -5.026406e-03 -1.735730e-03 [11] -3.185446e-03 3.130926e-03 -3.316434e-03 6.728403e-03 -6.915223e-03 [16] 4.883687e-03 6.045301e-03 -2.938461e-02 -6.575953e-03 3.472585e-02 [21] -6.631458e-03 -5.276942e-03 4.658625e-03 3.401615e-03 -2.562123e-03 [26] -4.442875e-04 -5.533121e-03 7.986920e-03 1.014019e-04 -2.782465e-02 [31] -8.132622e-03 3.471220e-02 4.219822e-04 -3.231672e-03 -2.386166e-04 [36] -6.676558e-04 6.140312e-05 4.232964e-03 -3.566852e-03 -1.349540e-03 [41] 5.583056e-03 -2.704258e-02 -6.817519e-03 3.676587e-02 2.548034e-03 [46] -9.987996e-03 -1.238355e-03 3.329150e-03 -4.100896e-03 5.721209e-03 [51] 0.000000e+00 -4.949463e-03 1.366336e-02 -2.071075e-02 -1.905862e-02 [56] 3.980541e-02 -3.458986e-03 -5.659798e-03 6.885729e-03 -3.563247e-03 [61] 4.590598e-04 8.326395e-03 -8.145219e-03 -2.619462e-03 7.375798e-03 [66] -2.026545e-02 -1.495472e-02 3.813362e-02 -5.433423e-03 > (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 35 2 46 -11 3.0102 0.006376 ** --- 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 35 2 46 -11 0.4017 0.9458 > postscript(file="/var/www/html/rcomp/tmp/1dwlr1261592610.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 0.091 0.085 0.089 0.068 0.019 -0.018 -0.027 -0.085 -0.101 -0.106 -0.143 -4 -3 -2 -1 0 1 2 3 4 5 6 -0.186 -0.240 -0.256 -0.233 -0.246 -0.269 -0.240 -0.254 -0.273 -0.255 -0.238 7 8 9 10 11 12 13 14 15 -0.194 -0.175 -0.195 -0.151 -0.089 -0.092 -0.094 -0.062 -0.054 > (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.144 0.022 0.051 0.101 -0.080 -0.093 0.125 0.024 -0.032 -0.035 0.095 -4 -3 -2 -1 0 1 2 3 4 5 6 0.000 -0.195 -0.054 0.165 0.069 -0.128 -0.032 0.058 0.007 -0.051 -0.083 7 8 9 10 11 12 13 14 15 0.171 0.052 -0.258 -0.033 0.180 0.063 -0.113 -0.090 0.066 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2wje41261592610.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/3nq4g1261592610.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/42keh1261592610.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/5itz51261592610.tab") > > try(system("convert tmp/1dwlr1261592610.ps tmp/1dwlr1261592610.png",intern=TRUE)) character(0) > try(system("convert tmp/2wje41261592610.ps tmp/2wje41261592610.png",intern=TRUE)) character(0) > try(system("convert tmp/3nq4g1261592610.ps tmp/3nq4g1261592610.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.956 0.483 1.133