[R] generating a gamma random variable

Marco Taboga mtaboga at tiscalinet.it
Mon Oct 22 16:20:35 CEST 2001


One method to generate a value x taken by a random variable X with a strictly increasing distribution function F(x) is the following:
    - Generate a value y taken by a random variable Y distributed as uniform on [0,1] (every programming language has routines to do this)
    - Evaluate the inverse of the distribution function F at the point y you just generated
    - The number you get x=F^(-1)(y) is the value x you wanted to generate (drawn from the distribution you chose)

This method is nice, but it can be computationally very expensive, since, in most cases (as in the case of a gamma), to compute the inverse of F you have to solve numerically the equation F(x)-y=0 and every iteration of the method you use to solve the equation requires the numerical computation of a definite integral to find F(x).
The reward you get for this great amount of computation is that your random generator for X is as good as the random generator for Y (the uniform random variable).

Sincerely,
Marco.



 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20011022/ed049ac9/attachment.html


More information about the R-help mailing list