Hi everybody, I have a data set with a value and a status (positive or negative case) and I want make a ROC Analysis. So, with ROCR Package, I have got the ROC curve (True Positive Fraction [tpf] according 1-True Negative Fraction [1-tnf]). http://r.789695.n4.nabble.com/file/n4469203/01.png But, now I want a new graphic which show the sum of true positive fraction and true negative fraction according each value on my data set (tpf + tnf according the values). http://r.789695.n4.nabble.com/file/n4469203/02.png If you have an idea ! Thank you very much for all help, Camille Leclerc -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405 Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4469203.html Sent from the R help mailing list archive at Nabble.com.
Hi Camille, Do you need something like that? ################### library(ROCR) data(ROCR.simple) pred <- prediction(ROCR.simple$predictions, ROCR.simple$labels) tpf <- unlist(performance(pred,"tpr")@y.values) tnf <- unlist(performance(pred,"tnr")@y.values) x <- rev(unlist(pred at cutoffs)) plot(x, tpf+tnf, t='l', xlab='Value', ylab='TPF+TNF') ################### Regards, Pascal ----- Mail original ----- De?: Camille Leclerc <camille.leclerc at ymail.com> ??: r-help at r-project.org Cc?: Envoy? le : Mardi 13 mars 2012 23h30 Objet?: [R] ROC Analysis Hi everybody, I have a data set with a value and a status (positive or negative case) and I want make a ROC Analysis. So, with ROCR Package, I have got the ROC curve (True Positive Fraction [tpf] according 1-True Negative Fraction [1-tnf]). http://r.789695.n4.nabble.com/file/n4469203/01.png But, now I want a new graphic which show the sum of true positive fraction and true negative fraction according each value on my data set (tpf + tnf according the values). http://r.789695.n4.nabble.com/file/n4469203/02.png If you have an idea ! Thank you very much for all help, Camille Leclerc -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405? Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4469203.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi, Pascal, I tried to use your method which functions but the values of the abscissa are not good. When I talked about ?value?, I wanted mean the values of my starting dataset that I have classified into two classes positive and negative classes, such as this : Value Status TPF TNF 1000 1 487 0 852 1 927 1 799 1 369 0 ? ? And for each value of my dataset, I want the tpf and tnf. With your method, I have an abscissa which has values between 0 and 1. All the best, Camille ----- -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405 Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4471300.html Sent from the R help mailing list archive at Nabble.com.
Hi Camille, I am surprised by your answer. If you do: pred <- prediction(ROCR.simple$predictions*1000, ROCR.simple$labels) x <- rev(unlist(pred at cutoffs)) You can see than x values are now between 0 and 1000. So, it should be probably the same for your data. Regards, Pascal -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4471300.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi, I made a mistake, effectively Pascal your method given to the first message is correct. I didn't use the good data, so it's sure that it could not work ! But, I have an another question : Can I obtain a same graph except that the y-axis represents the likelihood ratio ? All the best, Camille ----- -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405 Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4475038.html Sent from the R help mailing list archive at Nabble.com.
Hi everybody, Pascal, your script works again but I want to calculate the LR otherwise. I know the likelihood ratio is linked at the roc curve and so there are different ways to calculate the LR. The slope of an ROC curve can be defined in three ways: (1) as the tangent at a particular point on the ROC curve corresponding to a test value x (2) as the slope between the origin 0 and the point on the ROC curve corresponding to a test value x (3) as the slope between two points on the ROC curve corresponding to the test values x and y http://r.789695.n4.nabble.com/file/n4478233/LR.png But in my case, I want calculated the LR with the third way. So, LR (x,y) =(sensitivity (x)-sensitivity (y))/(specificity (y)-specificity (x)) = (TPR(x)-TPR (y))/(FPR (x)-FPR (y)) It is possible ?! All the best, Camille ----- -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405 Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4478233.html Sent from the R help mailing list archive at Nabble.com.
Hi Camille, Does following work? ll <- length(x) (TPR[1:(ll-1)]-TPR[2:ll])/(FPR[1:(ll-1)]-FPR[2:ll]) Regards, Pascal -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4478233.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi everybody, Pascal, your code works, but when I want to do the graph I have an error message. here is my code : x<-rev(unlist(pred at cutoffs)) tpf<-unlist(performance(pred, "tpr")@y.values) fpf<-unlist(performance(pred,"fpr")@y.values) ll<-length(x) p<-(tpf[1:(ll-1)]-tpf[2:ll])/(fpf[1:(ll-1)]-fpf[2:ll]) plot(x,p) *Erreur dans xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ* So, when I look the lenghts of x and p, I have this : *x : numeric[1735] p : numeric[1734]* On the other hand, it's normal since I have the slope between two points on the ROC curve and so I have x points and x-1 slope values. How to get the graph?! All the best, Camille ----- -- Camille Leclerc, Master student Lab ESE, UMR CNRS 8079 Univ Paris-Sud Bat 362 F-91405 Orsay Cedex FRANCE -- View this message in context: http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4503354.html Sent from the R help mailing list archive at Nabble.com.