我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用scipy.stats.binom_test()。
def burden_test(count, pred, offset, test_method, model, s): """ Perform burden test. Args: count: pred: offset: test_method: model: s: use_gmean: Returns: """ if test_method == 'auto': test_method = 'binomial' if model['pval_dispersion'] > 0.05 else 'negative_binomial' if test_method == 'negative_binomial': logger.info('Using negative binomial test with s={}, theta={}'.format(s, model['theta'])) theta = s * model['theta'] pvals = np.array([negbinom_test(x, mu, theta, o) for x, mu, o in zip(count, pred, offset)]) elif test_method == 'binomial': logger.info('Using binomial test') pvals = np.array([binom_test(x, n, p, 'greater') for x, n, p in zip(count, offset, pred/offset)]) else: logger.error('Unknown test method: {}. Please use binomial, negative_binomial or auto'.format(test_method)) sys.exit(1) return pvals
def pre(self, df): if self.variable not in df: df.loc[:, self.variable] = df.apply(lambda row: binom_test(np.round(row['s1_area_fraction_top'] * row['s1']), np.round(row['s1']), self.aft_map(np.sqrt(row['x']**2 + row['y']**2), row['z'])[0, 0]), axis=1) return df
def binomial_test(mut_on_kmer, mut_on_gene, e): ''' performs binomial tests for mutations on each kmer, returns pvalue ''' pval = binom_test(mut_on_kmer, mut_on_gene, e) return(pval)