【发布时间】:2021-10-23 12:05:50
【问题描述】:
library(dslabs)
data("research_funding_rates")
research_funding_rates
“使用所有学科的总数,按获奖状态(获奖/未获奖)构建一个 2×2 的性别(男性/女性)表。”
我试过了
r_s <- research_funding_rates %>% mutate(not_awarded_men = applications_men - awards_men, not_awarded_women = applications_women - awards_women)
r_s_t <- r_s %>% summarise(not_awarded_women = sum(not_awarded_women), awarded_women = sum(awards_women), not_awarded_men = sum(not_awarded_men), awarded_men = sum(awards_men))
colnames(r_s_t) <- NULL
t <- as.table(matrix(r_s_t, ncol = 2, byrow=TRUE))
chisq.test(t)
但这给出了错误 sum(x) 出错,类型列表无效
str(t) 返回 4人名单 $ : 数字 1011 $ : 数字 1345 $ : 数字 177 $ : 数字 29 而不是表格
而这个简单的例子
sex_pet <- matrix(c(19, 34, 22, 26, 28, 6),nrow=2, byrow = TRUE, dimnames =list(sex=c("Male", "Female"), pet=c("Cats", "Dogs", "Other")))
sex_pet_table <- as.table(sex_pet)
chisq.test(sex_pet_table)
按预期工作。如何从上面的数据中获取 2x2 表来执行 chisq.test??
谢谢,
汉斯
【问题讨论】:
标签: r chi-squared