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(258596,259056,264193,260325,261890,260683,257941,258151,262434,261577,262188,261092,263571,265031,270388,265458,266218,266386,263486,263620,267755,266554,266981,264133,265980,267183,272113,267261,269117,269034,266609,267261,271406,269529,270282,268663,269847,270998,277068,273529,275307,276488,274455,274507,279528,277673,278102,275131,277162,278799,285502,280672,281342,281132,278286,279120,289131,294453,295733,302233,308859,311054,318130,315823,316517,316907,314969,316107) > x <- c(269285,269829,270911,266844,271244,269907,271296,270157,271322,267179,264101,265518,269419,268714,272482,268351,268175,270674,272764,272599,270333,270846,270491,269160,274027,273784,276663,274525,271344,271115,270798,273911,273985,271917,273338,270601,273547,275363,281229,277793,279913,282500,280041,282166,290304,283519,287816,285226,287595,289741,289148,288301,290155,289648,288225,289351,294735,305333,309030,310215,321935,325734,320846,323023,319753,321753,320757,324479) > par8 = '3' > 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#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] -1249 2686 -64 -4576 3836 701 974 -3431 4656 2723 -2748 966 [13] 462 -889 1993 -3005 -2728 -2407 3278 2340 -2581 1776 -1406 -1921 [25] 2059 2987 -1298 5301 2816 -2142 -988 8064 -4717 2876 147 -577 [37] 330 -6459 2589 -266 -3094 1036 -999 -2754 17383 -600 3775 9351 [49] 1653 -4295 3024 -5124 2507 427 2596 > y [1] 1000 220 -1062 -805 1375 -158 -76 -148 -344 -184 -1752 -632 [13] -257 -427 78 1096 -251 475 518 10 -676 326 1229 -663 [25] -52 1140 1313 -78 1264 392 -600 876 22 -324 -1352 847 [37] 486 633 -1291 -1108 -1391 -813 782 4990 7177 851 9471 4595 [49] 558 373 2523 24 600 908 304 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:3) + Lags(, 1:3) Model 2: ~ Lags(, 1:3) Res.Df Df F Pr(>F) 1 45 2 48 -3 2.3523 0.0848 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:3) + Lags(, 1:3) Model 2: ~ Lags(, 1:3) Res.Df Df F Pr(>F) 1 45 2 48 -3 5.213 0.003559 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/1lr1n1260984800.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 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 0.203 0.223 0.240 0.259 0.278 0.326 0.380 0.439 0.518 0.605 0.673 0.749 0.811 -2 -1 0 1 2 3 4 5 6 7 8 9 10 0.875 0.927 0.982 0.920 0.857 0.789 0.717 0.642 0.559 0.490 0.426 0.374 0.335 11 12 13 14 15 0.290 0.255 0.236 0.221 0.206 > (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.119 0.102 -0.046 -0.048 -0.075 -0.156 0.019 -0.191 -0.034 -0.043 -0.059 -3 -2 -1 0 1 2 3 4 5 6 7 0.139 0.317 -0.032 0.473 0.338 0.103 0.110 0.065 -0.160 -0.063 -0.078 8 9 10 11 12 13 14 -0.034 0.048 0.040 -0.010 -0.005 0.039 -0.075 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2gq8n1260984800.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/30bdo1260984800.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/4witl1260984800.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/5qqz21260984800.tab") > > try(system("convert tmp/1lr1n1260984800.ps tmp/1lr1n1260984800.png",intern=TRUE)) character(0) > try(system("convert tmp/2gq8n1260984800.ps tmp/2gq8n1260984800.png",intern=TRUE)) character(0) > try(system("convert tmp/30bdo1260984800.ps tmp/30bdo1260984800.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.917 0.468 1.319