This package provides a robust implementation of the Toda-Yamamoto causality test for time series analysis in R. The Toda-Yamamoto procedure is an extension of the Granger causality test that allows for testing causality between variables even when the series are non-stationary or have different orders of integration.
Traditional Granger causality tests require stationary time series data, which often means differencing or transforming data. This can lead to:
- Loss of information contained in the original levels
- Pre-testing bias from unit root and cointegration tests
- Incorrect model specification
The Toda-Yamamoto approach addresses these issues by allowing for the testing of Granger causality in level VAR models regardless of the integration or cointegration properties of the data.
This package requires:
- tidyverse
- vars
- aod
- purrr
- dplyr
# Example with two data frames containing time series
results <- toda_yamamoto(
list(df1 = df1, df2 = df2),
criterion = "AIC"
)
data_list
: A list of data frames where each data frame contains your time series variables- The first column should be the "effect" variable
- Remaining columns should be potential "cause" variables
criterion
: Selection criterion for determining optimal lag length (e.g., "AIC", "BIC", "HQ")
The function returns a list of data frames (one for each input data frame) with the following columns:
cause
: The variable being tested as the causal factoreffect
: The outcome variablechi_square
: Chi-square statistic from the Wald testp_value
: P-value for the causality hypothesis test
The Toda-Yamamoto procedure works as follows:
- Determine the maximum order of integration (d) for the variables in the system
- Select the optimal lag length (p) for the VAR model using information criteria
- Estimate a VAR(p+d) model (add d extra lags beyond the optimal lag length)
- Perform Wald tests on the first p lags only, ignoring the extra d lags
This implementation automatically selects the optimal lag length using the specified criterion and adds one additional lag, which is suitable for most economic and financial time series (which are typically I(1)).
# Create example time series data
set.seed(123)
n <- 200
x <- cumsum(rnorm(n))
y <- cumsum(0.7*x + rnorm(n))
z <- cumsum(0.3*y + rnorm(n))
df1 <- data.frame(y, x)
df2 <- data.frame(z, x, y)
# Apply Toda-Yamamoto test
results <- toda_yamamoto(
list(df1 = df1, df2 = df2),
criterion = "AIC"
)
# View results
results$df1
results$df2
Toda, H. Y., & Yamamoto, T. (1995). Statistical inference in vector autoregressions with possibly integrated processes. Journal of Econometrics, 66(1-2), 225-250.
Contributions are welcome! Please feel free to submit a Pull Request.