def _anderson_ksamp_right(samples, Z, Zstar, k, n, N):
 A2kN = 0.0
 lj = (Z.searchsorted(Zstar[:(-1)], 'right') - Z.searchsorted(Zstar[:(-1)], 'left'))
 Bj = lj.cumsum()
 for i in arange(0, k):
  s = np.sort(samples[i])
  Mij = s.searchsorted(Zstar[:(-1)], side='right')
  inner = (((lj / float(N)) * (((N * Mij) - (Bj * n[i])) ** 2)) / (Bj * (N - Bj)))
  A2kN += (inner.sum() / n[i])
 return A2kN

def _anderson_ksamp_right ( samples , Z , Zstar , k , n , N ) : A2kN = 0.0 lj = ( Z . searchsorted ( Zstar [ : ( - 1 ) ] , 'right' ) - Z . searchsorted ( Zstar [ : ( - 1 ) ] , 'left' ) ) Bj = lj . cumsum ( ) for i in arange ( 0 , k ) : s = np . sort ( samples [ i ] ) Mij = s . searchsorted ( Zstar [ : ( - 1 ) ] , side = 'right' ) inner = ( ( ( lj / float ( N ) ) * ( ( ( N * Mij ) - ( Bj * n [ i ] ) ) ** 2 ) ) / ( Bj * ( N - Bj ) ) ) A2kN += ( inner . sum ( ) / n [ i ] ) return A2kN
compute a2akn equation 6 of scholz & stephens .