def cochrans_q(x):
 warnings.warn('Deprecated, use stats.cochrans_q instead', DeprecationWarning)
 x = np.asarray(x)
 gruni = np.unique(x)
 (N, k) = x.shape
 count_row_success = (x == gruni[(-1)]).sum(1, float)
 count_col_success = (x == gruni[(-1)]).sum(0, float)
 count_row_ss = count_row_success.sum()
 count_col_ss = count_col_success.sum()
 assert (count_row_ss == count_col_ss)
 q_stat = (((k - 1) * ((k * np.sum((count_col_success ** 2))) - (count_col_ss ** 2))) / ((k * count_row_ss) - np.sum((count_row_success ** 2))))
 return (q_stat, stats.chi2.sf(q_stat, (k - 1)))

def cochrans_q ( x ) : warnings . warn ( 'Deprecated, use stats.cochrans_q instead' , DeprecationWarning ) x = np . asarray ( x ) gruni = np . unique ( x ) ( N , k ) = x . shape count_row_success = ( x == gruni [ ( - 1 ) ] ) . sum ( 1 , float ) count_col_success = ( x == gruni [ ( - 1 ) ] ) . sum ( 0 , float ) count_row_ss = count_row_success . sum ( ) count_col_ss = count_col_success . sum ( ) assert ( count_row_ss == count_col_ss ) q_stat = ( ( ( k - 1 ) * ( ( k * np . sum ( ( count_col_success ** 2 ) ) ) - ( count_col_ss ** 2 ) ) ) / ( ( k * count_row_ss ) - np . sum ( ( count_row_success ** 2 ) ) ) ) return ( q_stat , stats . chi2 . sf ( q_stat , ( k - 1 ) ) )
cochrans q test for identical effect of k treatments cochrans q is a k-sample extension of the mcnemar test .