R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-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. > source('/home/pw/wessanet/cretab') > > > > myrfcuid = '' > > y <- c(8.00,4.00,.00,1.00,179.00,1261.00,7800.00,23729.00,38822.00,35855.00,23696.00,16932.00,11621.00,7095.00,6164.00,4607.00,3422.00,2679.00,2627.00,1746.00,4228.00,2938.00,2925.00,2113.00,3261.00,3990.00,5121.00,6712.00,8580.00,9463.00,8432.00,8942.00,10057.00,12398.00,13059.00,16656.00,30187.00,48277.00,77828.00,113712.0,138562.0,128064.0,119435.0,131486.0,134591.0,161817.0,179285.0,121738.0,122456.0,153761.0,103289.0,92428.00,75974.00) > x <- c(38.92,38.92,77.77,77.77,152.78,186.57,248.61,463.88,537.95,537.95,537.95,537.95,537.95,526.38,452.30,437.48,418.04,418.04,418.04,418.04,440.30,444.01,435.67,385.63,385.63,385.63,399.53,403.22,398.58,404.14,418.04,365.29,346.78,346.78,346.78,346.78,346.78,402.34,422.70,427.33,437.05,453.67,453.67,459.23,473.13,473.13,576.87,576.87,579.65,590.75,583.31,583.31,249.99) > par8 = '5' > par7 = '0' > par6 = '1' > par5 = '1' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '1' > ylab = 'y' > xlab = 'x' > par8 <- '5' > par7 <- '0' > par6 <- '1' > par5 <- '1' > par4 <- '1' > par3 <- '0' > par2 <- '1' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 (Thu, 22 Sep 2016 20:39:32 +0200) > #Author: root > #To cite this work: Wessa P., (2016), Bivariate Granger Causality (v1.0.4) 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 > # > library(lmtest) Loading required package: zoo Attaching package: 'zoo' The following objects are masked from 'package:base': as.Date, 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) > print(x) [1] 0.00 38.85 0.00 75.01 33.79 62.04 215.27 74.07 0.00 [10] 0.00 0.00 0.00 -11.57 -74.08 -14.82 -19.44 0.00 0.00 [19] 0.00 22.26 3.71 -8.34 -50.04 0.00 0.00 13.90 3.69 [28] -4.64 5.56 13.90 -52.75 -18.51 0.00 0.00 0.00 0.00 [37] 55.56 20.36 4.63 9.72 16.62 0.00 5.56 13.90 0.00 [46] 103.74 0.00 2.78 11.10 -7.44 0.00 -333.32 > print(y) [1] -4 -4 1 178 1082 6539 15929 15093 -2967 -12159 [11] -6764 -5311 -4526 -931 -1557 -1185 -743 -52 -881 2482 [21] -1290 -13 -812 1148 729 1131 1591 1868 883 -1031 [31] 510 1115 2341 661 3597 13531 18090 29551 35884 24850 [41] -10498 -8629 12051 3105 27226 17468 -57547 718 31305 -50472 [51] -10861 -16454 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: y ~ Lags(y, 1:5) + Lags(x, 1:5) Model 2: y ~ Lags(y, 1:5) Res.Df Df F Pr(>F) 1 36 2 41 -5 1.1833 0.3366 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: x ~ Lags(x, 1:5) + Lags(y, 1:5) Model 2: x ~ Lags(x, 1:5) Res.Df Df F Pr(>F) 1 36 2 41 -5 3.8193 0.007058 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/home/pw/wessanet/rcomp/tmp/16tj91612646498.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.013 0.007 0.007 0.005 -0.004 -0.015 -0.022 -0.010 0.033 0.097 0.170 -3 -2 -1 0 1 2 3 4 5 6 7 0.264 0.352 0.432 0.482 0.466 0.428 0.349 0.308 0.259 0.165 0.109 8 9 10 11 12 13 14 0.087 0.059 0.034 -0.006 -0.054 -0.079 -0.088 > (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.083 -0.083 -0.020 -0.014 -0.074 -0.056 -0.040 -0.076 -0.125 -0.081 -0.168 -3 -2 -1 0 1 2 3 4 5 6 7 0.024 0.050 -0.004 0.295 0.218 0.372 -0.149 0.018 0.375 -0.079 -0.136 8 9 10 11 12 13 14 0.028 -0.038 0.095 0.085 -0.143 -0.206 -0.187 > par(op) > dev.off() null device 1 > postscript(file="/home/pw/wessanet/rcomp/tmp/20rcs1612646498.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="/home/pw/wessanet/rcomp/tmp/3s2h81612646498.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 > > 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="/home/pw/wessanet/rcomp/tmp/4mzpo1612646498.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="/home/pw/wessanet/rcomp/tmp/5j84v1612646498.tab") > > try(system("convert /home/pw/wessanet/rcomp/tmp/16tj91612646498.ps /home/pw/wessanet/rcomp/tmp/16tj91612646498.png",intern=TRUE)) character(0) > try(system("convert /home/pw/wessanet/rcomp/tmp/20rcs1612646498.ps /home/pw/wessanet/rcomp/tmp/20rcs1612646498.png",intern=TRUE)) character(0) > try(system("convert /home/pw/wessanet/rcomp/tmp/3s2h81612646498.ps /home/pw/wessanet/rcomp/tmp/3s2h81612646498.png",intern=TRUE)) character(0) > > proc.time() user system elapsed 0.632 0.080 0.688