1

I'm trying to recreate the following integral with empirical data:

$$ \int_0^1 |F(G^{-1}(p))-p| + |G(F^{-1}(p))-p| dp $$

where $F$, $G$ are cdfs and $F^{-1}$, $G^{-1}$ are quantile functions.

Here's my code in python:

def eqces(u,v):
    import numpy as np
    import statsmodels.api as sm
    from scipy.stats.mstats import mquantiles

    ecdfu = sm.distributions.ECDF(u)
    ecdfv = sm.distributions.ECDF(v)
    p = np.concatenate([ecdfu.y, ecdfv.y])
    p = np.unique(p) 
    p.sort()

    qfu = mquantiles(u, p)
    qfv = mquantiles(v, p)

    uvinv = ecdfu(qfv)
    vuinv = ecdfv(qfu)

    result = abs(uvinv - p) + abs(vuinv - p)
    return np.dot(result, np.ones(p.size))

The input for this code are two random distributions, which need not be normal or parametric. With this I would expect that eqces(u,u) = 0 for u = np.random.uniform(0,1,50) but this is generally not the case. Can anyone tell if i'm doing something wrong or suggest alternatives?

0 Answers0