hyppo/independence/hhg.py
def _pearson_stat(distx, disty):  # pragma: no cover
    """Calculate the Pearson chi square stats"""

    n = distx.shape[0]
    S = np.zeros((n, n))

    # iterate over all samples in the distance matrix
    for i in range(n):
        for j in range(n):
            if i != j:
                a = distx[i, :] <= distx[i, j]
                b = disty[i, :] <= disty[i, j]

                t11 = np.sum(a * b) - 2
                t12 = np.sum(a * (1 - b))
                t21 = np.sum((1 - a) * b)
                t22 = np.sum((1 - a) * (1 - b))

                denom = (t11 + t12) * (t21 + t22) * (t11 + t21) * (t12 + t22)
                if denom > 0:
                    S[i, j] = ((n - 2) * (t12 * t21 - t11 * t22) ** 2) / denom

    return S
Calculate the Pearson chi square stats
Calculate the Pearson chi square stats
Calculate the Pearson chi square stats
def _pearson_stat(distx, disty):  
    n = distx.shape[0]
    S = np.zeros((n, n))
    for i in range(n):
        for j in range(n):
            if i != j:
                a = distx[i, :] <= distx[i, j]
                b = disty[i, :] <= disty[i, j]
                t11 = np.sum(a * b) - 2
                t12 = np.sum(a * (1 - b))
                t21 = np.sum((1 - a) * b)
                t22 = np.sum((1 - a) * (1 - b))
                denom = (t11 + t12) * (t21 + t22) * (t11 + t21) * (t12 + t22)
                if denom > 0:
                    S[i, j] = ((n - 2) * (t12 * t21 - t11 * t22) ** 2) / denom
    return S
def _pearson_stat ( distx , disty ) : n = distx . shape [ 0 ] S = np . zeros ( ( n , n ) ) for i in range ( n ) : for j in range ( n ) : if i != j : a = distx [ i , : ] <= distx [ i , j ] b = disty [ i , : ] <= disty [ i , j ] t11 = np . sum ( a * b ) - 2 t12 = np . sum ( a * ( 1 - b ) ) t21 = np . sum ( ( 1 - a ) * b ) t22 = np . sum ( ( 1 - a ) * ( 1 - b ) ) denom = ( t11 + t12 ) * ( t21 + t22 ) * ( t11 + t21 ) * ( t12 + t22 ) if denom > 0 : S [ i , j ] = ( ( n - 2 ) * ( t12 * t21 - t11 * t22 ) ** 2 ) / denom return S
Calculate the Pearson chi square stats
Calculate the Pearson chi square stats
# pragma: no cover """Calculate the Pearson chi square stats""" # iterate over all samples in the distance matrix
distx
disty