[R] Function for AUC?

Armin Goralczyk agoralczyk at gmail.com
Mon Dec 17 11:07:25 CET 2007


Hi all

On Dec 17, 2007 9:57 AM, N. Lapidus <n.lapidus at gmail.com> wrote:
> Hi Armin,
> Do you know the rocr package ? This is very easy to draw ROC curves and to
> calculate AUC with it.
> http://rocr.bioinf.mpi-sb.mpg.de/
> Hope this will help.
>

I know ROCR although I am not familiar with ROC. I have seen the AUC
function of ROCR, but are you sure that this is applicable to the
stated problem, i.e. calculate AUC of serum levels of a drug over
time?! ROC seems to handle completely different problems.

I have been reading the following post (thanks for the hint Stephen):

> On Dec 17, 2007 2:58 AM, Stephen Weigand <weigand.stephen at gmail.com> wrote:
>
> > RSiteSearch("AUC")
> >
> > would lead you to
> >
> > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46416.html
> >

I tried it:

> y<-c(1,2,3,4,5);x<-c(10,15,10,5,0)
> trap.rule <- function(x,y) sum(diff(x)*(y[-1]+y[-length(y)]))/2
> trap.rule(x,y)
[1] -45

It is not the correct value, but the formula seems applicable and I
changed it to

> auc <- function(x,y) sum((x[-length(x)] + x[-1]) * (y[-1]-y[-length(y)]))/2
> auc(x,y)
[1] 35

which seems to be correct. I hope everyone agees.
I didn't know it's that simple. I guess I don't need another function.
Thank's for all the help and all the suggestions.

-- 
Armin Goralczyk, M.D.
--
Universitätsmedizin Göttingen
Abteilung Allgemein- und Viszeralchirurgie
Rudolf-Koch-Str. 40
39099 Göttingen
--
Dept. of General Surgery
University of Göttingen
Göttingen, Germany
--
http://www.chirurgie-goettingen.de


More information about the R-help mailing list