If you use logspline estimation (logspline package) instead of kernel density estimation then this is simple as there are cumulative area functions for logspline fits.

If you need to do this with kernel density estimates then you can just find the area over your region for the kernel centered at each data point and average those values together to get the area under the entire density estimate.

-----Original Message-----

From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Duke

Sent: Friday, January 27, 2012 3:45 PM

To: r-help at r-project.org

Subject: [R] percentage from density()

Hi folks,

I know that density function will give a estimated density for a give

dataset. Now from that I want to have a percentage estimation for a

certain range. For examle:

y = density(c(-20,rep(0,98),20))

plot(y, xlim=c(-4,4))

Now if I want to know the percentage of data lying in (-20,2). Basically

it should be the area of the curve from -20 to 2. Anybody knows a simple

function to do it?

Thanks,

D.

______________________________________________

R-help at r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.