| Title: | Multiple Granger Causality Tests for Time Series and Panel Data |
|---|---|
| Description: | Comprehensive suite of Granger causality tests for time series and panel data. For time series: Toda-Yamamoto (1995) <doi:10.1016/0304-4076(94)01616-8>, Fourier-based tests with single frequency (Enders and Jones, 2016) <doi:10.1515/snde-2014-0101> and cumulative frequencies (Nazlioglu et al., 2019) <doi:10.1080/1540496X.2018.1434072>, quantile causality tests (Cai et al., 2023) <doi:10.1016/j.frl.2023.104327>, and Bootstrap Fourier Granger Causality in Quantiles (Cheng et al., 2021) <doi:10.1007/s12076-020-00263-0>. For panel data: Panel Fourier Toda-Yamamoto (Yilanci and Gorus, 2020) <doi:10.1007/s11356-020-10092-9> and Panel Quantile Causality tests (Wang and Nguyen, 2022) <doi:10.1080/1331677X.2021.1952089>, as well as Group-Mean and Pooled Fully Modified OLS estimators for panel cointegrating polynomial regressions (Wagner and Reichold, 2023) <doi:10.1080/07474938.2023.2178141>. All tests include bootstrap inference for robust p-values. |
| Authors: | Muhammad Alkhalaf [aut, cre, cph] (ORCID: <https://orcid.org/0009-0002-2677-9246>) |
| Maintainer: | Muhammad Alkhalaf <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.1 |
| Built: | 2026-05-28 06:11:39 UTC |
| Source: | https://github.com/muhammedalkhalaf/caustests |
Performs various Granger causality tests including Toda-Yamamoto, Fourier-based tests (single and cumulative frequency), and quantile causality tests with bootstrap inference.
caustests( data, test, pmax = 8, ic = 1, nboot = 1000, kmax = 3, dmax = NULL, quantiles = seq(0.1, 0.9, 0.1), verbose = TRUE )caustests( data, test, pmax = 8, ic = 1, nboot = 1000, kmax = 3, dmax = NULL, quantiles = seq(0.1, 0.9, 0.1), verbose = TRUE )
data |
A data frame or matrix with time series variables (columns). |
test |
Integer 1-7 specifying the test type:
|
pmax |
Maximum lag order for model selection (default: 8). |
ic |
Information criterion: 1 for AIC, 2 for SBC/BIC (default: 1). |
nboot |
Number of bootstrap replications (default: 1000). |
kmax |
Maximum Fourier frequency (default: 3, used for tests 2-5, 7). |
dmax |
Extra lags for Toda-Yamamoto augmentation. If NULL, automatically set to 0 for tests 2, 4 (differences) and 1 for tests 1, 3, 5, 6, 7 (levels). |
quantiles |
Numeric vector of quantiles for tests 6-7 (default: seq(0.1, 0.9, 0.1)). |
verbose |
Logical; print progress messages (default: TRUE). |
The package implements seven Granger causality tests:
Test 1: Toda-Yamamoto (1995) Standard Granger causality in levels using VAR with extra lags equal to the maximum integration order (dmax). This approach is robust to unknown integration and cointegration properties.
Tests 2-3: Single Fourier Frequency Incorporate a single Fourier frequency to capture smooth structural breaks. Test 2 uses first differences, Test 3 uses levels (Toda-Yamamoto style).
Tests 4-5: Cumulative Fourier Frequency Use cumulative Fourier frequencies (1 to k) for more flexible break patterns. Test 4 uses first differences, Test 5 uses levels.
Test 6: Quantile Toda-Yamamoto Extends Toda-Yamamoto to quantile regression, allowing causality analysis across different quantiles of the conditional distribution.
Test 7: Bootstrap Fourier Granger Causality in Quantiles (BFGC-Q) Combines Fourier flexibility with quantile regression for robust inference under structural breaks and across quantiles.
An object of class "caustests" containing:
results |
Data frame with test results for each direction |
test |
Test number used |
test_name |
Name of the test |
pmax |
Maximum lag considered |
ic |
Information criterion used |
nboot |
Number of bootstrap replications |
kmax |
Maximum Fourier frequency |
dmax |
Augmentation lags |
quantiles |
Quantiles used (for tests 6-7) |
quantile_results |
Detailed quantile results (for tests 6-7) |
Toda, H. Y., & Yamamoto, T. (1995). Statistical inference in vector autoregressions with possibly integrated processes. Journal of Econometrics, 66(1-2), 225-250. doi:10.1016/0304-4076(94)01616-8
Enders, W., & Jones, P. (2016). Grain prices, oil prices, and multiple smooth breaks in a VAR. Studies in Nonlinear Dynamics & Econometrics, 20(4), 399-419. doi:10.1515/snde-2014-0101
Nazlioglu, S., Gormus, N. A., & Soytas, U. (2016). Oil prices and real estate investment trusts (REITs): Gradual-shift causality and volatility transmission analysis. Energy Economics, 60, 168-175. doi:10.1016/j.eneco.2016.09.009
Nazlioglu, S., Soytas, U., & Gormus, N. A. (2019). Oil prices and monetary policy in emerging markets: Structural shifts in causal linkages. Emerging Markets Finance and Trade, 55(1), 105-117. doi:10.1080/1540496X.2018.1434072
Cai, Y., Chang, T., Xiang, Y., & Chang, H. L. (2023). Testing Granger causality in quantiles between the stock and the foreign exchange markets of Japan. Finance Research Letters, 58, 104327. doi:10.1016/j.frl.2023.104327
Cheng, S. C., Hsueh, H. P., Ranjbar, O., Wang, M. C., & Chang, T. (2021). Bootstrap Fourier Granger causality test in quantiles and the asymmetric causal relationship between CO2 emissions and economic growth. Letters in Spatial and Resource Sciences, 14, 31-49. doi:10.1007/s12076-020-00263-0
# Load example data data(caustests_data) # Test 1: Toda-Yamamoto test result1 <- caustests(caustests_data, test = 1, nboot = 199) print(result1) summary(result1) # Test 3: Single Fourier Toda-Yamamoto result3 <- caustests(caustests_data, test = 3, kmax = 2, nboot = 199) print(result3) # Test 6: Quantile causality (fewer quantiles for speed) result6 <- caustests(caustests_data, test = 6, quantiles = c(0.25, 0.50, 0.75), nboot = 199) print(result6)# Load example data data(caustests_data) # Test 1: Toda-Yamamoto test result1 <- caustests(caustests_data, test = 1, nboot = 199) print(result1) summary(result1) # Test 3: Single Fourier Toda-Yamamoto result3 <- caustests(caustests_data, test = 3, kmax = 2, nboot = 199) print(result3) # Test 6: Quantile causality (fewer quantiles for speed) result6 <- caustests(caustests_data, test = 6, quantiles = c(0.25, 0.50, 0.75), nboot = 199) print(result6)
A simulated dataset containing three time series variables for demonstrating Granger causality tests. The data includes one dependent variable (Y) and two potential causal variables (X1, X2) with known causal relationships.
caustests_datacaustests_data
A data frame with 200 observations and 3 variables:
Dependent variable, generated as AR(2) plus causal effects from X1
First explanatory variable, AR(1) process
Second explanatory variable, independent AR(1) process
The data generating process is:
X1 and X2 are independent AR(1) processes
Y depends on its own lags plus lagged values of X1 (but not X2)
This creates a true causal relationship from X1 to Y
There is no true causality from X2 to Y or from Y to X1/X2
This allows users to verify that the causality tests correctly identify the causal direction X1 => Y while finding no significant causality in other directions (with appropriate sample sizes and test settings).
Simulated data for package demonstration
data(caustests_data) head(caustests_data) summary(caustests_data) # Check correlations cor(caustests_data)data(caustests_data) head(caustests_data) summary(caustests_data) # Check correlations cor(caustests_data)
Returns the Grunfeld (1958) balanced panel dataset for examples.
grunfeld_cmg()grunfeld_cmg()
A data frame with columns firm, year,
invest, and mvalue.
dat <- grunfeld_cmg() head(dat)dat <- grunfeld_cmg() head(dat)
Returns a small balanced panel dataset (subset of Grunfeld 1958) for use in examples and testing.
grunfeld_panel()grunfeld_panel()
A data frame with columns firm, year,
invest, and mvalue.
dat <- grunfeld_panel() head(dat)dat <- grunfeld_panel() head(dat)
Creates diagnostic plots for quantile causality tests (tests 6-7).
## S3 method for class 'caustests' plot(x, which = 1, type = "both", ...)## S3 method for class 'caustests' plot(x, which = 1, type = "both", ...)
x |
An object of class |
which |
Which direction to plot (default: 1, first direction). |
type |
Plot type: "wald" for Wald statistics, "pval" for p-values, or "both" (default). |
... |
Additional arguments passed to |
Invisibly returns the plotted data.
data(caustests_data) result <- caustests(caustests_data, test = 6, quantiles = c(0.25, 0.50, 0.75), nboot = 199) plot(result)data(caustests_data) result <- caustests(caustests_data, test = 6, quantiles = c(0.25, 0.50, 0.75), nboot = 199) plot(result)
Print Method for xtpcaus Objects
## S3 method for class 'xtpcaus' print(x, ...)## S3 method for class 'xtpcaus' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
Invisibly returns x.
Print Method for xtpcmg Objects
## S3 method for class 'xtpcmg' print(x, ...)## S3 method for class 'xtpcmg' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
Invisibly returns x.
Summary Method for xtpcaus Objects
## S3 method for class 'xtpcaus' summary(object, ...)## S3 method for class 'xtpcaus' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
Invisibly returns object.
Summary Method for xtpcmg Objects
## S3 method for class 'xtpcmg' summary(object, ...)## S3 method for class 'xtpcmg' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
Invisibly returns object.
Tests whether x Granger-causes y in a balanced panel using
either the Panel Fourier Toda-Yamamoto (PFTY) test or the Panel Quantile
Causality (PQC) test.
xtpcaus( data, y, x, panel_id, time_id, test = c("pfty", "pqc"), pmax = 4L, dmax = 1L, nboot = 499L, kmax = 3L, ic = c("aic", "bic"), quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9), seed = -1L )xtpcaus( data, y, x, panel_id, time_id, test = c("pfty", "pqc"), pmax = 4L, dmax = 1L, nboot = 499L, kmax = 3L, ic = c("aic", "bic"), quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9), seed = -1L )
data |
A data frame in long format. |
y |
Character. Name of the dependent (caused) variable. |
x |
Character. Name of the independent (causing) variable. |
panel_id |
Character. Name of the panel identifier variable. |
time_id |
Character. Name of the time variable. |
test |
Character. Test type: |
pmax |
Integer. Maximum lag order for selection. Default is |
dmax |
Integer. Maximum integration order for Toda-Yamamoto
augmentation. Default is |
nboot |
Integer. Number of bootstrap replications. Minimum 99.
Default is |
kmax |
Integer. Maximum Fourier frequency (PFTY only). Default is
|
ic |
Character. Information criterion: |
quantiles |
Numeric vector. Quantile grid for PQC test (values strictly
between 0 and 1). Default is
|
seed |
Integer. Random seed for bootstrap. |
An object of class "xtpcaus" containing:
Character. "pfty" or "pqc".
Integer. Number of panel units.
Integer. Number of time periods.
Integer. Number of bootstrap replications.
Character. Name of the y variable.
Character. Name of the x variable.
For PFTY:
Numeric. Fisher panel statistic.
Integer. Degrees of freedom (2*N).
Numeric. Fisher p-value.
Numeric. Average individual Wald statistic.
Numeric. Dumitrescu-Hurlin Z-bar statistic.
Numeric. Z-bar p-value.
Numeric vector. Individual Wald statistics (length N).
Integer vector. Optimal Fourier frequencies (length N).
Numeric vector. Bootstrap p-values (length N).
Integer vector. Selected lag orders (length N).
For PQC:
Numeric vector. Quantiles tested.
Numeric vector. Wald statistics per quantile (x => y).
Numeric vector. Bootstrap p-values per quantile (x => y).
Numeric vector. Wald statistics per quantile (y => x).
Numeric vector. Bootstrap p-values per quantile (y => x).
Numeric. Sup-Wald statistic for x => y.
Numeric. Sup-Wald statistic for y => x.
Integer. Selected optimal lag.
Chuang, C.C., Kuan, C.M. and Lin, H.Y. (2009). Causality in quantiles and dynamic stock return-volume relations. Journal of Banking and Finance, 33(7), 1351–1360. doi:10.1016/j.jbankfin.2009.02.013
Emirmahmutoglu, F. and Kose, N. (2011). Testing for Granger causality in heterogeneous mixed panels. Economic Modelling, 28(3), 870–876. doi:10.1016/j.econmod.2010.10.018
Toda, H.Y. and Yamamoto, T. (1995). Statistical inference in vector autoregressions with possibly integrated processes. Journal of Econometrics, 66(1–2), 225–250. doi:10.1016/0304-4076(94)01616-8
Wang, K.M. and Nguyen, T.B. (2022). A quantile panel-type analysis of income inequality and healthcare expenditure. Economic Research, 35(1), 873–893. doi:10.1080/1331677X.2021.1952089
Yilanci, V. and Gorus, M.S. (2020). Does economic globalization have predictive power for ecological footprint. Environmental Science and Pollution Research, 27, 40552–40562. doi:10.1007/s11356-020-10092-9
dat <- grunfeld_panel() # PFTY test (quick with few bootstrap reps) res <- xtpcaus(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", test = "pfty", pmax = 2L, dmax = 1L, nboot = 99L, kmax = 2L, seed = 42L) print(res) # PQC test res2 <- xtpcaus(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", test = "pqc", pmax = 2L, nboot = 99L, quantiles = c(0.25, 0.50, 0.75), seed = 42L) print(res2)dat <- grunfeld_panel() # PFTY test (quick with few bootstrap reps) res <- xtpcaus(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", test = "pfty", pmax = 2L, dmax = 1L, nboot = 99L, kmax = 2L, seed = 42L) print(res) # PQC test res2 <- xtpcaus(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", test = "pqc", pmax = 2L, nboot = 99L, quantiles = c(0.25, 0.50, 0.75), seed = 42L) print(res2)
Estimates a polynomial cointegrating regression in a panel using either Group-Mean FM-OLS (Wagner & Reichold 2023) or Pooled FM-OLS (de Jong & Wagner 2022). Models the long-run relationship:
xtpcmg( data, y, x, panel_id, time_id, model = c("mg", "pmg"), q = 2L, controls = NULL, trend = 1L, kernel = "ba", bw = "And91", effects = "oneway", corr_rob = FALSE )xtpcmg( data, y, x, panel_id, time_id, model = c("mg", "pmg"), q = 2L, controls = NULL, trend = 1L, kernel = "ba", bw = "And91", effects = "oneway", corr_rob = FALSE )
data |
A data frame in long format. |
y |
Character. Name of the dependent variable. |
x |
Character. Name of the polynomial (I(1)) regressor. |
panel_id |
Character. Name of the panel identifier variable. |
time_id |
Character. Name of the time variable. |
model |
Character. Estimator: |
q |
Integer. Polynomial degree: |
controls |
Character vector. Names of additional I(1) control
variables. Default is |
trend |
Integer. Deterministic trend type: |
kernel |
Character. HAC kernel: |
bw |
Character or numeric. Bandwidth for HAC estimation. |
effects |
Character. For Pooled FM-OLS: |
corr_rob |
Logical. For Group-Mean FM-OLS: if |
where and are I(1) processes.
An object of class "xtpcmg" with elements:
coefficients (named numeric vector),
vcov (variance-covariance matrix),
se (standard errors),
tstat (t-statistics),
pvalue (two-sided p-values),
model (estimator type: mg or pmg),
q (polynomial degree),
N (number of panel units),
TT (number of time periods),
y (dependent variable name),
x (polynomial variable name),
tp (turning point estimate, quadratic models only),
tp_se (delta-method SE for turning point),
tp_lo and tp_hi (95% CI bounds),
ind_coef (individual FM-OLS estimates, MG model),
swamy_s and swamy_p (Swamy slope homogeneity test).
Andrews, D.W.K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59(3), 817–858. doi:10.2307/2938229
de Jong, R.M. and Wagner, M. (2022). Panel cointegrating polynomial regressions. Annals of Applied Statistics, 16(1), 416–442. doi:10.1214/21-AOAS1536
Wagner, M. and Reichold, K. (2023). Panel cointegrating polynomial regressions. Econometric Reviews, 42(9–10), 782–827. doi:10.1080/07474938.2023.2178141
dat <- grunfeld_cmg() # Group-Mean FM-OLS (quadratic EKC-type model) res <- xtpcmg(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", model = "mg", q = 2L) print(res) summary(res) # Pooled FM-OLS res2 <- xtpcmg(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", model = "pmg", q = 2L) print(res2)dat <- grunfeld_cmg() # Group-Mean FM-OLS (quadratic EKC-type model) res <- xtpcmg(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", model = "mg", q = 2L) print(res) summary(res) # Pooled FM-OLS res2 <- xtpcmg(dat, y = "invest", x = "mvalue", panel_id = "firm", time_id = "year", model = "pmg", q = 2L) print(res2)