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(10284.5,12792,12823.61538,13845.66667,15335.63636,11188.5,13633.25,12298.46667,15353.63636,12696.15385,12213.93333,13683.72727,11214.14286,13950.23077,11179.13333,11801.875,11188.82353,16456.27273,11110.0625,16530.69231,10038.41176,11681.25,11148.88235,8631,9386.444444,9764.736842,12043.75,12948.06667,10987.125,11648.3125,10633.35294,10219.3,9037.6,10296.31579,11705.41176,10681.94444,9362.947368,11306.35294,10984.45,10062.61905,8118.583333,8867.48,8346.72,8529.307692,10697.18182,8591.84,8695.607143,8125.571429,7009.758621,7883.466667,7527.645161,6763.758621,6682.333333,7855.681818,6738.88,7895.434783,6361.884615,6935.956522,8344.454545,9107.944444) > x <- c(9904.642857,13710.15385,13747.69231,14517,15185.81818,11422.28571,13819.66667,12749,16217,13238,12391,14780.09091,10815.42857,14770.84615,11831,11931.3125,10611.94118,15923.18182,11094.875,16209.53846,10100,12149.6875,11644.35294,9249.947368,8980.777778,10244.52632,12457.5625,13307.46667,10839.625,11827.625,10925.94118,10675.3,9297.3,10433.21053,12261.41176,10911.22222,9334.421053,11655.05882,11080,9840.142857,7448.916667,8362.6,8465.64,8220.923077,10432.86364,8537.4,8535.464286,7997.464286,6301.413793,7595.566667,7200.483871,6152.482759,6064.259259,7269.909091,6578.44,7708.26087,6401.153846,7042.043478,8296.409091,9613.333333) > 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] 3805.510993 37.538460 769.307690 668.818180 -3763.532470 [6] 2397.380960 -1070.666670 3468.000000 -2979.000000 -847.000000 [11] 2389.090910 -3964.662340 3955.417580 -2939.846150 100.312500 [16] -1319.371320 5311.240640 -4828.306820 5114.663460 -6109.538460 [21] 2049.687500 -505.334560 -2394.405572 -269.169590 1263.748542 [26] 2213.036180 849.904170 -2467.841670 988.000000 -901.683820 [31] -250.641180 -1378.000000 1135.910530 1828.201230 -1350.189540 [36] -1576.801167 2320.637767 -575.058820 -1239.857143 -2391.226190 [41] 913.683333 103.040000 -244.716923 2211.940563 -1895.463640 [46] -1.935714 -538.000000 -1696.050493 1294.152874 -395.082796 [51] -1048.001112 -88.223500 1205.649832 -691.469091 1129.820870 [56] -1307.107024 640.889632 1254.365613 1316.924242 > y [1] 2507.50000 31.61538 1022.05129 1489.96969 -4147.13636 2444.75000 [7] -1334.78333 3055.16969 -2657.48251 -482.22052 1469.79394 -2469.58441 [13] 2736.08791 -2771.09744 622.74167 -613.05147 5267.44920 -5346.21023 [19] 5420.62981 -6492.28055 1642.83824 -532.36765 -2517.88235 755.44444 [25] 378.29240 2279.01316 904.31667 -1960.94167 661.18750 -1014.95956 [31] -414.05294 -1181.70000 1258.71579 1409.09597 -1023.46732 -1318.99707 [37] 1943.40557 -321.90294 -921.83095 -1944.03572 748.89667 -520.76000 [43] 182.58769 2167.87413 -2105.34182 103.76714 -570.03571 -1115.81281 [49] 873.70805 -355.82151 -763.88654 -81.42529 1173.34849 -1116.80182 [55] 1156.55478 -1533.55017 574.07191 1408.49802 763.48990 > (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 55 2 56 -1 0.0054 0.9417 > (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 55 2 56 -1 0.1311 0.7187 > postscript(file="/var/www/html/rcomp/tmp/1p7uh1260471388.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 -3 -2 0.150 0.215 0.220 0.341 0.363 0.446 0.486 0.477 0.516 0.538 0.577 0.570 0.738 -1 0 1 2 3 4 5 6 7 8 9 10 11 0.644 0.989 0.643 0.715 0.553 0.556 0.516 0.467 0.456 0.443 0.424 0.359 0.310 12 13 14 0.207 0.199 0.128 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -0.138 0.095 -0.162 0.136 -0.085 0.060 0.077 -0.078 0.035 -0.042 0.077 -3 -2 -1 0 1 2 3 4 5 6 7 -0.250 0.365 -0.624 0.976 -0.593 0.326 -0.235 0.066 0.006 -0.049 -0.003 8 9 10 11 12 13 14 0.013 0.064 -0.022 0.075 -0.134 0.095 -0.169 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2k1bw1260471388.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/3amhq1260471388.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/4na0a1260471388.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/5liwf1260471388.tab") > > system("convert tmp/1p7uh1260471388.ps tmp/1p7uh1260471388.png") > system("convert tmp/2k1bw1260471388.ps tmp/2k1bw1260471388.png") > system("convert tmp/3amhq1260471388.ps tmp/3amhq1260471388.png") > > > proc.time() user system elapsed 0.896 0.458 1.049