Question: Plotting ROC curve using R
0
gravatar for muvinika
3.8 years ago by
muvinika0
muvinika0 wrote:

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

R gene • 2.7k views
ADD COMMENTlink modified 2.5 years ago by rk21530 • written 3.8 years ago by muvinika0

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

ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by rk21530
0
gravatar for Irsan
3.8 years ago by
Irsan6.8k
Amsterdam
Irsan6.8k wrote:
Use the ROCR-package
ADD COMMENTlink written 3.8 years ago by Irsan6.8k
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 REPLYlink written 3.8 years ago by muvinika0

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 REPLYlink written 3.6 years ago by HumeMarx20
0
gravatar for rk2153
2.5 years ago by
rk21530
rk21530 wrote:

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 COMMENTlink written 2.5 years ago by rk21530
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1814 users visited in the last hour