[R] Computing a CDF or many quantiles

Jerome Asselin jerome at hivnet.ubc.ca
Thu Sep 11 01:24:34 CEST 2003

On September 10, 2003 04:03 pm, Kevin S. Van Horn wrote:
> Your method looks like a naive reimplementation of integration, and
> won't work so well for distributions that have the great majority of the
> probability mass concentrated in a small fraction of the sample space.
>  I was hoping for something that would retain the adaptability of
> integrate().

Yesterday, I've suggested to use approxfun(). Did you consider my 
suggestion? Below is an example.

N <- 500
x <- rexp(N)
y <- rank(x)/(N+1)
empCDF <- approxfun(x,y)
xvals <- seq(0,4,.01)
xlab="Quantile",ylab="Cumulative Distribution Function")
legend(2,.4,c("Empirical CDF","Exact CDF"),lty=1:2)

It's possible to tune in some parameters in approxfun() to better match 
your personal preferences. Have a look at help(approxfun) for details.

Jerome Asselin

More information about the R-help mailing list