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 = '1' > 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] 269284 269828 270910 266843 271243 269906 271295 270156 271321 267178 [11] 264100 265517 269418 268713 272481 268350 268174 270673 272763 272598 [21] 270332 270845 270490 269159 274026 273783 276662 274524 271343 271114 [31] 270797 273910 273984 271916 273337 270600 273546 275362 281228 277792 [41] 279912 282499 280040 282165 290303 283518 287815 285225 287594 289740 [51] 289147 288300 290154 289647 288224 289350 294734 305332 309029 310214 [61] 321934 325733 320845 323022 319752 321752 320756 324478 > y [1] 258595 259055 264192 260324 261889 260682 257940 258150 262433 261576 [11] 262187 261091 263570 265030 270387 265457 266217 266385 263485 263619 [21] 267754 266553 266980 264132 265979 267182 272112 267260 269116 269033 [31] 266608 267260 271405 269528 270281 268662 269846 270997 277067 273528 [41] 275306 276487 274454 274506 279527 277672 278101 275130 277161 278798 [51] 285501 280671 281341 281131 278285 279119 289130 294452 295732 302232 [61] 308858 311053 318129 315822 316516 316906 314968 316106 > (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 64 2 65 -1 12.438 0.000784 *** --- 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:1) + Lags(, 1:1) Model 2: ~ Lags(, 1:1) Res.Df Df F Pr(>F) 1 64 2 65 -1 0.8929 0.3483 > postscript(file="/var/www/html/rcomp/tmp/1p1hj1260545606.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 -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 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2mms41260545606.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/3qv2h1260545606.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/4v9lp1260545606.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/5ytl11260545606.tab") > > system("convert tmp/1p1hj1260545606.ps tmp/1p1hj1260545606.png") > system("convert tmp/2mms41260545606.ps tmp/2mms41260545606.png") > system("convert tmp/3qv2h1260545606.ps tmp/3qv2h1260545606.png") > > > proc.time() user system elapsed 0.938 0.481 1.120