plot multiple ROC curves for logistic regression m

2019-04-12 20:00发布

I have a logistic regression model (using R) as

fit6 <- glm(formula = survived ~ ascore + gini + failed, data=records, family = binomial)
summary(fit6)

I'm using pROC package to draw ROC curves and figure out AUC for 6 models fit1 through fit6.

I have approached this way to plots one ROC.

prob6=predict(fit6,type=c("response"))
records$prob6 = prob6
g6 <- roc(survived~prob6, data=records)
plot(g6)

But is there a way I can combine the ROCs for all 6 curves in one plot and display the AUCs for all of them, and if possible the Confidence Intervals too.

1条回答
不美不萌又怎样
2楼-- · 2019-04-12 20:39

You can use the add = TRUE argument the plot function to plot multiple ROC curves.

Make up some fake data

library(pROC)
a=rbinom(100, 1, 0.25)
b=runif(100)
c=rnorm(100)

Get model fits

fit1=glm(a~b+c, family='binomial')
fit2=glm(a~c, family='binomial')

Predict on the same data you trained the model with (or hold some out to test on if you want)

preds=predict(fit1)
roc1=roc(a ~ preds)

preds2=predict(fit2)
roc2=roc(a ~ preds2)

Plot it up.

plot(roc1)
plot(roc2, add=TRUE, col='red')

This produces the different fits on the same plot. You can get the AUC of the ROC curve by roc1$auc, and can add it either using the text() function in base R plotting, or perhaps just toss it in the legend.

I don't know how to quantify confidence intervals...or if that is even a thing you can do with ROC curves. Someone else will have to fill in the details on that one. Sorry. Hopefully the rest helped though.

查看更多
登录 后发表回答