Re: [R] Percentile Estimation From Kernel Density Estimate

From: Karl Ove Hufthammer <>
Date: Mon, 28 Jul 2008 11:18:13 +0200

> Has anyone developed a defensible method of estimating percentiles from a
> univariate kernel density estimate?  I am working on a problem in which
> the density estimate is of interest, but I would also like to estimate the
> value of the variable for which the distribution was, say, 0.20.  I spent
> some time searching the archives and found some message from 2006 that
> implied such a method was not available at that time.

You could always use simple numerical integration do this. Something like

x = rnorm(1000)
d = density(x, n=10^4)
w = d$x[2] - d$x[1]
s = cumsum( w*d$y ) # Probably better to use 'integrate' with 'approxfun'.
d$x[ which(s >= .2)[1] ]

But it's certainly not very 'defensible' (I won't defend it!), and you would likely get a better (and defensible) answer with


Compare this with the 'real' value


Karl Ove Hufthammer

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 28 Jul 2008 - 09:20:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jul 2008 - 09:32:55 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive