当前位置: 首页>>代码示例>>Python>>正文


Python stats.fisher_exact方法代码示例

本文整理汇总了Python中scipy.stats.fisher_exact方法的典型用法代码示例。如果您正苦于以下问题:Python stats.fisher_exact方法的具体用法?Python stats.fisher_exact怎么用?Python stats.fisher_exact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.fisher_exact方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_precise

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_precise(self):
        # results from R
        #
        # R defines oddsratio differently (see Notes section of fisher_exact
        # docstring), so those will not match.  We leave them in anyway, in
        # case they will be useful later on. We test only the p-value.
        tablist = [
            ([[100, 2], [1000, 5]], (2.505583993422285e-001, 1.300759363430016e-001)),
            ([[2, 7], [8, 2]], (8.586235135736206e-002, 2.301413756522114e-002)),
            ([[5, 1], [10, 10]], (4.725646047336584e+000, 1.973244147157190e-001)),
            ([[5, 15], [20, 20]], (3.394396617440852e-001, 9.580440012477637e-002)),
            ([[5, 16], [20, 25]], (3.960558326183334e-001, 1.725864953812994e-001)),
            ([[10, 5], [10, 1]], (2.116112781158483e-001, 1.973244147157190e-001)),
            ([[10, 5], [10, 0]], (0.000000000000000e+000, 6.126482213438734e-002)),
            ([[5, 0], [1, 4]], (np.inf, 4.761904761904762e-002)),
            ([[0, 5], [1, 4]], (0.000000000000000e+000, 1.000000000000000e+000)),
            ([[5, 1], [0, 4]], (np.inf, 4.761904761904758e-002)),
            ([[0, 1], [3, 2]], (0.000000000000000e+000, 1.000000000000000e+000))
            ]
        for table, res_r in tablist:
            res = stats.fisher_exact(np.asarray(table))
            np.testing.assert_almost_equal(res[1], res_r[1], decimal=11,
                                           verbose=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,代码来源:test_stats.py

示例2: fisher_exact_test

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def fisher_exact_test(pDataFile1, pDataFile2, pAlpha):

    test_result = []
    accepted = []
    rejected = []
    for i, (group1, group2) in enumerate(zip(pDataFile1, pDataFile2)):
        try:
            odds, p_value = stats.fisher_exact(np.ceil([group1, group2]))
            if p_value <= pAlpha:
                test_result.append(p_value)
                rejected.append([i, p_value])
            else:
                test_result.append(p_value)
                accepted.append([i, p_value])
        except ValueError:
            test_result.append(np.nan)
            accepted.append([i, 1.0])
    return test_result, accepted, rejected 
开发者ID:deeptools,项目名称:HiCExplorer,代码行数:20,代码来源:chicDifferentialTest.py

示例3: doTargetPrediction

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def doTargetPrediction(pickled_model_name):
	if os.name == 'nt': sep = '\\'
	else: sep = '/'
	mod = pickled_model_name.split(sep)[-1].split('.')[0]
	clf = open_Model(mod)
	probs1 = map(int, clf.predict_proba(querymatrix1)[:,1] > threshold)
	preds1 = sum(probs1)
	probs2 = map(int, clf.predict_proba(querymatrix2)[:,1] > threshold)
	preds2 = sum(probs2)
	oddsratio, pvalue = stats.fisher_exact([[preds2,len(querymatrix2)-preds2],[preds1,len(querymatrix1)-preds1]])
	try:
		ratio, preds1_percentage, preds2_percentage = calcPredictionRatio(preds1,preds2)
		return ratio, mod, preds1, preds1_percentage, preds2, preds2_percentage, oddsratio, pvalue, probs1 + probs2
	except TypeError: return None

#prediction runner 
开发者ID:lhm30,项目名称:PIDGINv2,代码行数:18,代码来源:predict_enriched_two_libraries_decision_tree.py

示例4: run

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def run(self):
        A = self.GenesWith & self.foreground
        B = self.GenesWithout & self.foreground
        C = self.GenesWith & self.background
        D = self.GenesWithout & self.background

        fishlist = ((len(A), len(B)), (len(C), len(D)))

        FT = stats.fisher_exact(fishlist)
        OR, p = FT
        padj = self.correct(p)
        if padj > 1:
            padj = 1
        significant = self.sig(padj)

        return OR, p, padj, significant, fishlist, A, C

# functions below here correspond to specific steps in the
# pipeline_enrichment pipeline - they are written as functions
# so the cluster_runnable decorater can be used. 
开发者ID:CGATOxford,项目名称:CGATPipelines,代码行数:22,代码来源:PipelineGSEnrichment.py

示例5: old_method

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def old_method(a_range, b_range, bed):

    from scipy.stats import fisher_exact

    def meth_counts(interval):
        if not interval.empty:
            all, methylated = interval.as_df()[['calls', "methylated"]].sum()
            return [all - methylated, methylated]
        else:
            return [0, 0]

    rowdicts = []

    for chr, begin, end in bed.merge().as_df().itertuples(index=False, name=None):
        [d1, n1], [d2, n2] = meth_counts(
            a_range[chr, begin:end]), meth_counts(b_range[chr, begin:end])
        rowdicts.append({"Chromosome": chr, "Start": begin, "End": end,
                         "d1": d1, "d2": d2, "n1": n1, "n2": n2})
        # print(c1, c2)
        # print(a, b, c, d)
        # odr, pv = fisher_exact([c1, c2])
        # print(odr, pv)
        # rowdicts.append({"Chromosome": chr, "Start": begin, "End": end, "OR": odr, "P": pv})

    return pd.DataFrame.from_dict(rowdicts) 
开发者ID:wdecoster,项目名称:methplotlib,代码行数:27,代码来源:test_differential.py

示例6: fisher_exact

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def fisher_exact(*_args, **_kwargs):
        raise NotImplementedError

### Indices to marginals arguments: 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:6,代码来源:association.py

示例7: fisher

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def fisher(cls, *marginals):
        """Scores bigrams using Fisher's Exact Test (Pedersen 1996).  Less
        sensitive to small counts than PMI or Chi Sq, but also more expensive
        to compute. Requires scipy.
        """

        n_ii, n_io, n_oi, n_oo = cls._contingency(*marginals)

        (odds, pvalue) = fisher_exact([[n_ii, n_io], [n_oi, n_oo]], alternative='less')
        return pvalue 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:12,代码来源:association.py

示例8: _get_fisher_scores_from_counts

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def _get_fisher_scores_from_counts(self, cat_word_counts, not_cat_word_counts):
        cat_not_word_counts = cat_word_counts.sum() - cat_word_counts
        not_cat_not_word_counts = not_cat_word_counts.sum() - not_cat_word_counts

        def do_fisher_exact(x):
            return fisher_exact([[x[0], x[1]], [x[2], x[3]]], alternative='greater')

        odds_ratio, p_values = np.apply_along_axis(
            do_fisher_exact,
            0,
            np.array([cat_word_counts, cat_not_word_counts, not_cat_word_counts, not_cat_not_word_counts]))
        return odds_ratio, p_values 
开发者ID:JasonKessler,项目名称:scattertext,代码行数:14,代码来源:TermDocMatrix.py

示例9: _test_group

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def _test_group(pvalues, group_name, group, exact=True):
    """test if the objects in the group are different from the general set.

    The test is performed on the pvalues set (ad a pandas series) over
    the group specified via a fisher exact test.
    """
    from scipy.stats import fisher_exact, chi2_contingency

    totals = 1.0 * len(pvalues)
    total_significant = 1.0 * np.sum(pvalues)
    cross_index = [c for c in group if c in pvalues.index]
    missing = [c for c in group if c not in pvalues.index]
    if missing:
        s = ('the test is not well defined if the group '
             'has elements not presents in the significativity '
             'array. group name: {}, missing elements: {}')
        logging.warning(s.format(group_name, missing))
    # how many are significant and not in the group
    group_total = 1.0 * len(cross_index)
    group_sign = 1.0 * len([c for c in cross_index if pvalues[c]])
    group_nonsign = 1.0 * (group_total - group_sign)
    # how many are significant and not outside the group
    extern_sign = 1.0 * (total_significant - group_sign)
    extern_nonsign = 1.0 * (totals - total_significant - group_nonsign)
    # make the fisher test or the chi squared
    test = fisher_exact if exact else chi2_contingency
    table = [[extern_nonsign, extern_sign], [group_nonsign, group_sign]]
    pvalue = test(np.array(table))[1]
    # is the group more represented or less?
    part = group_sign, group_nonsign, extern_sign, extern_nonsign
    #increase = (group_sign / group_total) > (total_significant / totals)
    increase = np.log((totals * group_sign)
                      / (total_significant * group_total))
    return pvalue, increase, part 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:36,代码来源:multilinear.py

示例10: test_basic

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_basic(self):
        fisher_exact = stats.fisher_exact

        res = fisher_exact([[14500, 20000], [30000, 40000]])[1]
        assert_approx_equal(res, 0.01106, significant=4)
        res = fisher_exact([[100, 2], [1000, 5]])[1]
        assert_approx_equal(res, 0.1301, significant=4)
        res = fisher_exact([[2, 7], [8, 2]])[1]
        assert_approx_equal(res, 0.0230141, significant=6)
        res = fisher_exact([[5, 1], [10, 10]])[1]
        assert_approx_equal(res, 0.1973244, significant=6)
        res = fisher_exact([[5, 15], [20, 20]])[1]
        assert_approx_equal(res, 0.0958044, significant=6)
        res = fisher_exact([[5, 16], [20, 25]])[1]
        assert_approx_equal(res, 0.1725862, significant=6)
        res = fisher_exact([[10, 5], [10, 1]])[1]
        assert_approx_equal(res, 0.1973244, significant=6)
        res = fisher_exact([[5, 0], [1, 4]])[1]
        assert_approx_equal(res, 0.04761904, significant=6)
        res = fisher_exact([[0, 1], [3, 2]])[1]
        assert_approx_equal(res, 1.0)
        res = fisher_exact([[0, 2], [6, 4]])[1]
        assert_approx_equal(res, 0.4545454545)
        res = fisher_exact([[2, 7], [8, 2]])
        assert_approx_equal(res[1], 0.0230141, significant=6)
        assert_approx_equal(res[0], 4.0 / 56) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:28,代码来源:test_stats.py

示例11: test_large_numbers

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_large_numbers(self):
        # Test with some large numbers. Regression test for #1401
        pvals = [5.56e-11, 2.666e-11, 1.363e-11]  # from R
        for pval, num in zip(pvals, [75, 76, 77]):
            res = stats.fisher_exact([[17704, 496], [1065, num]])[1]
            assert_approx_equal(res, pval, significant=4)

        res = stats.fisher_exact([[18000, 80000], [20000, 90000]])[1]
        assert_approx_equal(res, 0.2751, significant=4) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_stats.py

示例12: test_raises

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_raises(self):
        # test we raise an error for wrong shape of input.
        assert_raises(ValueError, stats.fisher_exact,
                      np.arange(6).reshape(2, 3)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_stats.py

示例13: test_row_or_col_zero

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_row_or_col_zero(self):
        tables = ([[0, 0], [5, 10]],
                  [[5, 10], [0, 0]],
                  [[0, 5], [0, 10]],
                  [[5, 0], [10, 0]])
        for table in tables:
            oddsratio, pval = stats.fisher_exact(table)
            assert_equal(pval, 1.0)
            assert_equal(oddsratio, np.nan) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_stats.py

示例14: doTargetPrediction

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def doTargetPrediction(pickled_model_name):
	if os.name == 'nt': sep = '\\'
	else: sep = '/'
	mod = pickled_model_name.split(sep)[-1].split('.')[0]
	clf = open_Model(mod)
	probs1 = map(int, clf.predict_proba(querymatrix1)[:,1] > threshold)
	preds1 = sum(probs1)
	preds2 = bg_preds[mod]
	oddsratio, pvalue = stats.fisher_exact([[preds2,2000000-preds2],[preds1,len(querymatrix1)-preds1]])
	try:
		ratio, preds1_percentage, preds2_percentage = calcPredictionRatio(preds1,preds2)
		return ratio, mod, preds1, preds1_percentage, preds2, preds2_percentage, oddsratio, pvalue, probs1
	except TypeError: return None

#prediction runner 
开发者ID:lhm30,项目名称:PIDGINv2,代码行数:17,代码来源:predict_enriched_decision_tree.py

示例15: test_gh3014

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import fisher_exact [as 别名]
def test_gh3014(self):
        # check if issue #3014 has been fixed.
        # before, this would have risen a ValueError
        odds, pvalue = stats.fisher_exact([[1, 2], [9, 84419233]]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:test_stats.py


注:本文中的scipy.stats.fisher_exact方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。