Gamma Distribution

 

Menu location: Data_Generating_Random Numbers_Gamma.

 

The gamma distribution depends upon two parameters: A (the shaping parameter) and B (the scaling parameter).

 

The gamma density function is:

 

The gamma function Γ(*) is:

 

If A is an integer then Γ(A)=(A-1)! where x! is factorial x.

 

When A = 1 this gives an exponential distribution. If you vary A then the shape of the distribution will change. Changing B does not affect the shape of the distribution, just its scale on the x axis.

 

Illustration

Suppose you want 100 random values from a gamma distribution with a shaping parameter A = 2 and a scaling parameter B = 3, for example to simulate waiting times that have a mean of 6 and a right skewed spread.

 

To generate them in StatsDirect select Gamma from the Random Numbers section of the Generating section of the Data menu. Enter 1 as the number of columns to fill and 100 as the number of rows, 2 for A and 3 for B, and enter 1234 as the seed in place of the one suggested. A column headed "Gamma (seed 1234, A = 2, B = 3)" is written to the workbook; the same seed gives the same column again.

 

For this distribution, where Γ(2) = 1! = 1 so that g(t) = t e-t/3/9:

 

Mean = 6 (AB)

Variance = 18 (AB2)

Standard deviation = 4.242641

Density at t = 4: 0.117154

P(t <= 4) = 0.38494

Median = 5.035041

95th centile = 14.231594

 

A sample of 100 values generated in R (see the R code below) had:

 

Sample mean = 6.599323

Sample sd = 4.681867

 

The column that StatsDirect writes for seed 1234 has mean 6.021564 and standard deviation 4.184212.

 

The sample mean is 0.6 above the mean of the distribution, well within the sampling variation to expect from 100 values (the standard error of the mean is 4.24/10 = 0.42). The values that StatsDirect writes differ from R's for any seed, because each program seeds its generator in its own way, but a column of 100 gamma deviates from either should have a mean near 6, a standard deviation near 4.24 and a right skewed histogram with its peak near (A-1)B = 3.

 

The special cases above can be checked from the cumulative probabilities:

 

A = 1: P(t <= 4) = 0.736403 (the exponential distribution with mean 3 gives 0.736403)

A = 0.5, B = 1: P(t <= 1.5) = 0.916735 (the chi-square distribution with 1 degree of freedom gives 0.916735 for a squared standard normal deviate of at most 3)

 

These figures were calculated in R, whose dgamma, pgamma, qgamma and rgamma functions define shape and scale as StatsDirect defines A and B. StatsDirect itself only generates the random numbers, so the probabilities and quantiles do not appear in a StatsDirect report.

 

See random number fill.