python - Scipy fisher_exact 测试需要很长时间

标签 python scipy

我使用的是 scipy 版本 1.0.0。

import scipy as sp
x = [[5829225, 5692693], [5760959, 5760959]]
sp.stats.fisher_exact(x)

对于上面的值,scipy 不返回任何东西,而是等待。 这可能是什么原因? 我该如何解决?

但是在 R 中它几乎立即返回一个 p 值。

a = matrix(c(5829225,5692693,5760959,5760959), nrow=2)
fisher.test(a)

最佳答案

来自 documentation 中的注释:

The calculated odds ratio is different from the one R uses. This scipy implementation returns the (more common) “unconditional Maximum Likelihood Estimate”, while R uses the “conditional Maximum Likelihood Estimate”.

For tables with large numbers, the (inexact) chi-square test implemented in the function chi2_contingency can also be used.

(强调我的)

就像提到的 DSM 的评论一样,对于您的大值来说,它可能非常慢。由于注释标注了较大的值,您可以尝试他们建议的替代方案:

>>> chi2, p, dof, expected = sp.stats.chi2_contingency(x)
>>> p
6.140729432506709e-178

关于python - Scipy fisher_exact 测试需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52210788/

相关文章:

python - 如何使用 python/pandas 消除列中具有连续值的行

python - 使用python的递归grep

javascript - 是否可以使用 HTML+CSS+JavaScript 设计 GUI 但它实际上会运行 python 脚本?

Python/Numpy 查找长度变量跨度

python-3.x - 如何在Python的scipy信号卷积中添加比率参数?

python - 将字符串列表转换为以空格分隔的字符串

Python正则表达式从字符串中的 anchor 提取上一个/下一个组

python - Numpy 和 Scipy 在 Windows 上的安装

python - 从层次聚类的不同级别获取标签

python - 在总和有限的情况下以最快的速度优化面积差