Quantile of kernel density estimator I consider the kernel density estimation, and I want to find the quantile the quantile at some level (0.95) of the KDE.     
z<-rnorm(25)
v<-density(z)
plot(v$x,v$y,type="l")

qt<-quantile(z,0.997)
abline(v=qt,col="red")


plot(v$x,cumsum(v$y),type="l")
abline(h=0.997,col="blue",type="p")

The first plot is the plot of the KDE and the line of the quantile of the data.
How to get the distribution of the KDE? 
How to get the quantile with respect to the KDE? Is only for comparison.

 A: The cdf corresponding to the kernel density estimate $\hat f(x)$ is given by
$$
\hat F(x)=\int_{-\infty}^x \hat f(u)du = \frac1n\sum_{i=1}^n \phi(\frac{x-x_i}h)
$$
where $h$ is the bandwidth and $\phi$ is the cdf of the kernel used (e.g. the cdf of the standard normal).  So equating this to $\alpha$ and solving for $x$ (numerically using some root finding algorithm) gives you the corresponding estimate of the $\alpha$-quantile (red line below), slightly larger than the empirical quantile (blue line).
R implementation:
set.seed(1)
z<-rnorm(25)
v<-density(z)
plot(v,main="")

g <- function(x, z, bw, p) sum(pnorm(x-z, sd=bw))/length(z) - p
abline(v=uniroot(g,range(v$x)+c(-1,1),z=z,bw=v$bw,p=.95)$root,col="red") # quantile based on kernel density estimate
abline(v=quantile(z,.95),col="blue") # empirical quantile
points(z,rep(0,25)) 


A: In my programs, I am using a split approach. Within the distribution range the emperical quantiles are accurate enough usually, so I am sorting the data and calculate the quantiles from this, best with linear interpolation. I think Excel or other programs are doing so too. For extreme percentile e.g. beyond (n-1)/n and using KDE often only the last few kernels matter, so only these have pdf>0, and only these can make cdf<1. If only the last kernel matters I need only the CDF of that last kernel and the cdf (close to 1.0) will become 1-CDFkernel/n. And this is easy to invert for all practical kernels. And I do not need to deal with root finding techniques.
