Re: [R] Inverse fuction of ecdf

2007-01-28 Thread Duncan Murdoch
On 1/28/2007 5:41 PM, Geoffrey Zhu wrote:
> Hi Everyone,
> 
> I want to generate some random numbers according to some empirical
> distribution. Therefore I am looking for the inverse of an empirical
> cumulative distribution function. I haven't found any in R. Can anyone
> give a pointer?

sample() works fine if you have a sample to start from.  If you really 
need to start from an ecdf, you could generate x and prob args to 
sample() by looking inside the ecdf object.  For example:

x <- rbinom(100, 100, 0.2)
e <- ecdf(x)

Now either of these should give you what you want.

size <- 1000
sample(x, size, replace=TRUE)

or

vals <- get("x", environment(e))
probs <- diff(c(0, get("y", environment(e
sample(vals, size, replace=TRUE, prob=probs)

Duncan Murdoch

__
R-help@stat.math.ethz.ch 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.


Re: [R] Inverse fuction of ecdf

2007-01-28 Thread roger koenker
quantile() does some somewhat exotic interpolation --- if you are  
wanting to
match moments you need to be more explicit about how you are computing
moments for the two approaches...

On Jan 28, 2007, at 5:06 PM, Geoffrey Zhu wrote:

> Hi Benilton,
>
> I tried this. It sort of works, but the results are not very
> satisfactionary. The 3rd moment and higher do not match those of the
> original by a large difference. Do you have any better way to do this?
>
> Thanks,
> Geoffrey
>
> -Original Message-
> From: Benilton Carvalho [mailto:[EMAIL PROTECTED]
> Sent: Sunday, January 28, 2007 4:45 PM
> To: Geoffrey Zhu
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Inverse fuction of ecdf
>
> ?quantile
>
> b
>
> On Jan 28, 2007, at 5:41 PM, Geoffrey Zhu wrote:
>
>> Hi Everyone,
>>
>> I want to generate some random numbers according to some empirical
>> distribution. Therefore I am looking for the inverse of an empirical
>> cumulative distribution function. I haven't found any in R. Can  
>> anyone
>
>> give a pointer?
>>
>> Thanks,
>> Geoffrey
>
>
>
> ___=0A=
> =0A=
> =0A=
> The information in this email or in any file attached hereto... 
> {{dropped}}
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.


Re: [R] Inverse fuction of ecdf

2007-01-28 Thread Geoffrey Zhu
Hi Benilton,

I tried this. It sort of works, but the results are not very
satisfactionary. The 3rd moment and higher do not match those of the
original by a large difference. Do you have any better way to do this?

Thanks,
Geoffrey 

-Original Message-
From: Benilton Carvalho [mailto:[EMAIL PROTECTED] 
Sent: Sunday, January 28, 2007 4:45 PM
To: Geoffrey Zhu
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Inverse fuction of ecdf

?quantile

b

On Jan 28, 2007, at 5:41 PM, Geoffrey Zhu wrote:

> Hi Everyone,
>
> I want to generate some random numbers according to some empirical 
> distribution. Therefore I am looking for the inverse of an empirical 
> cumulative distribution function. I haven't found any in R. Can anyone

> give a pointer?
>
> Thanks,
> Geoffrey



___=0A=
=0A=
=0A=
The information in this email or in any file attached hereto...{{dropped}}

__
R-help@stat.math.ethz.ch 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.


Re: [R] Inverse fuction of ecdf

2007-01-28 Thread Benilton Carvalho
?quantile

b

On Jan 28, 2007, at 5:41 PM, Geoffrey Zhu wrote:

> Hi Everyone,
>
> I want to generate some random numbers according to some empirical
> distribution. Therefore I am looking for the inverse of an empirical
> cumulative distribution function. I haven't found any in R. Can anyone
> give a pointer?
>
> Thanks,
> Geoffrey

__
R-help@stat.math.ethz.ch 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] Inverse fuction of ecdf

2007-01-28 Thread Geoffrey Zhu
Hi Everyone,

I want to generate some random numbers according to some empirical
distribution. Therefore I am looking for the inverse of an empirical
cumulative distribution function. I haven't found any in R. Can anyone
give a pointer?

Thanks,
Geoffrey

___=0A=
=0A=
=0A=
The information in this email or in any file attached hereto...{{dropped}}

__
R-help@stat.math.ethz.ch 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.