Python 与 R 中的二项式检验
Binomial test in Python vs R
我正在尝试用 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
因为int除法。
为什么值不同?我必须指定 Scipy / binom.sf
的时刻吗?
我应该使用其他库吗?
这是我在 R 中得到的:
> binom.test(2, 8, 11/2364, alternative = "greater")
Exact binomial test
data: 2 and 8
number of successes = 2, number of trials = 8, p-value = 0.0005951
alternative hypothesis: true probability of success is greater than 0.00465313
95 percent confidence interval:
0.04638926 1.00000000
sample estimates:
probability of success
0.25
>
请注意,p 值为 0.0005951。
将其与 scipy.stats.binom_test
的结果进行比较(returns 只是 p 值):
In [25]: from scipy.stats import binom_test
In [26]: binom_test(2, 8, 11/2364, alternative='greater')
Out[26]: 0.00059505960517880572
所以这与 R 一致。
要使用 scipy.stats.binom
的生存函数,您必须调整第一个参数(如 Marius 的评论所述):
In [27]: from scipy.stats import binom
In [28]: binom.sf(1, 8, 11/2364)
Out[28]: 0.00059505960517880572
(我用的是 Python 3,所以 11/2364
等于 0.004653130287648054
。如果你用的是 Python 2,一定要把那个分数写成 11.0/2364
或 float(11)/2364
.)
我正在尝试用 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
因为int除法。
为什么值不同?我必须指定 Scipy / binom.sf
的时刻吗?
我应该使用其他库吗?
这是我在 R 中得到的:
> binom.test(2, 8, 11/2364, alternative = "greater")
Exact binomial test
data: 2 and 8
number of successes = 2, number of trials = 8, p-value = 0.0005951
alternative hypothesis: true probability of success is greater than 0.00465313
95 percent confidence interval:
0.04638926 1.00000000
sample estimates:
probability of success
0.25
>
请注意,p 值为 0.0005951。
将其与 scipy.stats.binom_test
的结果进行比较(returns 只是 p 值):
In [25]: from scipy.stats import binom_test
In [26]: binom_test(2, 8, 11/2364, alternative='greater')
Out[26]: 0.00059505960517880572
所以这与 R 一致。
要使用 scipy.stats.binom
的生存函数,您必须调整第一个参数(如 Marius 的评论所述):
In [27]: from scipy.stats import binom
In [28]: binom.sf(1, 8, 11/2364)
Out[28]: 0.00059505960517880572
(我用的是 Python 3,所以 11/2364
等于 0.004653130287648054
。如果你用的是 Python 2,一定要把那个分数写成 11.0/2364
或 float(11)/2364
.)