def binom_test(count, nobs, prop=0.5, alternative='two-sided'):
 if (np.any((prop > 1.0)) or np.any((prop < 0.0))):
  raise ValueError('p must be in range [0,1]')
 if (alternative in ['2s', 'two-sided']):
  pval = stats.binom_test(count, n=nobs, p=prop)
 elif (alternative in ['l', 'larger']):
  pval = stats.binom.sf((count - 1), nobs, prop)
 elif (alternative in ['s', 'smaller']):
  pval = stats.binom.cdf(count, nobs, prop)
 else:
  raise ValueError('alternative not recognized\nshould be two-sided, larger or smaller')
 return pval

def binom_test ( count , nobs , prop = 0.5 , alternative = 'two-sided' ) : if ( np . any ( ( prop > 1.0 ) ) or np . any ( ( prop < 0.0 ) ) ) : raise ValueError ( 'p must be in range [0,1]' ) if ( alternative in [ '2s' , 'two-sided' ] ) : pval = stats . binom_test ( count , n = nobs , p = prop ) elif ( alternative in [ 'l' , 'larger' ] ) : pval = stats . binom . sf ( ( count - 1 ) , nobs , prop ) elif ( alternative in [ 's' , 'smaller' ] ) : pval = stats . binom . cdf ( count , nobs , prop ) else : raise ValueError ( 'alternative not recognized\nshould be two-sided, larger or smaller' ) return pval
perform a test that the probability of success is p .