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

calc_cramers_dist_equal_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 "approximation1" and "approximation2". See Details for more information.

Value

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

Details

This function requires the two vectors of quantiles to be of equal length. The approximation methods are formulated based on two collections of quantiles corresponding to equally-spaced probability levels. The approximation formula for "approximation1" is $$ \text{CD}(F,G) \approx \left\{\frac{1}{K(K+1)}\sum^{2K-1}_{i=1}b_i(b_i+1)(q_{i+1}-q_i)\right\} $$ and the approximation formula for "approximation2" is $$ \text{CD}(F,G) \approx \left\{\frac{1}{(K+1)^2}\sum^{2K-1}_{i=1}b_i^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 \(b_i\) is an element of a vector of the absolute values of cumulative sums of \(\mathbf{a}\), whose element is 1 if \(q_i\) is a quantile of F or -1 if \(q_i\) is a quantile of G. The "approximation1" formula reduces to the WIS if G is a point mass, while the "approximation2" formula is a direct approximation of the integral via a step function.

Examples

f_vector <- 1:9
tau_F_vector <- tau_G_vector <- seq(0.1, 0.9, 0.1)
g_vector <- seq(2, 18, 2)
calc_cramers_dist_equal_space(f_vector, tau_F_vector, g_vector, tau_G_vector, "approximation1")
#> [1] 2.111111