V135: Gamma or Chi-Square Random Numbers

Author(s): F. James, K.S. Kölbig Library: MATHLIB
Submitter: Submitted: 15.10.1994
Language: Fortran Revised:

Function subprogram RANGAM generates a positive random number x according to the gamma distribution with parameter p>0, i.e., according to the density

displaymath75

A special case is the tex2html_wrap_inline77 -distribution with N degrees of freedom

displaymath81

Structure:

FUNCTION subprogram
User Entry Names: RNGAMA
External References: RANLUX, RNORMX

Usage:

In any arithmetic expression,

    RNGAMA(P)
has the value of a gamma-distributed random number, where tex2html_wrap_inline83 is of type REAL. The value of P may vary from call to call without influencing the efficiency.

Method:

For integral values of tex2html_wrap_inline85 , the logarithm of the product of p uniform random numbers is used. For any value of p > 15, the Wilson-Hilferty approximation (a transformed normal distribution) is used. For all other p, Johnk's algorithm is used.

Notes:

The routine is fast for small integer values of p, and for p > 15, (one Gaussian random number and one square root, plus a few multiplications). Non-integral values of p < 15 are rather slow.

Examples:

    CHI2 = 2*RNGAMA(0.5*N)
sets CHI2 to a random number distributed as tex2html_wrap_inline99 with N degrees of freedom.
tex2html_wrap_inline101

Michel Goossens Wed Jun 5 08:45:01 METDST 1996