簡體   English   中英

Python中的Chi Square獨立測試

[英]Chi Square Test of Independence in Python

在Ubuntu 10.04.4下,使用Python 2.6.5,NumPy和SciPy,是否可以進行卡方檢驗的獨立性? R ,這可以通過以下方式實現

> row1 = c(91,90,51)
> row2 = c(150,200,155)
> row3 = c(109,198,172)
> data.table = rbind(row1,row2,row3)
> chisq.test(data.table)

我怎么能用Python做到這一點?

from scipy.stats import chi2_contingency

row1 = [91,90,51]
row2 = [150,200,155]
row3 = [109,198,172]
data=[row1,row2,row3]
print chi2_contingency(data)

輸出:

(25.085973274234959, 4.8346447416999636e-05, 4, array([[  66.77631579,   93.10526316,   72.11842105],
       [ 145.35361842,  202.66447368,  156.98190789],
       [ 137.87006579,  192.23026316,  148.89967105]]))

R輸出:

        Pearson's Chi-squared test

data:  data.table 
X-squared = 25.086, df = 4, p-value = 4.835e-05

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM