[R] Calculate the area under a curve

Charles Determan cdetermanjr at gmail.com
Mon Aug 24 16:10:47 CEST 2015


Hi Carsten,

This list is meant to help you solve specific coding problems.  What have
you tried?  A quick google search will provide several packages including
caTools, ROCR, AUC, pROC.  Look in to some of them, try them out and report
back if you have problems 'using' a function instead of just asking 'how
can I do this?'  As with everything in R, there are many different ways to
accomplish the same thing.

Regards,
Charles

On Mon, Aug 24, 2015 at 4:10 AM, CarstenH <cahoff at gmx.de> wrote:

> Hi all
>
> I need to calculate the area under a curve (integral) for the following
> data
> pairs:
>
> Depth SOC
> 22.5    0.143
> 28.5    0.165
> 34.5    0.131
> 37.5    0.134
> 40.5    0.138
> 43.5    0.107
> 46.5    0.132
> 49.5    0.175
> 52.5    0.087
> 55.5    0.117
> 58.5    0.126
> 61.5    0.13
> 64.5    0.122
> 67.5    0.161
> 71.5    0.144
> 76.5    0.146
> 82.5    0.156
> 94.5    0.132
>
> (Table name is P)
>
> After reading the data set I assiged the collumns by:
>
> /x <- (P$Depth)
> y <- (P$SOC)
> /
>
> and decided to make a ploynominal function (3rd order):
>
> /fitP <- lm( y~poly(x,3,raw=TRUE) )/
>
> At the next step I failed. I can plot point and function but am not able to
> integrate the curve between e.g. depths 20 and 80.
>
> If I try:
> /
> integrand <-function(fitP1)
>   predict(y)
> integrate(integrand, lower = 25, upper = 80)/
>
> the "Conosle" opend with the message: "Source unavailable or out of sync"
> and
> /
> function(fitP1)
> predict(y)
> /
> )
>
>
> Would be great if somebody could help!
>
> Thanks
>
> Carsten
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Calculate-the-area-under-a-curve-tp4711418.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list