I am trying to integrate a quadratic linear function for each individual within my study system.
I have already fit a lm
for each individual and calculated the intercept, linear coefficient and quadratic coefficient so my data set looks something like this for 75 individuals:
id.x Intercept coeff1 coeff2
1 0.1683109 -0.005091914 3.850922e-05
45 -0.5147262 0.015340073 -1.142777e-04
I would like the integrate the area under the curve ((int+x*coeff1+I(x^2)*coeff2) from lower=60.1 to upper=70.37)
for each individual.
I have tried using the integrate function written into a for loop:
for( i in 1:nrow( data ) ){
integrate( function(x)( data$Intercept[i]+data$coeff1[i]*x+data$coeff2[i]*I(x^2) ), lower=60.1, upper=70.37 )
}
As well as by using the sapply function but have not been able to get either to work. Any help with the coding would be greatly appreciated !!