s-news
[Top] [All Lists]

Re: Area between curves

To: jconnor@bio.ri.ccf.org
Subject: Re: Area between curves
From: "Petr Pikal" <petr.pikal@precheza.cz>
Date: Tue, 17 Apr 2001 08:09:46 +0200
Cc: s-news@wubios.wustl.edu
In-reply-to: <Pine.SOL.3.96.1010416161854.19195S-100000@foster>
Hi

On 16 Apr 2001, at 16:21, Jason Connor wrote:

> 
> 
> Say I have have vectors y1 and y2 and corresponding vector x.
> 
> Plotting y1 vs. x and y2 vs. x, the two curves may or may not cross.
> 
> Does anyone have a function that quickly calculates the area between
> the curves betwen min(x) and max(x)?
> 
> Thank you.
> 
> 
> 
> ---------------------------------------------------------------------
> 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

Actually I have only a functions for R which could be used in S+ (I 
hope) computing the area of a peak in some spectrum, so you mayby 
has to modify it a bit. And sorry they were not designed for public so 
they are not well documented.

The first one uses locator to pinpoint lower left and upper right corner 
of the curve from some plot. 

osum is an area from the baseline x to the curve
and 
cista is a only peak area without a rectangular area below lower and 
upper margins of y.

The second one uses lower and upper margin of x stated manually.

Hope it helps you.
integ_function (x,y)
{
replot(x,y)
meze_locator(2)
dm_meze$x[1]
hm_meze$x[2]
abline(v=c(dm,hm),col=2)
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))
}

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))
}


Petr Pikal
0641 25 2258
0724 008 364
petr.pikal@precheza.cz
p.pik@volny.cz


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