2013-12-10 4 views
5

scipy.stats.chisquareを使用しようとしています。私は間違って何をやっているPython scipy chisquareがR chisquareと異なる値を返す

> 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 

Rリターンの

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) 

同じ例:私はおもちゃの例を構築していますか?

おかげで、このchisq.testコールのpythonと同等の場合

答えて

9

chi2_contingencyです:

この関数は、観測観測周波数in the contingency tableの独立性の仮説検定のためのカイ2乗統計量と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) 
関連する問題