Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate nonparametric curve in R

Tags:

r

Just a warning, I started using R a day ago...my apologies if anything seems idiotically simple.

Right now im trying to have R take in a .txt file with acelerometer data of an impact and calculate a Head injury criterion test for it. The HIC test requires that curve from the data be integrated on a certain interval.

The equation is at the link below...i tried to insert it here as an image but it would not let me. Apparently i need some reputation points before it'll let me do that.

equation

a(t) is the aceleration curve.

So far i have not had an issue generating a suitable curve in R to match the data. The loess function worked quite well, and is exactly the kind of thing i was looking for...i just have no idea how to integrate it. As far as i can tell, loess is a non-parametric regression so there is no way to determine the equation of the curve iteslf. Is there a way to integrate it though?

If not, is there another way to acomplish this task using a different function?

Any help or insighful comments would be very much appreciated.

Thanks in advance,

Wes

One more question though James, how can i just get the number without the text and error when using the integrate() function?

like image 408
user1003131 Avatar asked Oct 19 '11 12:10

user1003131


1 Answers

You can use the predict function on your loess model to create a function to use with integrate.

# using the inbuilt dataset "pressure"
plot(pressure,type="l")

# create loess object and prediction function
l <- loess(pressure~temperature,pressure)
f <- function(x) predict(l,newdata=x)

# perform integration
integrate(f,0,360)
40176.5 with absolute error < 4.6

And to extract the value alone:

integrate(f,0,360)$value
[1] 40176.5
like image 108
James Avatar answered Sep 28 '22 08:09

James