用 R语言 & Python 运算 卡方检验
R语言Python
mytable
R语言
install.packages
('vcd')
library
(vcd
)
mytable
<- matrix
(c
(23,45,15,96),2,2,byrow
=T
)
chisq.test
(mytable
,correct
=F
)
Pearson's Chi
-squared test
data
: mytable
X
-squared
= 10.402, df
= 1, p
-value
= 0.001259
Python
from scipy
.stats
import chi2_contingency
import numpy
as np
kf_data
= np
.array
([[23,45], [15,96]])
kf
= chi2_contingency
(kf_data
,correction
=False)
print('chisq-statistic=%.4f, p-value=%.4f, df=%i expected_frep=%s'%kf
)
chisq
-statistic
=10.4017, p
-value
=0.0013, df
=1 expected_frep
=[[14.43575419 53.56424581]
[23.56424581 87.43575419]]
转载请注明原文地址: https://lol.8miu.com/read-9002.html