granger_test: Granger causality test (bivariate).

View source: R/bruceR-stats_5_advance.R

granger_testR Documentation

Granger causality test (bivariate).

Description

Granger test of predictive causality (between two time series) using the lmtest::grangertest() function.

Usage

granger_test(formula, data, lags = 1:5, test.reverse = TRUE, file = NULL, ...)

Arguments

formula

Model formula like y ~ x.

data

Data frame.

lags

Time lags. Defaults to 1:5.

test.reverse

Whether to test reverse causality. Defaults to TRUE.

file

File name of MS Word (.doc).

...

Further arguments passed to lmtest::grangertest(). For example, you may use robust standard errors by specifying the vcov argument (see GitHub Issue #23).

Details

Granger causality test examines whether the lagged values of a predictor have an incremental role in predicting (i.e., help to predict) an outcome when controlling for the lagged values of the outcome.

Granger causality does not necessarily constitute a true causal effect.

Value

A data frame of results.

See Also

ccf_plot, granger_causality

Examples

granger_test(chicken ~ egg, data=lmtest::ChickEgg)
granger_test(chicken ~ egg, data=lmtest::ChickEgg, lags=1:10, file="Granger.doc")
unlink("Granger.doc")  # delete file for code check


bruceR documentation built on June 22, 2024, 12:26 p.m.