DADiSP Worksheet Functions > Function Categories > Generated Series > GRANDGAMMA

 

GRANDGAMMA

Purpose:

Generates a gamma distributed random series.

Syntax:

GRANDGAMMA(length, spacing, shape, scale)

length

-

An integer, the length of the output series.

spacing

-

A real, the spacing (delta x) between points.

shape

-

Optional. A real, the shape parameter. Defaults to 1.0.

scale

-

Optional. A real, the scale parameter. Defaults to 1.0.

Returns:

A series.

Example:

grandgamma(100, 0.01, 2.0, 4.0)

 

creates a 100 point gamma distributed random series of values from a population where the shape is 2.0 and the scale is 4.0.

Example:

x = 0..0.1..30;

k = 10;

theta = 1;

 

W1: grandgamma(50000, 1, k, theta);label("Random Gamma")

W2: hist(W1, 50, "pdf");label("Histogram")

W3: exp((k-1)*log(x/theta) - x/theta - gammaln(k))/theta;overp(W2, lred);lines;label("Gamma Distribution")

 

W1 contains 50000 samples of gamma distributed random values with a shape parameter of 10 and a scale parameter of 1.

 

W2 contains a 50 sample normalized histogram of W1.

 

W3 compares the distribution of the generated gamma random series to the analytic distribution with shape 10 and scale 1.

Remarks:

GRANDGAMMA uses a transformation-rejection method due to Marsaglia and Tsang [1] to transform uniformly distributed random values to gamma distributed values.

 

The probability density function, f(x), for gamma distributed random values is:

 

 

where k is the shape parameter, θ is the scale parameter and Γ is the gamma function implemented by GAMMA.  The cumulative distribution function is:

 

 

where γ is the lower incomplete gamma function implemented by GAMMAINC.

 

The mean of a gamma distribution is and the variance is 2.

 

The exponential distribution and chi-squared distribution are special cases of the gamma distribution.

See Also:

GNORMAL

GRANDBINOMIAL

GRANDOM

GRANDPOISSON

HISTOGRAM

PDFNORM

PROBN

RAND

RANDN

SEEDRAND

References:

[1]  Marsaglia G and Tsang W

       A Simple Method for Generating Gamma Variables

       ACM Transactions on Mathematical Software

       Vol 26, No 3, September 2000, pages 363-372.