s-news
[Top] [All Lists]

Re: Area under the curve

To: Alesia Ferguson <afer@stanford.edu>
Subject: Re: Area under the curve
From: "Petr Pikal" <petr.pikal@precheza.cz>
Date: Thu, 30 May 2002 14:49:42 +0200
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <5.1.0.14.0.20020529120133.00aaa7e0@afer.pobox.stanford.edu>

On 29 May 2002 at 12:03, Alesia Ferguson wrote:

> Using S-plus 6 on Windows ME
> 
> I looking for an equivalent function to trapz() found in Matlab to
> implement in S-plus 6

I do not know exact function of trapz() but from the subject and 
F.Harrell's reply this remainds me what I use for numeric 
integration to find out area of a peak

integ1<-function (x,y,dm=-Inf,hm=+Inf)
{
if(dm==-Inf)dm<-min(x)
if(hm==+Inf)hm<-max(x)
vyber<-x<=hm&x>=dm
l<-length(x[vyber])
v<-diff(x[vyber])
z<-y[vyber][1:l-1]+y[vyber][2:l]
o<-z*v/2
osum<-sum(o)
o1<-
(y[x==min(x[vyber])]+y[x==max(x[vyber])])*(max(x[vyber])-
min(x[vyber]))/2
cista<-osum-o1
return(c(osum,cista))
}

"osum" is an area below part of a curve to y=0 and "cista" is an 
area to baseline given by lowest y values in requred range.

The code works in R, for S+ it will need some minor language 
modification. 

> 
> Thank you
> Alesia
> 
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

Petr Pikal
petr.pikal@precheza.cz
p.pik@volny.cz



<Prev in Thread] Current Thread [Next in Thread>