Something like this? library(KernSmooth) x <- rnorm(100) KS <- bkde(x) diff <- KS$x[2] - KS$x[1] yc <- cumsum(KS$y*diff) approx(yc, KS$x, runif(1000))
If you are going to use approx() repeatedly, you can create a function with approxfun(). ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 ----- Original Message ----- From: "firdaus.janoos" <fjan...@bwh.harvard.edu> To: r-help@r-project.org Sent: Wednesday, July 11, 2012 9:33:30 AM Subject: [R] Computing inverse cdf (quantile function) from a KDE Hello, I wanted to know if there is a simple way of getting the inverse cdf for a KDE estimate of a density (using the ks or KernSmooth packages) in R ? The method I'm using now is to perform a numerical integration of the pdf to get the cdf and then doing a search for the desired probablity value, which is highly inefficient and very slow. Thanks, -fj [[alternative HTML version deleted]] ______________________________________________ R-help@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. ______________________________________________ R-help@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.