# Getting started with nonParQuantileCausality

We follow the testing framework introduced in Balcilar, Gupta, and Pierdzioch (2016) and Balcilar et al. (2016).

    library(nonParQuantileCausality)
    data(gold_oil)
    # use first 500 rows
    gold_oil <- gold_oil[1:501,]
    q_grid <- seq(0.05, 0.95, by = 0.05)

    # 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

    ## $statistic
    ##  [1]  0.5714180  1.2387415  1.2852325  5.0139738 28.5733057 33.2290576
    ##  [7] 24.1403710 33.5687605 32.7787184 29.0534395 21.7815491 17.5309699
    ## [13] 12.6467496  8.5343776  4.8681249  2.3873202  0.8908481  0.6262628
    ## [19]  0.5768538
    ##
    ## $quantiles
    ##  [1] 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75
    ## [16] 0.80 0.85 0.90 0.95
    ##
    ## $bandwidth
    ## [1] 5.277595
    ##
    ## $type
    ## [1] "mean"
    ##
    ## $n
    ## [1] 500
    ##
    ## $call
    ## np_quantile_causality(x = gold_oil$Oil, y = gold_oil$Gold, type = "mean",
    ##     q = q_grid)
    ##
    ## attr(,"class")
    ## [1] "np_quantile_causality"

    # Causality in conditional variance
    res_var <- np_quantile_causality(
      x = gold_oil$Oil,
      y = gold_oil$Gold,
      type = "variance",
      q = q_grid
    )
    res_var

    ## $statistic
    ##  [1]  0.5736890  1.2650061  1.2852325  1.7193656  9.9986456 12.8120752
    ##  [7] 28.0885519 30.5262840 32.5687650 24.9263036 23.3006958 15.8487117
    ## [13] 12.3373828  8.2520515  4.9858627  2.2036083  0.8908481  0.6262628
    ## [19]  0.5350642
    ##
    ## $quantiles
    ##  [1] 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75
    ## [16] 0.80 0.85 0.90 0.95
    ##
    ## $bandwidth
    ## [1] 5.277595
    ##
    ## $type
    ## [1] "variance"
    ##
    ## $n
    ## [1] 500
    ##
    ## $call
    ## np_quantile_causality(x = gold_oil$Oil, y = gold_oil$Gold, type = "variance",
    ##     q = q_grid)
    ##
    ## attr(,"class")
    ## [1] "np_quantile_causality"

    # Plot (with 5% critical value line); returns a ggplot object invisibly
    plot(res_mean)

    plot(res_var)

Balcilar, Mehmet, Rangan Gupta, Clement Kyei, and Mark E. Wohar. 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–50.
Balcilar, Mehmet, Rangan Gupta, and Christian Pierdzioch. 2016. “Does Uncertainty Move the Gold Price? New Evidence from a Nonparametric Causality-in-Quantiles Test.” Resources Policy 49: 74–80.