R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(0.6923,0.6886,0.6855,0.6745,0.6769,0.6758,0.6896,0.6843,0.6818,0.6774,0.6821,0.6885,0.6829,0.6796,0.6976,0.6924,0.6849,0.6921,0.6839,0.6727,0.6776,0.6692,0.6738,0.6740,0.6635,0.6737,0.6788,0.6828,0.6795,0.6740,0.6744,0.6764,0.6987,0.6967,0.7116,0.7357,0.7455,0.7639,0.7958,0.7864,0.7853,0.7903,0.7866,0.8039,0.7916,0.7903,0.8242,0.9567,0.8850,0.8865,0.9258,0.8948,0.8762,0.8527,0.8536,0.8805,0.9155,0.8961,0.9127,0.8857) > x <- c(1.3031,1.3241,1.2961,1.2865,1.2305,1.2101,1.2125,1.2350,1.2014,1.1992,1.1791,1.1832,1.2159,1.1922,1.2114,1.2614,1.2812,1.2786,1.2772,1.2815,1.2679,1.2765,1.3247,1.3191,1.3029,1.3234,1.3354,1.3651,1.3453,1.3534,1.3706,1.3638,1.4268,1.4485,1.4635,1.4587,1.4876,1.5189,1.5783,1.5633,1.5554,1.5757,1.5593,1.4660,1.4065,1.2759,1.2705,1.3954,1.2793,1.2694,1.3282,1.3230,1.4135,1.4042,1.4253,1.4322,1.4632,1.4713,1.5016,1.4318) > par8 = '1' > par7 = '0' > par6 = '1' > par5 = '0.0' > par4 = '12' > par3 = '0' > par2 = '1' > par1 = '0.0' > #'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 > 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] 0.015986942 -0.021373228 -0.007434403 -0.044504762 -0.016717590 [6] 0.001981343 0.018386626 -0.027583427 -0.001832876 -0.016903232 [11] 0.003471197 0.027261911 -0.019684204 0.015976376 0.040445500 [16] 0.015574924 -0.002031409 -0.001095547 0.003361085 -0.010669278 [21] 0.006759969 0.037064061 -0.004236333 -0.012357137 0.015611633 [26] 0.009026690 0.021996814 -0.014610650 0.006002908 0.012628655 [31] -0.004973679 0.045159253 0.015094364 0.010302289 -0.003285199 [36] 0.019618455 0.020822306 0.038361930 -0.009549347 -0.005066224 [41] 0.012966871 -0.010462615 -0.061699399 -0.041433255 -0.097452537 [46] -0.004241288 0.093770589 -0.086868059 -0.007768705 0.045280294 [51] -0.003922757 0.066167013 -0.006601153 0.014914572 0.004829406 [56] 0.021414095 0.005520546 0.020384843 -0.047598812 > y [1] -0.0053588368 -0.0045120519 -0.0161768234 0.0035518759 -0.0016263772 [6] 0.0202145451 -0.0077153014 -0.0036600583 -0.0064744193 0.0069143343 [11] 0.0093390435 -0.0081668822 -0.0048440462 0.0261414828 -0.0074820493 [16] -0.0108909811 0.0104576116 -0.0119187457 -0.0165122431 0.0072576783 [21] -0.0124741742 0.0068503619 0.0002967799 -0.0157012571 0.0152560542 [26] 0.0075416254 0.0058754576 -0.0048447573 -0.0081271227 0.0005932958 [31] 0.0029612103 0.0324368485 -0.0028665635 0.0211610538 0.0333064711 [36] 0.0132327073 0.0243817563 0.0409110074 -0.0118823292 -0.0013997585 [41] 0.0063468098 -0.0046927602 0.0217550233 -0.0154186696 -0.0016435935 [46] 0.0420005987 0.1490766438 -0.0779022177 0.0016934805 0.0433771031 [51] -0.0340579990 -0.0210058542 -0.0271865896 0.0010549142 0.0310272279 [56] 0.0389804362 -0.0214183502 0.0183552256 -0.0300289467 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: y ~ Lags(y, 1:1) + Lags(x, 1:1) Model 2: y ~ Lags(y, 1:1) Res.Df Df F Pr(>F) 1 55 2 56 -1 4.5566 0.03726 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: x ~ Lags(x, 1:1) + Lags(y, 1:1) Model 2: x ~ Lags(x, 1:1) Res.Df Df F Pr(>F) 1 55 2 56 -1 1.2262 0.2730 > postscript(file="/var/www/rcomp/tmp/14loe1292164497.ps",horizontal=F,onefile=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.712 0.681 0.677 0.658 0.630 0.623 0.581 0.546 0.525 0.499 0.466 -3 -2 -1 0 1 2 3 4 5 6 7 0.453 0.427 0.445 0.475 0.425 0.388 0.359 0.318 0.283 0.236 0.186 8 9 10 11 12 13 14 0.142 0.100 0.048 0.010 -0.035 -0.076 -0.090 > (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.129 0.029 -0.118 0.076 -0.053 0.275 0.148 -0.157 0.082 0.077 -0.110 -3 -2 -1 0 1 2 3 4 5 6 7 0.131 -0.358 -0.302 0.537 -0.128 -0.089 0.058 -0.044 0.116 0.012 -0.076 8 9 10 11 12 13 14 -0.122 0.047 -0.130 0.024 -0.097 -0.140 -0.047 > par(op) > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/24loe1292164497.ps",horizontal=F,onefile=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/rcomp/tmp/3fc6h1292164497.ps",horizontal=F,onefile=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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/4t4m81292164497.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/rcomp/tmp/5fnkw1292164497.tab") > > try(system("convert tmp/14loe1292164497.ps tmp/14loe1292164497.png",intern=TRUE)) character(0) > try(system("convert tmp/24loe1292164497.ps tmp/24loe1292164497.png",intern=TRUE)) character(0) > try(system("convert tmp/3fc6h1292164497.ps tmp/3fc6h1292164497.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.130 0.640 1.836