def symmetry_bowker(table):
 warnings.warn('Deprecated, use stats.TableSymmetry instead', DeprecationWarning)
 table = np.asarray(table)
 (k, k2) = table.shape
 if (k != k2):
  raise ValueError('table needs to be square')
 upp_idx = np.triu_indices(k, 1)
 tril = table.T[upp_idx]
 triu = table[upp_idx]
 stat = (((tril - triu) ** 2) / ((tril + triu) + 1e-20)).sum()
 df = ((k * (k - 1)) / 2.0)
 pval = stats.chi2.sf(stat, df)
 return (stat, pval, df)

def symmetry_bowker ( table ) : warnings . warn ( 'Deprecated, use stats.TableSymmetry instead' , DeprecationWarning ) table = np . asarray ( table ) ( k , k2 ) = table . shape if ( k != k2 ) : raise ValueError ( 'table needs to be square' ) upp_idx = np . triu_indices ( k , 1 ) tril = table . T [ upp_idx ] triu = table [ upp_idx ] stat = ( ( ( tril - triu ) ** 2 ) / ( ( tril + triu ) + 1e-20 ) ) . sum ( ) df = ( ( k * ( k - 1 ) ) / 2.0 ) pval = stats . chi2 . sf ( stat , df ) return ( stat , pval , df )
test for symmetry of a square contingency table this is an extension of the mcnemar test to test the null hypothesis that the contingency table is symmetric around the main diagonal .