Python scipy chisquare返回的值与R chisquare不同 [英] Python scipy chisquare returns different values than R chisquare
本文介绍了Python scipy chisquare返回的值与R chisquare不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用scipy.stats.chisquare
.我建立了一个玩具示例:
I am trying to use scipy.stats.chisquare
. I have built a toy example:
In [1]: import scipy.stats as sps
In [2]: import numpy as np
In [3]: sps.chisquare(np.array([38,27,23,17,11,4]), np.array([98, 100, 80, 85,60,23]))
Out[11]: (240.74951271813072, 5.302429887719704e-50)
R
中的相同示例返回:
> chisq.test(matrix(c(38,27,23,17,11,4,98,100,80,85,60,23), ncol=2))
Pearson's Chi-squared test
data: matrix(c(38, 27, 23, 17, 11, 4, 98, 100, 80, 85, 60, 23), ncol = 2)
X-squared = 7.0762, df = 5, p-value = 0.215
我在做什么错了?
谢谢
推荐答案
For this chisq.test
call python equivalent is chi2_contingency
:
此函数计算卡方统计量和p值,用于假设检验中独立于所观察频率 列联表 .
>>> arr = np.array([38,27,23,17,11,4,98,100,80,85,60,23]).reshape(2,-1)
>>> arr
array([[ 38, 27, 23, 17, 11, 4],
[ 98, 100, 80, 85, 60, 23]])
>>> chi2, p, dof, expected = scipy.stats.chi2_contingency(arr)
>>> chi2, p, dof
(7.0762165124844367, 0.21503342516989818, 5)
这篇关于Python scipy chisquare返回的值与R chisquare不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文