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 = '6' > 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] 422.4 403.1 499.0 471.6 495.1 561.0 433.8 537.2 576.6 517.1 [11] 624.2 560.2 522.3 535.1 606.3 636.3 605.9 651.9 616.2 669.4 [21] 728.9 676.2 709.0 843.3 747.2 652.9 741.6 853.2 807.4 1818.0 [31] 1935.5 1965.1 2082.1 1619.1 1526.6 1794.0 1684.1 1850.8 2163.4 1980.8 [41] 1725.5 2143.6 1757.2 1671.9 1836.3 1595.1 1445.0 1897.4 1963.1 1754.9 [51] 2254.3 1880.2 2116.9 1655.5 1543.1 2097.9 2132.3 1962.5 1800.2 2364.4 [61] 1935.5 1666.6 1982.5 2057.6 2447.3 1857.1 1624.4 2129.6 2514.7 2229.2 [71] 2085.9 2234.0 2099.2 2287.6 2489.0 2572.7 2542.8 2003.7 2389.0 2337.4 [81] 2723.5 2291.5 2385.0 2476.9 2336.0 2604.1 2559.8 2838.3 2406.2 2084.2 [91] 2734.6 2797.7 3052.2 2404.0 2470.9 2726.3 2789.7 2384.4 3205.6 2704.6 [101] 3517.4 1953.9 2583.3 2534.8 2684.9 2865.0 2235.6 2933.9 2667.6 2370.2 [111] 3164.9 2886.2 3111.2 2670.2 2431.6 2811.3 3094.7 2861.9 2606.3 2861.5 > y [1] 285.1 306.0 357.1 340.8 377.8 374.2 294.6 361.7 408.6 335.8 [11] 388.1 388.3 354.9 541.0 647.4 451.0 581.4 505.5 554.5 529.4 [21] 608.4 542.9 615.2 633.6 540.7 548.8 626.6 796.4 688.8 1575.6 [31] 1571.1 1625.4 1971.4 1508.6 1583.9 1879.0 1323.0 1776.7 2171.4 1779.3 [41] 2133.9 1837.4 1556.0 1754.2 1701.0 1576.5 1484.9 2178.1 1739.9 1723.5 [51] 2327.1 1773.1 2223.2 1535.3 1520.2 2050.8 2482.1 1928.8 1807.6 2583.9 [61] 1996.9 1638.9 2378.1 1714.0 2749.9 1864.4 1646.4 2179.4 2592.0 2056.2 [71] 2634.8 2314.4 1862.6 2037.0 2234.8 2221.1 2635.9 2075.8 1934.5 2085.3 [81] 2469.9 1853.6 2040.3 2169.8 1904.5 2129.2 2790.2 2538.7 2660.3 1763.9 [91] 2175.9 2457.5 2178.0 2241.5 2088.6 2660.6 2111.0 2366.3 2542.0 2602.9 [101] 3145.7 1788.2 2113.8 2235.3 2287.1 2172.2 1876.7 2806.4 2356.4 2106.7 [111] 2855.8 2509.8 2874.0 2228.7 2054.1 2544.4 2774.1 2251.2 2090.7 2432.0 > (gyx <- grangertest(y ~ x, order=par8)) Granger causality test Model 1: ~ Lags(, 1:6) + Lags(, 1:6) Model 2: ~ Lags(, 1:6) Res.Df Df F Pr(>F) 1 101 2 107 -6 1.3542 0.2405 > (gxy <- grangertest(x ~ y, order=par8)) Granger causality test Model 1: ~ Lags(, 1:6) + Lags(, 1:6) Model 2: ~ Lags(, 1:6) Res.Df Df F Pr(>F) 1 101 2 107 -6 4.41 0.0005325 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > postscript(file="/var/www/html/rcomp/tmp/1njw61260372214.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 -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 > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2e4ti1260372214.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/3r5hl1260372214.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/4ljd91260372214.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/5tqtj1260372214.tab") > system("convert tmp/1njw61260372214.ps tmp/1njw61260372214.png") > system("convert tmp/2e4ti1260372214.ps tmp/2e4ti1260372214.png") > system("convert tmp/3r5hl1260372214.ps tmp/3r5hl1260372214.png") > > > proc.time() user system elapsed 0.938 0.476 1.126