def nri(distmat, marginals, group, iters):
 group_marginals = [marginals.index(i) for i in group]
 mn_x_obs = mpd(reduce_mtx(distmat, group_marginals))
 (mn_x_n, sd_x_n) = random_mpd(distmat, len(group_marginals), iters)
 if (abs(sd_x_n) < 1e-05):
  raise ValueError(((('The standard deviation of the means of the random' + ' draws from the distance matrix was less than .00001. This is') + ' likely do to a phylogeny with distances to all tips equal.') + ' This phylogeny is not suitable for NRI/NTI analysis.'))
 return ((-1.0) * ((mn_x_obs - mn_x_n) / sd_x_n))

def nri ( distmat , marginals , group , iters ) : group_marginals = [ marginals . index ( i ) for i in group ] mn_x_obs = mpd ( reduce_mtx ( distmat , group_marginals ) ) ( mn_x_n , sd_x_n ) = random_mpd ( distmat , len ( group_marginals ) , iters ) if ( abs ( sd_x_n ) < 1e-05 ) : raise ValueError ( ( ( ( 'The standard deviation of the means of the random' + ' draws from the distance matrix was less than .00001. This is' ) + ' likely do to a phylogeny with distances to all tips equal.' ) + ' This phylogeny is not suitable for NRI/NTI analysis.' ) ) return ( ( - 1.0 ) * ( ( mn_x_obs - mn_x_n ) / sd_x_n ) )
calculate the nri of the selected group .