On 02-May-07 07:45:48, Prof Brian Ripley wrote:
> Please do not send everything twice: you are using R-help in both the
> To: 
> and Cc: fields.
> 
> I disagree with Ted: it _is_ much easier to create a generator for this
> purpose.
> 
> Consider
> 
> rtgamma <- function(n, ..., tr = log(5000000))
> {
>      p <- pgamma(tr, ...)
>      qgamma(p*runif(n), ...)
> }
> 
> as inversion (especially at C level) is plenty fast enough.

Of course ... !!

Just to explain Brian's solution above:

Since pgamma(rgamma(...),...) is uniformly distributed on (0,1),
if rgamma is truncated to (0,tr) them pgamma(rgamma) will be
truncated to (0,pgamma(tr)), and hence uniformly distributed
on this range.

Best wishes,
Ted.



--------------------------------------------------------------------
E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 02-May-07                                       Time: 09:16:08
------------------------------ XFMail ------------------------------

______________________________________________
[email protected] 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.

Reply via email to