【发布时间】:2023-05-15 00:29:02
【问题描述】:
我的数据集包含以下列:
Voted? Political Category
1 Right
0 Left
1 Center
1 Right
1 Right
1 Right
我需要查看哪个类别与投票的人最相关。为此,我需要计算卡方。 我想要按投票分组?和政治类别才能有这样的东西:
(1, Right) : 1500 people
(0, Right) : 202 people
(1, Left): 826 people
(0, Left): 652 people
(1, Center): 431 people
(0, Center): 542 people
在 R 中,我会这样做:
yes = c(1500, 826, 431)
no = c(212, 652, 542)
TBL = rbind(yes, no); TBL
[,1] [,2] [,3]
yes 1500 826 431
no 212 652 542
并申请
chisq.test(TBL, cor=F)
与:
X-squared = 630.08, df = 2, p-value < 2.2e-16
如果我使用 prop.test 会更好,因为它会给出每个政治类别中投票的人的比例。
prop 1 prop 2 prop 3
0.8761682 0.5588633 0.4429599
我想在 Python 中获得相同或相似的结果。
【问题讨论】:
标签: python scipy chi-squared scipy.stats