Plotting ROC curve using R
2
0
Entering edit mode
8.8 years ago
muvinika ▴ 10

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

gene R • 4.7k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
8.8 years ago
Irsan ★ 7.8k
Use the ROCR-package
ADD COMMENT
0
Entering edit mode

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)
ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
7.5 years ago
rk2153 • 0

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")
ADD COMMENT

Login before adding your answer.

Traffic: 2168 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6