Re: [R] Computing a CDF or many quantiles

2003-09-10 Thread Jerome Asselin

Also look at ecdf() from package "stepfun".

HTH,
Jerome Asselin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Computing a CDF or many quantiles

2003-09-10 Thread Jerome Asselin
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)
plot(xvals,empCDF(xvals),type="l",
xlab="Quantile",ylab="Cumulative Distribution Function")
lines(xvals,pexp(xvals),lty=2)
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.

HTH,
Jerome Asselin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Computing a CDF or many quantiles

2003-09-10 Thread Kevin S. Van Horn
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().

(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)
Quantiles:
 N=10;e<-CDF[1];
 for(i in (0:10)){
 j<-max(which(CDF<=i/N+e));print(c(x[j],CDF[j]))
 }
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Computing a CDF or many quantiles

2003-09-09 Thread Ted Harding
On 09-Sep-03 Kevin S. Van Horn wrote:
> Given f, a pdf over a finite interval, is there any existing R function
> that 
> can efficiently tabulate the cumulative distribution function for f, or
> produce all N+1 quantiles of the form i/N?  "Efficiently" here means
> better than doing repeated integrations for each point.

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)

Quantiles:
  N=10;e<-CDF[1];
  for(i in (0:10)){
  j<-max(which(CDF<=i/N+e));print(c(x[j],CDF[j]))
  }
  [1] -1.00  0.0003543119
  [1] -0.75000.09992753
  [1] -0.539 0.132
  [1] -0.350 0.2999169
  [1] -0.172 0.4003052
  [1]  0.000 0.5002921
  [1]  0.172 0.6002703
  [1]  0.349 0.7000831
  [1]  0.538 0.868
  [1]  0.749 0.9000725
  [1]  1 1
(a bit approximate here owing to not adopting a slightly more subtle
 approach to the first step).

Tabulation should be extremely straightforward.

Is this what you mean?

Best wishes,
Ted.



E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 167 1972
Date: 09-Sep-03   Time: 23:28:53
-- XFMail --

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Computing a CDF or many quantiles

2003-09-09 Thread Jerome Asselin

Perhaps approx() or approxfun() can help you create an efficient CDF.

HTH,
Jerome

On September 9, 2003 01:38 pm, Kevin S. Van Horn wrote:
> Content-Length: 417
> Status: R
> X-Status: N
>
> Given f, a pdf over a finite interval, is there any existing R function
> that can efficiently tabulate the cumulative distribution function for
> f, or produce all N+1 quantiles of the form i/N?  "Efficiently" here
> means better than doing repeated integrations for each point.
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Computing a CDF or many quantiles

2003-09-09 Thread Kevin S. Van Horn
Given f, a pdf over a finite interval, is there any existing R function that 
can efficiently tabulate the cumulative distribution function for f, or 
produce all N+1 quantiles of the form i/N?  "Efficiently" here means better 
than doing repeated integrations for each point.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help