[R] Computing a CDF or many quantiles

Kevin S. Van Horn kvanhorn at ksvanhorn.com
Thu Sep 11 01:03:51 CEST 2003

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 

(Ted Harding) wrote:

>If that's all you want to do, then a very straightfoward approach should
>be OK. I illustrate with a truncated normal distribution on [-1,1]:
>  x <- (-1)+(0.001*(0:2000));pdf<-dnorm(x); pdf<-pdf/(sum(pdf)*0.001)
>  CDF<-cumsum(pdf)*0.001
>  plot(x,pdf,ylim=c(0,1),type="l");lines(x,CDF)
>  N=10;e<-CDF[1];
>  for(i in (0:10)){
>      j<-max(which(CDF<=i/N+e));print(c(x[j],CDF[j]))
>  }

More information about the R-help mailing list