Re: [R] Percentile Estimation From Kernel Density Estimate

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

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive