def mcnemar(x, y=None, exact=True, correction=True):
 warnings.warn('Deprecated, use stats.TableSymmetry instead', DeprecationWarning)
 x = np.asarray(x)
 if ((y is None) and (x.shape[0] == x.shape[1])):
  if (x.shape[0] != 2):
   raise ValueError('table needs to be 2 by 2')
  (n1, n2) = (x[(1, 0)], x[(0, 1)])
 else:
  n1 = np.sum((x < y), 0)
  n2 = np.sum((x > y), 0)
 if exact:
  stat = np.minimum(n1, n2)
  pval = (stats.binom.cdf(stat, (n1 + n2), 0.5) * 2)
  pval = np.minimum(pval, 1)
 else:
  corr = int(correction)
  stat = (((np.abs((n1 - n2)) - corr) ** 2) / (1.0 * (n1 + n2)))
  df = 1
  pval = stats.chi2.sf(stat, df)
 return (stat, pval)

def mcnemar ( x , y = None , exact = True , correction = True ) : warnings . warn ( 'Deprecated, use stats.TableSymmetry instead' , DeprecationWarning ) x = np . asarray ( x ) if ( ( y is None ) and ( x . shape [ 0 ] == x . shape [ 1 ] ) ) : if ( x . shape [ 0 ] != 2 ) : raise ValueError ( 'table needs to be 2 by 2' ) ( n1 , n2 ) = ( x [ ( 1 , 0 ) ] , x [ ( 0 , 1 ) ] ) else : n1 = np . sum ( ( x < y ) , 0 ) n2 = np . sum ( ( x > y ) , 0 ) if exact : stat = np . minimum ( n1 , n2 ) pval = ( stats . binom . cdf ( stat , ( n1 + n2 ) , 0.5 ) * 2 ) pval = np . minimum ( pval , 1 ) else : corr = int ( correction ) stat = ( ( ( np . abs ( ( n1 - n2 ) ) - corr ) ** 2 ) / ( 1.0 * ( n1 + n2 ) ) ) df = 1 pval = stats . chi2 . sf ( stat , df ) return ( stat , pval )
mcnemar test of homogeneity .