How to find ROC plot in R?

r
plotting
logistic_regression

#1

I am solving one classification problem using logistic regression algorithm.I am currently trying to find ROC(Reciever Operator Characteristic ) curve to optimize threshold value of the model.

quality=read.csv(“quality.csv”) # load the data
require(“caTools”) # package for splitting
set.seed(88)
split= sample.split(quality$PoorCare,0.75) # 75% data for training
qualitytrain=subset(quality,split==TRUE)
qualitytest=subset(quality,split==FALSE)
QualityLog=glm(PoorCare~ OfficeVisits+Narcotics , data=qualitytrain,family=binomial) # model
predicttrain=predict(QualityLog,type=“response”) #predicting on training data


#2

Hello @sid100158 id100158,

Here is one way to draw ROC plot in R

predicttest=predict.glm(QualityLog,qualitytest,type=“response”) #predicting on testing data(exclude response variable from qualitytest)

Then For ROC plot
convert response variable into binary (0,1),say
poorcare = ifelse(qualitytest$PoorCare==“no”,0,1)

library(pROC)
rp=roc(poorcare~predicttest, data = qualitytest)
plot(rp)

Hope this helps,
Regards,
Nilesh_Borade