[R] Problem with area()
Agustin Lobo
aloboaleu at gmail.com
Fri Aug 7 11:54:30 CEST 2009
I'm using area() to evaluate the area under
2 functions (defined using approxfun()) and the result is in contradiction
with visual inspection (please see:
http://sites.google.com/site/eospansite/dummy/problem_area.jpg
)
The area under the red curve should be larger
than the one under the black curve, but I'm
geting the opposite result using area().
This is what I'm doing:
require(MASS)
f1 <- approxfun(x,y1)
f2 <- approxfun(x,y2)
plot(x,y1,ylim=range(c(y1,y2)))
lines(x,f1(x),col="black")
points(x,y2)
lines(x,f2(x),col="red")
area1 <- area(f1,min(x),max(x))
area2 <- area(f2,min(x),max(x))
text(4.5,1.6,paste("f2:",round(area2,3)),col="red")
text(5.5,0.1,paste("f1:",round(area1,3)),col="black")
title(main="Areas under curves")
grid(50,50)
What am I doing wrong? Could this be a problem with
an inappropriate use of approxfun() ?
Data can be found here:
http://sites.google.com/site/eospansite/dummy/areaproblem.rda
Thanks
Agus
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
e-mail Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster
More information about the R-help
mailing list