To find the area lying between the curve y = y(x) and 45 degree line (which,
assuming it goes through the origin, is y = x), you can use the following
function based on trapezoidal rule:
trap.rule < function(x,f) {sum(diff(x)*(f[1]+f[length(f)]))/2}
trap.rule(x,f=yx)
This area will be negative if y(x) is below the 45 degree line.
However, your question is not complete, I think. You need to specify the
interval of integration. For this you may need to determine the points of
intersection of the two curves, which involves the solution of a fixed point
problem.
Hope this helps,
Ravi.
Original Message
From: rhelpbounces at stat.math.ethz.ch [mailto:rhelp
bounces at stat.math.ethz.ch] On Behalf Of Renuka Sane
Sent: Tuesday, August 02, 2005 8:51 AM
To: rhelp at stat.math.ethz.ch
Subject: [R] question on graphs and finding area under a curve
Question on graphs:
The default case for drawing a graph in R, is where a little space is left
on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) 

there will be some space between the edge of the xaxis and where 0 is
placed. If I want 0 on the edge, how do I do it in R?
Area under the curve:
I have a 45 degree line and a curve above or below it. Is there a way in R
to find the area between the two?
Thanks,
Renuka

Renuka Sane
http://www.nyx.net/~rsane
[[alternative HTML version deleted]]
______________________________________________
Rhelp at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/rhelp
PLEASE do read the posting guide! http://www.Rproject.org/posting
guide.html
From: rhelpbounces at stat.math.ethz.ch [mailto:rhelp
bounces at stat.math.ethz.ch] On Behalf Of Renuka Sane
Sent: Tuesday, August 02, 2005 8:51 AM
To: rhelp at stat.math.ethz.ch
Subject: [R] question on graphs and finding area under a curve
Question on graphs:
The default case for drawing a graph in R, is where a little space is left
on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) 

there will be some space between the edge of the xaxis and where 0 is
placed. If I want 0 on the edge, how do I do it in R?
Area under the curve:
I have a 45 degree line and a curve above or below it. Is there a way in R
to find the area between the two?
Thanks,
Renuka

Renuka Sane
http://www.nyx.net/~rsane
[[alternative HTML version deleted]]
______________________________________________
Rhelp at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/rhelp
PLEASE do read the posting guide! http://www.Rproject.org/posting
guide.html