我是R的新手。我找到了以下用于对一组变量进行单变量逻辑回归的代码。我想做的是运行卡方检验,将一系列变量与因变量进行比较,类似于下面的逻辑回归代码。我发现了几个涉及创建所有可能变量组合的方法,但我无法使其正常工作。理想情况下,我希望其中一个变量(X)保持不变。
使用for循环进行R中的卡方分析
lapply(c("age","sex","race","service","cancer",
"renal","inf","cpr","sys","heart","prevad",
"type","frac","po2","ph","pco2","bic","cre","loc"),
function(var) {
formula <- as.formula(paste("status ~", var))
res.logist <- glm(formula, data = icu, family = binomial)
summary(res.logist)
})
set.seed()
)?status
,age
等是你的变量吗?具体哪里出了问题? - gung - Reinstate Monica