【发布时间】:2020-02-23 22:03:13
【问题描述】:
我在 R 中对 chisq.test() 进行了以下模拟测试
> dd <- data.frame(a=sample(1,size=100,replace=T),
+ group=sample(1:2,size=100,replace=T,prob = c(0.3,0.7)))
> dl <- data.frame(a=sample(1:2,size=100,replace=T),
+ group=sample(1:2,size =100,replace=T,prob = c(0.3,0.7)))
> table(dd)
group
a 1 2
1 32 68
> chisq.test(table(dd))
Chi-squared test for given probabilities
data: table(dd)
X-squared = 12.96, df = 1, p-value = 0.0003182
> table(dl)
group
a 1 2
1 21 33
2 9 37
> chisq.test(table(dl))
Pearson's Chi-squared test with Yates' continuity correction
data: table(dl)
X-squared = 3.5446, df = 1, p-value = 0.05974
我打算比较 group=1 和 group=2 之间的差异;计算在 dl 中正确完成。但是,在 dd 中,因为两组中的所有个体都包含 100% 的事件(所有个体都具有相同的类);两组之间应该没有差异(p=1),但是 chisq.test() 给出的 p 值为 0.0003,这应该是比较比例的差异(32% vs. 68%)。但我真正想比较的是组内的比例(100% vs. 100%)。在这种情况下,我怎样才能正确使用 chisq.test?
【问题讨论】:
标签: r chi-squared