Skip to content
Back to formatted view

Raw Message

Message-ID: <001101c15b04$b7f3f5a0$66250a3e@xxx>
Date: 2001-10-22T14:20:35Z
From: Marco Taboga
Subject: generating a gamma random variable

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