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 = '11' > 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] 9903.643 13709.154 13746.692 14516.000 15184.818 11421.286 13818.667 [8] 12748.000 16216.000 13237.000 12390.000 14779.091 10814.429 14769.846 [15] 11830.000 11930.312 10610.941 15922.182 11093.875 16208.538 10099.000 [22] 12148.688 11643.353 9248.947 8979.778 10243.526 12456.562 13306.467 [29] 10838.625 11826.625 10924.941 10674.300 9296.300 10432.211 12260.412 [36] 10910.222 9333.421 11654.059 11079.000 9839.143 7447.917 8361.600 [43] 8464.640 8219.923 10431.864 8536.400 8534.464 7996.464 6300.414 [50] 7594.567 7199.484 6151.483 6063.259 7268.909 6577.440 7707.261 [57] 6400.154 7041.043 8295.409 9612.333 > y [1] 10283.500 12791.000 12822.615 13844.667 15334.636 11187.500 13632.250 [8] 12297.467 15352.636 12695.154 12212.933 13682.727 11213.143 13949.231 [15] 11178.133 11800.875 11187.824 16455.273 11109.062 16529.692 10037.412 [22] 11680.250 11147.882 8630.000 9385.444 9763.737 12042.750 12947.067 [29] 10986.125 11647.312 10632.353 10218.300 9036.600 10295.316 11704.412 [36] 10680.944 9361.947 11305.353 10983.450 10061.619 8117.583 8866.480 [43] 8345.720 8528.308 10696.182 8590.840 8694.607 8124.571 7008.759 [50] 7882.467 7526.645 6762.759 6681.333 7854.682 6737.880 7894.435 [57] 6360.885 6934.957 8343.455 9106.944 > (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 26 2 37 -11 1.7388 0.1198 > (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 26 2 37 -11 1.3655 0.2468 > postscript(file="/var/www/html/rcomp/tmp/1npma1260469780.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 -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 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2900q1260469780.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/3ynob1260469780.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/4nvmn1260469780.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/5fdou1260469780.tab") > > system("convert tmp/1npma1260469780.ps tmp/1npma1260469780.png") > system("convert tmp/2900q1260469780.ps tmp/2900q1260469780.png") > system("convert tmp/3ynob1260469780.ps tmp/3ynob1260469780.png") > > > proc.time() user system elapsed 0.999 0.470 1.175