[R] Percentile Estimation From Kernel Density Estimate

Karl Ove Hufthammer Karl.Hufthammer at math.uib.no
Mon Jul 28 11:18:13 CEST 2008


Jeffrey_Bromaghin at fws.gov:

> 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

quantile(x,.2)

Compare this with the 'real' value

qnorm(.2)

-- 
Karl Ove Hufthammer



More information about the R-help mailing list