我使用的是 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/