This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Plotting ROC curve using R

I need to Construct and interpret an ROC curve using R for my dataset. Can anyone help me with the code.

gene r

try this -- and adapt for your dataset I have posted a redable/formatted version below

2 answers

Use the ROCR-package

Below is the sample code I have found. I am not clear how to interpret with my dataset. Kindly help

What did ROCR.simple$predictions contains in my way of understanding it is the predictions done. Correct me if am wrong. Else help me wit some example.

library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels )
pred2 <- prediction(abs(ROCR.simple$predictions + 
                        rnorm(length(ROCR.simple$predictions), 0, 0.1)), 
        ROCR.simple$labels)
perf <- performance( pred, "tpr", "fpr" )
perf2 <- performance(pred2, "tpr", "fpr")
plot( perf, colorize = TRUE)
plot(perf2, add = TRUE, colorize = TRUE)

Did you ever find an answer to this? I am finding it difficult to figure out what I need to put in. I just have a list of SNPs after performing logistic regression on them.

Try this -- and adapt for your dataset

titanic<-read.csv("http://christianherta.de/lehre/dataScience/machineLearning/data/titanic-train.csv",header=T)
head(titanic)
dim(titanic)
sm_titanic<-complete.cases(titanic[c(2,3,4,5,6,10),])
dim(sm_titanic)
head(sm_titanic)
sm_titantic_3<-titanic[,c(2,3,5,6,10)]
sm_titanic_3<-sm_titantic_3[complete.cases(sm_titantic_3),]
head(sm_titanic_3)
dim(sm_titanic_3)
tst_idx<-sample(714,200,replace=FALSE)
length(tst_idx)
tstdata<-sm_titanic_3[tst_idx,]
trdata<-sm_titanic_3[-tst_idx,]
length(trdata)
dim(tstdata)
dim(trdata)
glm_sm_titanic_3<-glm(Survived~.,data=trdata,family=binomial())
predicted<-predict(glm_sm_titanic_3,tstdata[,-Survived],type="response");
predicted<-predict(glm_sm_titanic_3,tstdata[,2:5],type="response");
require(ROCR)
auc_1<-prediction(predicted,tstdata$Survived)
auc_1
prf<-performance(auc_1, measure="tpr", x.measure="fpr")
slot_fp<-slot(auc_1,"fp")
slot_tp<-slot(auc_1,"tp")
table(tstdata$Survived)
xtpcount<-table(tstdata$Survived)
tpcount<-unlist(xtpcount)

fpr<-unlist(slot_fp)/tpcount[[1]]
tpr<-unlist(slot_tp)/tpcount[[2]]
plot(fpr,tpr, main="ROC Curve from first principles -- raw counts")

Log in to answer this question.