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(13132.1,17665.9,16913,17318.8,16224.2,15469.6,16557.5,19414.8,17335,16525.2,18160.4,15553.8,15262.2,18581,17564.1,18948.6,17187.8,17564.8,17668.4,20811.7,17257.8,18984.2,20532.6,17082.3,16894.9,20274.9,20078.6,19900.9,17012.2,19642.9,19024,21691,18835.9,19873.4,21468.2,19406.8,18385.3,20739.3,22268.3,21569,17514.8,21124.7,21251,21393,22145.2,20310.5,23466.9,21264.6,18388.1,22635.4,22014.3,18422.7,16120.2,16037.7,16410.7,17749.8,16349.8,15662.3,17782.3,16398.9) > x <- c(12002.4,15525.5,14247.9,15000.7,14931.4,13333.7,14711.2,17197.3,14985.2,14734.4,15937.8,13028.1,13836.8,16677.5,15130,17504,16979.9,16012.5,16247.7,19268.2,15533,16803.3,17396.1,15155.4,15692.4,18063.7,17568.6,18154.3,15467.4,16956.1,16854,19396.4,16457.6,17284.5,18395.3,16938.7,16414.3,18173.4,19919.7,19623.8,17228.1,18730.3,19039.1,19413.3,20013.6,17917.2,21270.3,18766.1,16790.8,19960.6,19586.7,17179,14964.9,13918.5,14401.3,15994.6,14521.1,13746.5,15956,14332.2) > par8 = '1' > 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/ > #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] -682.4 -269.9 1621.2 -454.8 630.3 -1142.3 534.4 -1523.1 1521.1 [10] -610.6 669.0 -271.7 -469.4 1052.4 -1788.3 -2162.8 2456.1 -337.3 [19] -478.1 796.4 -443.4 518.0 784.1 -1061.4 -612.2 2241.4 -881.6 [28] 291.2 13.5 410.9 -2168.2 3539.1 -2923.3 2242.3 -1047.6 -1450.9 [37] 1410.7 -2120.2 -2111.8 181.6 -2548.6 174.0 1219.1 -2073.8 1321.8 [46] -1143.6 880.4 > y [1] -1215.0 -264.0 978.7 -666.2 1131.6 -984.3 286.0 -1474.1 2536.2 [10] -86.8 -843.7 104.2 61.2 820.6 -1562.2 -1127.9 2253.7 -722.5 [19] -476.3 698.8 -688.9 46.4 1388.9 -834.1 -1026.0 1725.3 -521.6 [28] -1165.5 979.2 745.2 -2525.0 3607.3 -2872.2 1561.6 -140.9 -1855.0 [37] 1893.3 -2150.1 -2892.3 1751.7 -3692.4 246.7 1197.1 -2152.2 1147.2 [46] -1036.4 818.9 > (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 43 2 44 -1 0.5837 0.4490 > (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 43 2 44 -1 1.7629 0.1913 > postscript(file="/var/www/html/rcomp/tmp/1zc4y1260389036.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.128 -0.081 0.215 0.059 -0.013 0.081 0.167 0.189 0.315 0.334 0.445 -3 -2 -1 0 1 2 3 4 5 6 7 0.495 0.380 0.494 0.970 0.517 0.444 0.436 0.394 0.419 0.301 0.136 8 9 10 11 12 13 14 0.217 0.124 -0.051 0.074 0.238 -0.044 -0.099 > (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.031 -0.050 0.071 -0.075 -0.045 0.209 -0.358 0.256 0.031 -0.247 0.303 -2 -1 0 1 2 3 4 5 6 7 8 0.040 -0.472 0.919 -0.568 0.188 0.176 -0.296 0.249 -0.030 -0.253 0.262 9 10 11 12 13 -0.100 -0.077 0.127 -0.149 0.081 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/201jg1260389036.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/39qee1260389036.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/4mk5t1260389036.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/5jtds1260389036.tab") > > system("convert tmp/1zc4y1260389036.ps tmp/1zc4y1260389036.png") > system("convert tmp/201jg1260389036.ps tmp/201jg1260389036.png") > system("convert tmp/39qee1260389036.ps tmp/39qee1260389036.png") > > > proc.time() user system elapsed 0.927 0.488 1.095