1

我想dat$admit使用所有可用变量运行逻辑回归的因变量(在我的数据集中它是: ),每个回归都有自己的自变量与因变量。我想要返回的结果是每个回归摘要的列表:系数、p 值、AUC。使用下面提交的数据集应该有 3 个回归。

这是一个样本数据集(其中承认是逻辑回归因变量):

>dat <- read.table(text = " female  apcalc    admit       num
+ 0        0        0         7
+ 0        0        1         1
+ 0        1        0         3
+ 0        1        1         7
+ 1        0        0         5
+ 1        0        1         1
+ 1        1        0         0
+ 1        1        1         6",
+                   header = TRUE)

我有这个函数,它显示了每个回归和 coef 的列表,但我没有找到一种方法来绑定 AUC 和 p 值。这是代码:

t(sapply(setdiff(names(dat),"admit"), function(x) coef(glm(reformulate(x,response="admit"), data=dat,family=binomial)))) 

知道如何创建此列表吗?谢谢,罗恩

4

1 回答 1

2

尝试

library(caTools)
ResFunc <- function(x) {
  temp <- glm(reformulate(x,response="admit"), data=dat,family=binomial)
  c(summary(temp)$coefficients[,1], 
    summary(temp)$coefficients[,4],
    colAUC(predict(temp, type = "response"), dat$admit))
}

temp <- as.data.frame(t(sapply(setdiff(names(dat),"admit"), ResFunc)))
colnames(temp) <- c("Intercept", "Estimate", "P-Value (Intercept)", "P-Value (Estimate)", "AUC")
temp

#          Intercept      Estimate P-Value (Intercept) P-Value (Estimate) AUC
# female 0.000000e+00  0.000000e+00                   1                  1 0.5
# apcalc 0.000000e+00  0.000000e+00                   1                  1 0.5
# num    5.177403e-16 -1.171295e-16                   1                  1 0.5
于 2014-03-30T11:07:49.897 回答