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 = '11' > par7 = '1' > par6 = '1' > par5 = '1' > par4 = '1' > 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] -4800.7 2030.4 -822.1 -1528.4 2975.2 1108.6 -4698.2 1961.3 1454.2 [10] -4113.1 3718.4 2032.0 -4388.2 3921.5 -2898.1 -443.3 1202.6 2785.3 [19] -6755.7 5005.5 -677.5 -2833.5 2777.7 1834.3 -2866.4 1080.8 -3272.6 [28] 4175.6 -1590.8 2644.5 -5481.2 3765.7 283.9 -2567.4 932.2 2283.5 [37] -12.8 -2042.2 -2099.8 3897.9 -1193.4 65.4 226.1 -2696.7 5449.5 [46] -5857.3 528.9 5145.1 -3543.7 -2033.8 193.6 1167.7 1529.2 1110.5 [55] -3066.8 698.9 2984.1 -3833.3 > y [1] -5286.7 1158.7 -1500.4 340.0 1842.5 1769.4 -4937.1 1270.0 2445.0 [10] -4241.8 2315.0 3610.4 -4335.7 2401.4 -3145.3 2137.8 -273.4 3039.7 [19] -6697.2 5280.3 -178.0 -4998.7 3262.9 3567.4 -3576.3 18.6 -2711.0 [28] 5519.4 -3249.6 3285.9 -5522.1 3892.6 557.3 -3656.2 1039.9 3375.5 [37] -825.0 -2228.3 -3354.9 7664.1 -3483.6 15.7 610.2 -2586.9 4991.1 [46] -5358.7 -674.2 7123.8 -4868.4 -2970.5 1289.1 2220.0 455.5 966.1 [55] -2739.1 712.5 2807.5 -3503.4 > (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 24 2 35 -11 0.8647 0.5836 > (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 24 2 35 -11 1.8135 0.1079 > postscript(file="/var/www/html/rcomp/tmp/1rh8u1260461674.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 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -0.114 -0.249 0.534 -0.310 -0.024 0.043 0.046 -0.089 0.167 -0.197 0.026 -3 -2 -1 0 1 2 3 4 5 6 7 0.258 -0.204 -0.448 0.946 -0.530 -0.014 0.127 -0.099 0.056 0.096 -0.241 8 9 10 11 12 13 14 0.151 0.146 -0.182 -0.266 0.546 -0.254 -0.063 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2c6nq1260461674.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/3uso21260461674.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/4om9y1260461674.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/5mups1260461674.tab") > > system("convert tmp/1rh8u1260461674.ps tmp/1rh8u1260461674.png") > system("convert tmp/2c6nq1260461674.ps tmp/2c6nq1260461674.png") > system("convert tmp/3uso21260461674.ps tmp/3uso21260461674.png") > > > proc.time() user system elapsed 0.966 0.493 1.148