Test for Conditional Granger Causality
ms_condgrangertest.Rd
Faster implementation of the vector version of lmtest::grangertest()
with
conditioning on the history of a third variable. The function assumes time
series always have the same start date and periodicity, which is true for the data in this
package.
Usage
ms_condgrangertest(x, y, z, order = 1, na.action = stats::na.omit, ...)
Arguments
- x
response vector of observations.
- y
explanatory vector of observations.
- z
conditioning vector of observations
- order
number of lags (in frames).
- na.action
a function for eliminating NAs after aligning the series x and y.
- ...
passed to
lmtest::waldtest()
.
See also
Other Granger Causality:
autoplot.GrangerTime()
,
get_granger_interactions()
,
granger_test()
,
map_to_granger_test()
,
ms_grangertest1()
,
ms_grangertest2()
,
plot.GrangerInteraction()
,
plot_influence_diagram()
Examples
data(wages, package = "lmtest")
diff_wages <- diff(wages)
# Granger tests
lmtest::grangertest(diff_wages[, 'w'], diff_wages[, 'CPI'], order = 3)
#> Granger causality test
#>
#> Model 1: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3) + Lags(diff_wages[, "w"], 1:3)
#> Model 2: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3)
#> Res.Df Df F Pr(>F)
#> 1 7
#> 2 10 -3 7.5653 0.01338 *
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
ms_grangertest1(diff_wages[, 'w'], diff_wages[, 'CPI'], order = 3)
#> Granger causality test
#>
#> Model 1: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3) + Lags(diff_wages[, "w"], 1:3)
#> Model 2: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3)
#> Res.Df Df F Pr(>F)
#> 1 7
#> 2 10 -3 7.5653 0.01338 *
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
ms_grangertest2(diff_wages[, 'w'], diff_wages[, 'CPI'], order = 3)
#> Granger causality test
#>
#> Model 1: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3) + Lags(diff_wages[, "w"], 1:3)
#> Model 2: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3)
#> Res.Df Df F Pr(>F)
#> 1 7
#> 2 10 -3 7.5653 0.01338 *
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
ms_condgrangertest(diff_wages[, 'w'], diff_wages[, 'CPI'], diff_wages[, 'u'], order = 3)
#> Conditional Granger causality test
#> Model 1: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3) + Lags(diff_wages[, "w"], 1:3) + Lags(diff_wages[, "u"], 1:3)
#> Model 2: diff_wages[, "CPI"] ~ Lags(diff_wages[, "CPI"], 1:3) + Lags(diff_wages[, "u"], 1:3)
#>
#> Res.Df Df F Pr(>F)
#> 1 4
#> 2 7 -3 5.7136 0.06273 .
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1