我正在尝试用Python重新实现最初在R中开发的二项式检验,但我不确定是否使用了正确的功能。
在R中,我得到:
> binom.test (2, 8, 11/2364, alternative = "greater")
0.25
使用 Python
和 SciPy
,我可以完成以下操作:
from scipy.stats import binom
binom.sf(2, 8, float(11)/float(2364))
5.5441613055814931e-06
实际上,我必须执行 binom.sf(2, 8, float(11)/float(2364))
,以确保由于整数除法而导致的第三个参数不为0
。
为什么这些值不同?我是否需要为Scipy / binom.sf
指定时刻?
我应该使用其他库吗?
Scipy
有scipy.stats.binom_test
函数,因此不需要使用生存函数。如果要使用binom.sf
得到相同的结果,则需要使用binom.sf(1, 8, float(11)/float(2364))
,因为您希望包括2的概率。 - Marius