【发布时间】:2021-08-13 21:12:46
【问题描述】:
我有这些数据:
df <- structure(list(`Orientación dicotómica` = c("Neurogastro", "Neurogastro",
"Neurogastro", "Neurogastro", "No neurogastro", "No neurogastro",
"No neurogastro", "No neurogastro", "No neurogastro"), `Fisiopatología más frecuente variante constipación` = c("Más de una variante",
"Obstrucción del tracto de salida", "Tránsito lento / Inercia",
"Transito normal", "Más de una variante", "Obstrucción del tracto de salida",
"Tránsito lento / Inercia", "Transito normal", "Uso de fármacos"
), n = c(22L, 8L, 12L, 11L, 108L, 12L, 101L, 25L, 1L), Proporcion = c(41.5,
15.1, 22.6, 20.8, 43, 4.8, 40.2, 10, 0.4), ds = c(11.5, 11.5,
11.5, 11.5, 19.6, 19.6, 19.6, 19.6, 19.6), IC25 = c(32, 5.6,
13.1, 11.3, 29.8, -8.4, 27, -3.2, -12.8), IC75 = c(51, 24.6,
32.1, 30.3, 56.2, 18, 53.4, 23.2, 13.6)), row.names = c(NA, -9L
), class = c("tbl_df", "tbl", "data.frame"), na.action = structure(c(`10` = 10L), class = "omit"))
看起来像这样:
我正在尝试使用分组数据进行 chisq 测试,以分析在“fisiopatología más frecuente”方面“neurogastro”和“no neurogastro”之间是否存在统计学上的显着差异。
如发布于Chi -Square test with grouped data in dplyr
我试过了
test <- df %>%
group_by(`Fisiopatología más frecuente variante constipación`) %>%
summarise(pval = chisq.test(Proporcion,`Orientación dicotómica`)$p.value)
但我得到一个错误,我猜是因为没有用于神经胃的“Uso de fármacos”。我的方法可以吗?除了缺少的那一组之外,我如何对其余组进行测试?
谢谢!
【问题讨论】:
-
你可以使用
tryCatch来处理错误pval = tryCatch(chisq.test(...), error = function(e) NA) -
感谢@rawr,但我一直收到相同的“错误:
summarise()输入有问题pval。x 'x' 和 'y' 必须至少有 2 个级别我输入pval是tryCatch(chisq.test(Proporcion,Orientación dicotómica)$p.value). i 第 5 组发生错误:Fisiopatología más frecuente variante constipación = "Uso de fármacos"。" -
你没有添加
error = ...部分 -
我做到了。代码是
test <- fisiopato_constipacion_especialidad %>% group_by(Fisiopatología más frecuente variante constipación) %>% summarise(pval = tryCatch(chisq.test(Proporcion,Orientación dicotómica)$p.value), error = function(e) NA)。输出在上面... -
你的括号不在正确的位置
summarise(pval = tryCatch(chisq.test(...)$p.value, error = function(e) NA))
标签: r chi-squared groupingby