[R] Calculate the area under a curve

CarstenH cahoff at gmx.de
Mon Aug 24 16:38:40 CEST 2015


Hi Charles

I am new in R and would like to learn/use it in the beginning for easy
operations. I already used google for houres and did not find a solution for
this in my eyes easy calculation process. I spent long time with reading
forums, package handbooks, and tried and error but always failed. But I
still believe that somebody could tell me something like: Load package XY
and than use that command Z... 

Sorry if I am naive or half-baked but I guess there shout be a very easy
command to calculate the area under a function.


E.g. If I use the package AUC: 

auc(fitP, min=20, max=100)
there is an error report which I do not understand: 
/Error in auc(fitP1, min = 20, max = 100) : object 'ans' not found.
/

My task in short: 

I have 20 x and associated 20 y values and created a function by

fitP <- lm( y~poly(x,3,raw=TRUE) )

the function looks like this: 

fitP

/Call:
lm(formula = y2 ~ poly(x2, 3, raw = TRUE))


Coefficients:
             (Intercept)  poly(x2, 3, raw = TRUE)1  
               1.125e+01                -5.262e-01  
poly(x2, 3, raw = TRUE)2  poly(x2, 3, raw = TRUE)3  
               9.156e-03                -4.771e-05  

/

The last step now is to integrate the function. If I put this data by hand
in any of many AUC-calculators in the web it works. But I still not find the
"easy" way within R.






--
View this message in context: http://r.789695.n4.nabble.com/Calculate-the-area-under-a-curve-tp4711418p4711434.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list