[英]plot multiple ROC curves for logistic regression model in R
I have a logistic regression model (using R) as 我有一个逻辑回归模型(使用R)作为
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. 我正在使用
pROC
软件包来绘制ROC曲线并计算6个模型fit1到fit6的AUC。
I have approached this way to plots one ROC. 我采用这种方法来绘制一个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. 但有没有办法可以在一个图中为所有6条曲线组合ROC并显示所有这些曲线的AUC,如果可能的话还可以显示置信区间。
You can use the add = TRUE
argument the plot function to plot multiple ROC curves. 您可以使用绘图函数的
add = TRUE
参数来绘制多条ROC曲线。
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. 您可以通过
roc1$auc
获得ROC曲线的AUC,并且可以使用基础R绘图中的text()
函数添加它,或者可能只是将它放在图例中。
I don't know how to quantify confidence intervals...or if that is even a thing you can do with ROC curves. 我不知道如何量化置信区间...或者如果这甚至是你可以用ROC曲线做的事情。 Someone else will have to fill in the details on that one.
其他人将不得不填写那个细节。 Sorry.
抱歉。 Hopefully the rest helped though.
希望其余的有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.