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(286.1,307,358.1,341.8,378.8,375.2,295.6,362.7,409.6,336.8,389.1,389.3,355.9,542,648.4,452,582.4,506.5,555.5,530.4,609.4,543.9,616.2,634.6,541.7,549.8,627.6,797.4,689.8,1576.6,1572.1,1626.4,1972.4,1509.6,1584.9,1880,1324,1777.7,2172.4,1780.3,2134.9,1838.4,1557,1755.2,1702,1577.5,1485.9,2179.1,1740.9,1724.5,2328.1,1774.1,2224.2,1536.3,1521.2,2051.8,2483.1,1929.8,1808.6,2584.9,1997.9,1639.9,2379.1,1715,2750.9,1865.4,1647.4,2180.4,2593,2057.2,2635.8,2315.4,1863.6,2038,2235.8,2222.1,2636.9,2076.8,1935.5,2086.3,2470.9,1854.6,2041.3,2170.8,1905.5,2130.2,2791.2,2539.7,2661.3,1764.9,2176.9,2458.5,2179,2242.5,2089.6,2661.6,2112,2367.3,2543,2603.9,3146.7,1789.2,2114.8,2236.3,2288.1,2173.2,1877.7,2807.4,2357.4,2107.7,2856.8,2510.8,2875,2229.7,2055.1,2545.4,2775.1,2252.2,2091.7,2433) > x <- c(423.4,404.1,500,472.6,496.1,562,434.8,538.2,577.6,518.1,625.2,561.2,523.3,536.1,607.3,637.3,606.9,652.9,617.2,670.4,729.9,677.2,710,844.3,748.2,653.9,742.6,854.2,808.4,1819,1936.5,1966.1,2083.1,1620.1,1527.6,1795,1685.1,1851.8,2164.4,1981.8,1726.5,2144.6,1758.2,1672.9,1837.3,1596.1,1446,1898.4,1964.1,1755.9,2255.3,1881.2,2117.9,1656.5,1544.1,2098.9,2133.3,1963.5,1801.2,2365.4,1936.5,1667.6,1983.5,2058.6,2448.3,1858.1,1625.4,2130.6,2515.7,2230.2,2086.9,2235,2100.2,2288.6,2490,2573.7,2543.8,2004.7,2390,2338.4,2724.5,2292.5,2386,2477.9,2337,2605.1,2560.8,2839.3,2407.2,2085.2,2735.6,2798.7,3053.2,2405,2471.9,2727.3,2790.7,2385.4,3206.6,2705.6,3518.4,1954.9,2584.3,2535.8,2685.9,2866,2236.6,2934.9,2668.6,2371.2,3165.9,2887.2,3112.2,2671.2,2432.6,2812.3,3095.7,2862.9,2607.3,2862.5) > 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] 32.1 -24.7 57.4 -53.9 -19.9 91.5 -50.2 20.1 6.8 [10] -74.3 198.3 -58.2 -107.1 17.5 81.6 -15.4 964.6 153.2 [19] -23.6 57.5 -410.3 -125.3 133.1 -13.8 261.0 223.9 -294.2 [28] -209.5 -592.5 -503.9 -114.9 47.4 221.8 -57.6 185.0 175.6 [37] -374.9 186.8 -191.5 492.0 -879.5 274.0 640.1 -130.0 71.4 [46] -12.2 111.8 -494.6 -60.7 -183.5 449.2 153.0 -128.8 -120.3 [55] -49.6 350.7 -115.7 19.0 -416.1 294.1 457.3 -114.5 8.6 [64] -419.6 51.1 618.0 -556.8 1.0 -146.5 236.8 -56.2 -6.1 [73] 79.7 -245.7 194.8 -402.2 217.1 265.1 114.7 -131.6 -216.2 [82] -26.6 163.5 204.3 -673.4 865.5 -779.5 1244.9 -1241.5 -21.0 [91] -111.6 -104.4 828.3 -696.3 442.9 -329.7 107.9 -26.5 222.3 [100] -587.8 1122.5 -868.0 428.2 133.3 -412.9 373.8 -443.1 > y [1] 165.2 55.3 -180.1 93.4 -72.3 128.6 -92.2 32.1 7.3 [10] 20.0 18.2 -59.5 -178.0 -28.6 366.2 -238.0 962.7 -53.5 [19] 79.4 267.0 -397.3 3.0 276.7 -463.1 445.6 316.9 -561.9 [28] 462.2 -1183.3 -276.9 143.9 -399.2 338.3 -166.9 398.1 117.8 [37] -470.1 208.9 -161.9 95.5 -391.4 266.3 332.4 484.5 -428.8 [46] -29.6 83.1 -148.8 -341.6 135.6 -110.1 585.8 -197.6 -202.9 [55] 2.4 -18.7 17.5 699.8 -1096.7 135.2 532.4 -541.4 650.4 [64] -621.1 325.4 76.7 -382.2 -28.0 -80.5 -391.9 449.9 186.5 [73] 50.3 463.2 -237.8 -293.2 -336.3 553.3 130.8 -664.1 679.8 [82] -339.6 442.5 -284.3 30.6 -485.3 312.4 421.2 -461.1 -86.4 [91] -160.1 331.3 -178.4 -142.6 357.7 99.6 -505.0 573.4 -406.9 [100] -178.6 712.2 -500.2 368.8 177.9 -408.0 135.0 -588.4 > (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 97 2 100 -3 3.9919 0.009979 ** --- 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 97 2 100 -3 3.7789 0.013 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/1a95s1260313855.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 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 0.436 0.445 0.479 0.488 0.518 0.598 0.583 0.597 0.651 0.700 0.708 0.722 0.761 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 0.773 0.811 0.834 0.858 0.959 0.864 0.818 0.825 0.802 0.791 0.739 0.734 0.708 9 10 11 12 13 14 15 16 17 0.685 0.652 0.620 0.655 0.570 0.541 0.529 0.527 0.509 > (r <- ccf(x,y,main='Cross Correlation Function (transformed and differenced)',ylab='CCF',xlab='Lag (k)')) Autocorrelations of series 'X', by lag -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -0.009 -0.057 0.082 -0.204 0.071 -0.094 -0.026 0.079 -0.057 0.194 -0.125 -6 -5 -4 -3 -2 -1 0 1 2 3 4 -0.039 0.076 -0.121 -0.018 0.076 -0.127 0.445 -0.049 -0.208 0.250 -0.359 5 6 7 8 9 10 11 12 13 14 15 0.360 -0.275 0.035 0.069 0.025 0.078 -0.200 0.124 -0.196 0.147 -0.114 16 17 0.006 0.039 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2u3g71260313855.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/3422j1260313855.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/4989z1260313855.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/55bz91260313855.tab") > system("convert tmp/1a95s1260313855.ps tmp/1a95s1260313855.png") > system("convert tmp/2u3g71260313855.ps tmp/2u3g71260313855.png") > system("convert tmp/3422j1260313855.ps tmp/3422j1260313855.png") > > > proc.time() user system elapsed 0.967 0.505 1.201