[R] Calculate the area under a curve

CarstenH cahoff at gmx.de
Mon Aug 24 11:10:11 CEST 2015


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.



More information about the R-help mailing list