plot multiple ROC curves for logistic regression model in R

陌路散爱 提交于 2019-12-04 15:54:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!