| Title: | Nonparametric Causality in Quantiles Test |
|---|---|
| Description: | Implements the nonparametric causality-in-quantiles test (in mean or variance), returning a test object with an S3 plot() method. The current implementation uses one lag of each series (first-order Granger causality setup). Methodology is based on Balcilar, Gupta, and Pierdzioch (2016) <doi:10.1016/j.resourpol.2016.04.004> and Balcilar et al. (2016) <doi:10.1007/s11079-016-9388-x>. |
| Authors: | Mehmet Balcilar [aut, cre] |
| Maintainer: | Mehmet Balcilar <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-16 06:09:16 UTC |
| Source: | https://github.com/mbalcilar/nonparquantilecausality |
A small example dataset used to illustrate the nonparametric causality-in-quantiles test.
gold_oilgold_oil
A data frame with two numeric columns:
numeric: gold series
numeric: oil series
Columns are generic numeric series (already aligned and cleaned)
suitable for the examples in np_quantile_causality.
Provided by Mehmet Balcilar.
Computes the Balcilar-Jeong-Nishiyama style nonparametric quantile Granger-causality test for first-order lags. Methodology is based on Balcilar, Gupta, and Pierdzioch (2016, doi:10.1016/j.resourpol.2016.04.004) and Balcilar et al. (2016, doi:10.1007/s11079-016-9388-x).
np_quantile_causality(x, y, type = c("mean", "variance"), q = NULL, hm = NULL)np_quantile_causality(x, y, type = c("mean", "variance"), q = NULL, hm = NULL)
x |
numeric vector; candidate cause (independent) variable. The test internally uses the first lag of x (one-lag Granger causality setup). |
y |
numeric vector; effect (dependent) variable. The test internally uses the first lag of y (one-lag Granger causality setup). |
type |
character; "mean" or "variance" (causality in mean or variance). |
q |
numeric vector of quantiles in (0,1). Default is seq(0.01, 0.99, 0.01). |
hm |
optional numeric bandwidth; if |
Uses local polynomial quantile regression at each quantile with kernel weights, constructs the Song et al. (2012) style quadratic form, and rescales to the asymptotic standard-normal statistic.
An object of class np_quantile_causality with elements:
statistic: numeric vector of test statistics by quantile
quantiles: numeric vector of quantiles tested
bandwidth: scalar base bandwidth used before quantile adjustment
type: "mean" or "variance"
n: effective sample size
call: the matched call
The current implementation uses one lag of each series only:
and (first-order Granger setup).
Extending to higher lags requires changing the internal embedding
(currently stats::embed(*, 2)) and the kernel construction to handle
multivariate lag vectors (e.g., a product kernel over all lag coordinates
or a multivariate Gaussian kernel).
Balcilar, M., Gupta, R., & Pierdzioch, C. (2016). Does uncertainty move the gold price? New evidence from a nonparametric causality-in-quantiles test. Resources Policy, 49, 74–80. doi:10.1016/j.resourpol.2016.04.004
Balcilar, M., Gupta, R., Kyei, C., & Wohar, M. E. (2016). Does economic policy uncertainty predict exchange rate returns and volatility? Evidence from a nonparametric causality-in-quantiles test. Open Economies Review, 27(2), 229–250. doi:10.1007/s11079-016-9388-x
This function tests whether Granger-causes
in quantile (and, with type = "variance", whether
causes ). Higher-order lags are not supported
in this release.
set.seed(1234) x <- arima.sim(n = 600, list(ar = 0.4)) y <- 0.5*lag(x, -1) + rnorm(600) # x Granger-causes y y[is.na(y)] <- mean(y, na.rm = TRUE) obj <- np_quantile_causality(x, y, type = "mean", q = seq(0.1, 0.9, 0.1)) plot(obj) # test statistic vs quantiles with 5% CV line # Example with bundled dataset (Gold causes Gold or Oil depending on call) data(gold_oil) # use first 500 days gold_oil <- gold_oil[1:501,] q_grid <- seq(0.25, 0.75, by = 0.25) # Causality in conditional mean (does Oil_t-1 cause Gold_t?) res_mean <- np_quantile_causality( x = gold_oil$Oil, y = gold_oil$Gold, type = "mean", q = q_grid ) res_mean # Causality in conditional variance res_var <- np_quantile_causality( x = gold_oil$Oil, y = gold_oil$Gold, type = "variance", q = q_grid ) res_var # Plot (with 5% critical value line); returns a ggplot object invisibly plot(res_mean) plot(res_var)set.seed(1234) x <- arima.sim(n = 600, list(ar = 0.4)) y <- 0.5*lag(x, -1) + rnorm(600) # x Granger-causes y y[is.na(y)] <- mean(y, na.rm = TRUE) obj <- np_quantile_causality(x, y, type = "mean", q = seq(0.1, 0.9, 0.1)) plot(obj) # test statistic vs quantiles with 5% CV line # Example with bundled dataset (Gold causes Gold or Oil depending on call) data(gold_oil) # use first 500 days gold_oil <- gold_oil[1:501,] q_grid <- seq(0.25, 0.75, by = 0.25) # Causality in conditional mean (does Oil_t-1 cause Gold_t?) res_mean <- np_quantile_causality( x = gold_oil$Oil, y = gold_oil$Gold, type = "mean", q = q_grid ) res_mean # Causality in conditional variance res_var <- np_quantile_causality( x = gold_oil$Oil, y = gold_oil$Gold, type = "variance", q = q_grid ) res_var # Plot (with 5% critical value line); returns a ggplot object invisibly plot(res_mean) plot(res_var)
Plot method for np_quantile_causality objects
## S3 method for class 'np_quantile_causality' plot(x, cv = 1.96, title = NULL, ...)## S3 method for class 'np_quantile_causality' plot(x, cv = 1.96, title = NULL, ...)
x |
an object of class |
cv |
numeric; a reference critical value line (default 1.96 for ~5%) |
title |
optional plot title; default is constructed from |
... |
unused (for S3 compatibility) |
A ggplot object (invisibly).
Balcilar, M., Gupta, R., & Pierdzioch, C. (2016). Does uncertainty move the gold price? New evidence from a nonparametric causality-in-quantiles test. Resources Policy, 49, 74–80.
Balcilar, M., Gupta, R., Kyei, C., & Wohar, M. E. (2016). Does economic policy uncertainty predict exchange rate returns and volatility? Evidence from a nonparametric causality-in-quantiles test. Open Economies Review, 27(2), 229–250.
Tools for nonparametric causality-in-quantiles in mean and variance.
Balcilar, M., Gupta, R., & Pierdzioch, C. (2016). Does uncertainty move the gold price? New evidence from a nonparametric causality-in-quantiles test. Resources Policy, 49, 74–80.
Balcilar, M., Gupta, R., Kyei, C., & Wohar, M. E. (2016). Does economic policy uncertainty predict exchange rate returns and volatility? Evidence from a nonparametric causality-in-quantiles test. Open Economies Review, 27(2), 229–250.