Skip to content
Prev 14373 / 398502 Next

generating a gamma random variable

On Sun, 21 Oct 2001, Faheem Mitha wrote:

            
Or simulate from a gamma (using rgamma()) and multiply
Both 1 and 2 are more expensive than rchisq() or rgamma(), at least if T
is large. A simple experiment shows that rnorm takes about 2-3 times as
long as rexp, but that 10^6 of them still only takes a few seconds.

In general the answer to the question "Which is quicker?" is "Try it and
see" (and the most common result is "It doesn't matter").
You can obviously start by checking the mean, variance and perhaps a few
more moments.

One more general possibility is to use the large deviation bound used in
checking the built-in generators, in tests/p-r-random-tests.R.  The
empirical CDF F_n from a sample of size n and the true CDF F are related by
   P(sup | F_n - F | > t) < 2 exp(-2nt^2)

If you get a large enough sample n this should detect any error in the
distribution (provided you have F computed correctly). However, AFAIK this
test has never actually detected an error in any of our random number
generators so I don't know how useful it is in practice.

If there are special cases of your simulation where you know the correct
answer this can also help with checking.


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._