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(106370,109375,116476,123297,114813,117925,126466,131235,120546,123791,129813,133463,122987,125418,130199,133016,121454,122044,128313,131556,120027,123001,130111,132524,123742,124931,133646,136557,127509,128945,137191,139716,129083,131604,139413,143125,133948,137116,144864,149277,138796,143258,150034,154708,144888,148762,156500,161088,152772,158011,163318,169969,162269,165765,170600,174681,166364,170240,176150,182056,172218,177856,182253,188090,176863,183273,187969,194650,183036,189516,193805,200499,188142,193732,197126,205140,191751,196700,199784,207360,196101,200824,205743,212489,200810,203683,207286,210910,194915,217920) > x <- c(100.3,101.9,102.1,103.2,103.7,106.2,107.7,109.9,111.7,114.9,116,118.3,120.4,126,128.1,130.1,130.8,133.6,134.2,135.5,136.2,139.1,139,139.6,138.7,140.9,141.3,141.8,142,144.5,144.6,145.5,146.8,149.5,149.9,150.1,150.9,152.8,153.1,154,154.9,156.9,158.4,159.7,160.2,163.2,163.7,164.4,163.7,165.5,165.6,166.8,167.5,170.6,170.9,172,171.8,173.9,174,173.8,173.9,176,176.6,178.2,179.2,181.3,181.8,182.9,183.8,186.3,187.4,189.2,189.7,191.9,192.6,193.7,194.2,197.6,199.3,201.4,203,206.3,207.1,209.8,211.1,215.3,217.4,215.5,210.9,212.6) > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '1' > par4 = '4' > 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] 9.000000e-01 1.300000e+00 1.100000e+00 1.300000e+00 7.000000e-01 [6] -4.000000e-01 1.000000e-01 3.000000e-01 2.400000e+00 1.000000e+00 [11] -3.000000e-01 -1.400000e+00 -2.800000e+00 -1.500000e+00 -7.000000e-01 [16] -2.842171e-14 1.000000e-01 -7.000000e-01 -7.000000e-01 -1.600000e+00 [21] -7.000000e-01 5.000000e-01 -1.000000e-01 1.100000e+00 3.000000e-01 [26] -3.000000e-01 4.000000e-01 1.100000e+00 2.000000e-01 3.000000e-01 [31] -7.000000e-01 -5.000000e-01 -8.000000e-01 -1.000000e-01 7.000000e-01 [36] 1.000000e-01 1.000000e-01 1.200000e+00 4.000000e-01 -4.000000e-01 [41] 1.000000e+00 -1.000000e+00 -6.000000e-01 -1.200000e+00 -1.200000e+00 [46] -4.000000e-01 5.000000e-01 1.400000e+00 1.300000e+00 2.000000e-01 [51] -1.000000e-01 -9.000000e-01 -1.000000e+00 -2.000000e-01 -1.300000e+00 [56] 3.000000e-01 0.000000e+00 5.000000e-01 1.800000e+00 9.000000e-01 [61] 2.842171e-14 -1.000000e-01 -5.000000e-01 -1.000000e-01 4.000000e-01 [66] 6.000000e-01 7.000000e-01 -4.000000e-01 -3.000000e-01 -4.000000e-01 [71] -7.000000e-01 0.000000e+00 1.200000e+00 1.000000e+00 1.000000e+00 [76] 1.100000e+00 -1.000000e-01 -9.000000e-01 6.000000e-01 -3.000000e-01 [81] 9.000000e-01 1.300000e+00 -4.600000e+00 -5.900000e+00 -2.500000e+00 > y [1] 107 1440 -2052 -2205 133 -2519 -1119 213 -814 -1241 -833 -1086 [13] -1841 1488 426 33 2384 841 -830 2747 -1785 1605 498 -266 [25] 247 -469 -386 -1585 1085 -437 1187 1456 647 -61 701 -1304 [37] 1294 -972 261 661 -588 962 -86 1504 1365 -2431 2063 616 [49] -1743 -472 -2570 -617 380 1075 1825 -1521 1762 -1513 -69 -1389 [61] 772 299 844 -387 70 -407 13 -743 -890 -895 1320 -1032 [73] -641 -310 -438 2130 -226 1835 -830 -420 -1850 -1316 -3122 -4316 [85] 20132 > (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 81 2 82 -1 18.717 4.294e-05 *** --- 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 81 2 82 -1 2.5239 0.1160 > postscript(file="/var/www/html/rcomp/tmp/1ltu11260375306.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 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 0.530 0.548 0.572 0.596 0.622 0.639 0.663 0.690 0.718 0.737 0.765 0.795 0.829 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 0.855 0.887 0.919 0.953 0.911 0.888 0.852 0.817 0.779 0.749 0.709 0.672 0.635 10 11 12 13 14 15 16 0.607 0.569 0.535 0.499 0.474 0.439 0.407 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 0.011 0.017 -0.022 0.050 0.088 0.030 0.009 0.041 -0.064 -0.070 0.071 -5 -4 -3 -2 -1 0 1 2 3 4 5 -0.036 0.029 0.030 -0.489 -0.437 -0.122 0.111 0.100 0.058 0.099 0.012 6 7 8 9 10 11 12 13 14 15 16 0.006 -0.014 -0.014 0.021 0.048 0.028 0.033 -0.036 0.033 0.037 0.030 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2bd1j1260375306.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/3vqt91260375306.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/4q86p1260375306.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/55bkr1260375306.tab") > > system("convert tmp/1ltu11260375306.ps tmp/1ltu11260375306.png") > system("convert tmp/2bd1j1260375306.ps tmp/2bd1j1260375306.png") > system("convert tmp/3vqt91260375306.ps tmp/3vqt91260375306.png") > > > proc.time() user system elapsed 0.934 0.489 1.475