我有此数据集,在这里我想比较变量,以查看是否有任何类别的类别对各个分类变量有意义。当我使用以下代码时,R返回一条警告消息,指出p值可能是错误的。我对卡方的格式不正确吗?
df<-(group, gender, race, handedness
1, 0, 3, 0
1, 1, 3, 1
2, 1, 3, 0
2, 1, 3, 0
3, 0, 2, 1
3, 0, 2, 0)
# Is Gender significant among groups
gendertab<-table(df$gender, df$group)
chisq.test(gendertab)
# Is Race significant
racetab<-table(df$race, df$group)
chisq.test(racetab)
# Is Handedness significant
handtab<-table(df$handedness, df$group)
chisq.test(handtab)
答案 0 :(得分:0)
尝试使用参数simulate.p.value = TRUE
,并将结果与fisher.test
(R manual page或Wikipedia)进行比较。他们似乎彼此同意。
# Is Gender significant among groups
gendertab<-table(df$gender, df$group)
fisher.test(gendertab)
chisq.test(gendertab, simulate.p.value = TRUE)
# Is Race significant
racetab<-table(df$race, df$group)
fisher.test(racetab)
chisq.test(racetab, simulate.p.value = TRUE)
# Is Handedness significant
handtab<-table(df$handedness, df$group)
fisher.test(handtab)
chisq.test(handtab, simulate.p.value = TRUE)
数据。
df <- read.csv(text = "
group, gender, race, handedness
1, 0, 3, 0
1, 1, 3, 1
2, 1, 3, 0
2, 1, 3, 0
3, 0, 2, 1
3, 0, 2, 0")