#NEWLINE# def _compute_f_stat( sample_size , num_groups , tri_idxs , distances , group_sizes , s_T , grouping ) : #NEWLINE# #INDENT# 'Compute PERMANOVA pseudo-F statistic.' #NEWLINE# grouping_matrix = ( ( - 1 ) * np . ones ( ( sample_size , sample_size ) , dtype = int ) ) #NEWLINE# for group_idx in range ( num_groups ) : #NEWLINE# #INDENT# within_indices = _index_combinations ( np . where ( ( grouping == group_idx ) ) [ 0 ] ) #NEWLINE# grouping_matrix [ within_indices ] = group_idx #NEWLINE# #UNINDENT# grouping_tri = grouping_matrix [ tri_idxs ] #NEWLINE# s_W = 0 #NEWLINE# for i in range ( num_groups ) : #NEWLINE# #INDENT# s_W += ( ( distances [ ( grouping_tri == i ) ] ** 2 ) . sum ( ) / group_sizes [ i ] ) #NEWLINE# #UNINDENT# s_A = ( s_T - s_W ) #NEWLINE# return ( ( s_A / ( num_groups - 1 ) ) / ( s_W / ( s_W - num_groups ) ) )