在R中为逻辑回归模型绘制多条ROC曲线 [英] plot multiple ROC curves for logistic regression model in R

查看:767
本文介绍了在R中为逻辑回归模型绘制多条ROC曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个逻辑回归模型(使用R)作为

I have a logistic regression model (using R) as

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

我正在使用pROC软件包绘制ROC曲线,并找出6个模型fit1至fit6的AUC.

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

我已经用这种方法绘制了一个ROC.

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)

但是有一种方法我可以在一个图中组合所有6条曲线的ROC,并显示所有曲线的AUC,如果可能的话,还可以显示置信区间.

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.

推荐答案

您可以使用add = TRUE自变量plot函数绘制多条ROC曲线.

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

弥补一些虚假数据

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

获取模型拟合

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(roc1)
plot(roc2, add=TRUE, col='red')

这将在同一图上产生不同的拟合.您可以通过roc1$auc来获得ROC曲线的AUC,并可以在基本R绘图中使用text()函数将其添加,也可以仅在图例中将其抛弃.

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.

我不知道如何量化置信区间...或者,即使您使用ROC曲线也可以做到这一点.其他人将不得不填写该细节.对不起.希望其余的有所帮助.

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.

这篇关于在R中为逻辑回归模型绘制多条ROC曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆