# Gamma distribution

*950*pages on

this wiki

Template:Probability distribution
In probability theory and statistics, the **gamma distribution** is a two-parameter family of continuous probability distributions. It has a scale parameter *θ* and a shape parameter *k*. If *k* is an integer then the distribution represents the sum of *k* exponentially distributed random variables, each of which has parameter .

## Characterization

That a random variable *X* is gamma-distributed with scale *θ* and shape *k* is denoted

### Probability density function

The probability density function of the gamma distribution can be expressed in terms of the gamma function:

(This parameterization is used in the infobox and the plots.)

Alternatively, the gamma distribution can be parameterized in terms of a shape parameter and an inverse scale parameter , called a rate parameter:

- If is a positive integer, then

Both parameterizations are common because either can be more convenient depending on the situation.

### Cumulative distribution function

The cumulative distribution function is the regularized gamma function, which can be expressed in terms of the incomplete gamma function,

## Properties

### Summation

If *X*_{i} has a Γ(α_{i}, β) distribution for *i* = 1, 2, ..., *N*, then

provided all *X*_{i} are independent.

The gamma distribution exhibits infinite divisibility.

### Scaling

For any *t* > 0 it holds that *tX* is distributed Γ(*k*, *t*θ), demonstrating that *θ* is a scale parameter.

### Exponential family

The Gamma distribution is a two-parameter exponential family with natural parameters and , and natural statistics and .

### Information entropy

The information entropy is given by

where ψ(*k*) is the digamma function.

### Kullback–Leibler divergence

The directed Kullback–Leibler divergence between Γ(α_{0}, β_{0}) ('true' distribution) and Γ(α, β) ('approximating' distribution) is given by

### Laplace transform

The Laplace transformation of the gamma distribution is

## Parameter estimation

### Maximum likelihood estimation

The likelihood function for *N* iid observations is

from which we calculate the log-likelihood function

Finding the maximum with respect to by taking the derivative and setting it equal to zero yields the maximum likelihood estimate of the θ parameter:

Substituting this into the log-likelihood function gives

Finding the maximum with respect to *k* by taking the derivative and setting it equal to zero yields

where

is the digamma function.

There is no closed-form solution for *k*. The function is numerically very well behaved, so if a numerical solution is desired, it can be found using, for example, Newton's method. An initial value of *k* can be found either using the method of moments, or using the approximation

If we let

then *k* is approximately

which is within 1.5% of the correct value.^{[citation needed]} An explicit form for the Newton-Raphson update of this initial guess is given by Choi and Wette (1969) as the following expression:

where denotes the trigamma function (the derivative of the digamma function).

The digamma and trigamma functions can be difficult to calculate with high precision. However, approximations known to be good to several significant figures can be computed using the following **approximation formulae**:

and

For details, see Choi and Wette (1969).

### Bayesian minimum mean-squared error

With known *k* and unknown , the posterior PDF for theta (using the standard scale-invariant prior for ) is

Denoting

Integration over θ can be carried out using a change of variables, revealing that 1/θ is gamma-distributed with parameters .

The moments can be computed by taking the ratio (*m* by *m* = 0)

which shows that the mean +/- standard deviation estimate of the posterior distribution for theta is

- +/-

## Generating gamma-distributed random variables

Given the scaling property above, it is enough to generate gamma variables with *β* = 1 as we can later convert to any value of *β* with simple division.

Using the fact that a Γ(1, 1) distribution is the same as an Exp(1) distribution, and noting the method of generating exponential variables,
we conclude that if *U* is uniformly distributed on (0, 1],
then −ln(*U*) is distributed Γ(1, 1).
Now, using the "α-addition" property of gamma distribution, we expand this result:

where *U _{k}* are all uniformly distributed on (0, 1] and independent.

All that is left now is to generate a variable distributed as Γ(δ, 1) for 0 < δ < 1 and apply the "α-addition" property once more. This is the most difficult part.

We provide an algorithm without proof. It is an instance of the acceptance-rejection method:

- Let
*m*be 1. - Generate , and — independent uniformly distributed on (0, 1] variables.
- If , where , then go to step 4, else go to step 5.
- Let . Go to step 6.
- Let .
- If , then increment
*m*and go to step 2. - Assume to be the realization of

Now, to summarize,

where
[*k*] is the integral part of *k*, and *ξ* has been generated using the algorithm above with δ = {*k*} (the fractional part of *k*),
*U _{k}* and

*V*are distributed as explained above and are all independent.

_{l}The GNU Scientific Library (which has ports for Visual Studio) has robust routines for sampling many distributions including the Gamma distribution.

## Related distributions

### Specializations

- If , then
*X*has an exponential distribution with rate parameter λ. - If , then
*X*is identical to χ^{2}(*ν*), the chi-square distribution with*ν*degrees of freedom. - If is an integer, the gamma distribution is an Erlang distribution and is the probability distribution of the waiting time until the -th "arrival" in a one-dimensional Poisson process with intensity 1/θ.
- If , then
*X*has a Maxwell-Boltzmann distribution with parameter*a*. - , then

### Others

- If
*X*has a Γ(*k*, θ) distribution, then 1/*X*has an inverse-gamma distribution with parameters*k*and θ^{-1}. - If
*X*and*Y*are independently distributed Γ(α, θ) and Γ(β, θ) respectively, then*X*/ (*X*+*Y*) has a beta distribution with parameters α and β. - If
*X*are independently distributed Γ(α_{i}_{i},θ) respectively, then the vector (*X*_{1}/*S*, ...,*X*/_{n}*S*), where*S*=*X*_{1}+ ... +*X*, follows a Dirichlet distribution with parameters α_{n}_{1}, ..., α_{n}.

## References

- R. V. Hogg and A. T. Craig.
*Introduction to Mathematical Statistics*, 4th edition. New York: Macmillan, 1978.*(See Section 3.3.)* - Weisstein, Eric W., "Gamma distribution" from MathWorld.
- Engineering Statistics Handbook
- S. C. Choi and R. Wette. (1969)
*Maximum Likelihood Estimation of the Parameters of the Gamma Distribution and Their Bias*,**Technometrics**,**11**(4) 683-69