【发布时间】:2018-09-15 07:28:58
【问题描述】:
我使用以下代码对所有可能的列组合进行卡方分析。
Dat <- esoph[ , 1:3]
library(plyr)
combos <- combn(ncol(Dat),2)
adply(combos, 2, function(x) {
test <- chisq.test(Dat[, x[1]], Dat[, x[2]])
out <- data.frame("Row" = colnames(Dat)[x[1]]
, "Column" = colnames(Dat[x[2]])
, "Chi.Square" = round(test$statistic,3)
, "df"= test$parameter
, "p.value" = round(test$p.value, 3)
)
return(out)
})
X1 Row Column Chi.Square df p.value
1 1 agegp alcgp 1.419 15 1
2 2 agegp tobgp 2.400 15 1
3 3 alcgp tobgp 0.619 9 1
我想知道如何使用tidyverse 执行相同的操作。任何提示。
【问题讨论】:
-
您的基本解决方案不符合
标准的任何特殊原因?
标签: r dplyr plyr tidyverse chi-squared