Approximate the Cramer’s distance between a pair of distributions F and G that are represented by a collection of unequally-spaced quantiles.

calc_cramers_dist_unequal_space(q_F, tau_F, q_G, tau_G, approx_rule)

Arguments

q_F

vector containing the quantiles of F

tau_F

vector containing the probability levels corresponding to the quantiles of F.

q_G

vector containing the quantiles of G

tau_G

vector containing the probability levels corresponding to the quantiles of G.

approx_rule

string specifying which formula to use for approximation. Valid rules are "left_sided_riemann" and "trapezoid_riemann". See Details for more information.

Value

a single value of approximated pairwise Cramér distance between q_F and q_G

Details

This function accommodates cases when the lengths of q_F and q_G are not equal and when tau_F and tau_G are not equal. A Riemann sum is used to approximate a pairwise Cramér distance. The approximation formula for "left_sided_riemann" is $$ \text{CD}(F,G) \approx \left\{\sum^{2K-1}_{j=1}(\tau^F_j-\tau^G_j)^2(q_{i+1}-q_i)\right\} $$ and the approximation formula for "trapezoid_riemann" is $$ \text{CD}(F,G) \approx \left\{\frac{1}{(K+1)^2}\sum^{2K-1}_{i=1}\frac{(\tau^F_j-\tau^G_j)^2+(\tau^F_{j+1}-\tau^G_{j+1})^2}{2}(q_{i+1}-q_i)\right\} $$ where \(q_i\) is an element in a vector of an ordered pooled quantiles of q_F and q_G and \(\tau^F_j\) and \(\tau^G_j\) are defined as the probability level of a quantile in q_F when \(q_i\) comes from \(F\) and the probability level of a quantile in q_G when \(q_i\) comes from \(G\), respectively.

Examples

f_vector <- 1:9
tau_F_vector <- tau_G_vector <- seq(0.1, 0.9, 0.1)
g_vector <- seq(4, 20, 2)
calc_cramers_dist_unequal_space(f_vector, tau_F_vector, g_vector, tau_G_vector, "left_sided_riemann")
#> [1] 2.51