Gamma distribution


In probability theory and statistics,[] the gamma distribution is a versatile two-parameter family of continuous probability distributions. The exponential distribution, Erlang distribution, and chi-squared distribution are special cases of the gamma distribution. There are two equivalent parameterizations in common use:
  1. With a shape parameter and a scale parameter
  2. With a shape parameter and a rate parameter
In each of these forms, both parameters are positive real numbers.
The distribution has important applications in various fields, including econometrics, Bayesian statistics, and life testing. In econometrics, the parameterization is common for modeling waiting times, such as the time until death, where it often takes the form of an Erlang distribution for integer α values. Bayesian statisticians prefer the parameterization, utilizing the gamma distribution as a conjugate prior for several inverse scale parameters, facilitating analytical tractability in posterior distribution computations.
The gamma distribution is the maximum entropy probability distribution for a random variable for which is fixed and greater than zero, and is fixed.

Definitions

The parameterization with and appears to be more common in econometrics and other applied fields, where the gamma distribution is frequently used to model waiting times. For instance, in life testing, the waiting time until death is a random variable that is frequently modeled with a gamma distribution. See Hogg and Craig for an explicit motivation.
The parameterization with and is more common in Bayesian statistics, where the gamma distribution is used as a conjugate prior distribution for various types of inverse scale parameters, such as the of an exponential distribution or a Poisson distribution – or for that matter, the of the gamma distribution itself. The closely related inverse-gamma distribution is used as a conjugate prior for scale parameters, such as the variance of a normal distribution.
If is a positive integer, then the distribution represents an Erlang distribution; i.e., the sum of independent exponentially distributed random variables, each of which has a mean of.

Characterization using shape ''α'' and rate ''λ''

The gamma distribution can be parameterized in terms of a shape parameter and an inverse scale parameter, called a rate parameter. A random variable that is gamma-distributed with shape and rate is denoted
The corresponding probability density function in the shape-rate parameterization is
where is the gamma function.
For all positive integers,.
The cumulative distribution function is the regularized gamma function:
where is the lower incomplete gamma function.
If is a positive integer, the cumulative distribution function has the following series expansion:

Characterization using shape ''α'' and scale ''θ''

A random variable that is gamma-distributed with shape and scale is denoted by
Image:Gamma-PDF-3D.png|thumb|right|320px|Illustration of the gamma PDF for parameter values over and with set to and . One can see each layer by itself here as well as by and . .
The probability density function using the shape-scale parametrization is
Here is the gamma function evaluated at.
The cumulative distribution function is the regularized gamma function:
where is the lower incomplete gamma function.
It can also be expressed as follows, if is a positive integer :
Both parametrizations are common because either can be more convenient depending on the situation.

Properties

Mean and variance

The mean of gamma distribution is given by the product of its shape and scale parameters:
The variance is:
The square root of the inverse shape parameter gives the coefficient of variation:

Skewness

The skewness of the gamma distribution only depends on its shape parameter,, and it is equal to

Higher moments

The -th raw moment is given by:
with the rising factorial.

Median approximations and bounds

Unlike the mode and the mean, which have readily calculable formulas based on the parameters, the median does not have a closed-form equation. The median for this distribution is the value such that
A rigorous treatment of the problem of determining an asymptotic expansion and bounds for the median of the gamma distribution was handled first by Chen and Rubin, who proved that
where is the mean and is the median of the distribution. For other values of the scale parameter, the mean scales to, and the median bounds and approximations would be similarly scaled by.
K. P. Choi found the first five terms in a Laurent series asymptotic approximation of the median by comparing the median to Ramanujan's function. Berg and Pedersen found more terms:
Partial sums of these series are good approximations for high enough ; they are not plotted in the figure, which is focused on the low- region that is less well approximated.
Berg and Pedersen also proved many properties of the median, showing that it is a convex function of, and that the asymptotic behavior near is, and that for all the median is bounded by.
A closer linear upper bound, for only, was provided in 2021 by Gaunt and Merkle, relying on the Berg and Pedersen result that the slope of is everywhere less than 1:
for
which can be extended to a bound for all by taking the max with the chord shown in the figure, since the median was proved convex.
An approximation to the median that is asymptotically accurate at high and reasonable down to or a bit lower follows from the Wilson–Hilferty transformation:
which goes negative for.
In 2021, Lyon proposed several approximations of the form. He conjectured values of and for which this approximation is an asymptotically tight upper or lower bound for all. In particular, he proposed these closed-form bounds, which he proved in 2023:
is a lower bound, asymptotically tight as
is an upper bound, asymptotically tight as
Lyon also showed two other lower bounds that are not closed-form expressions, including this one involving the gamma function, based on solving the integral expression substituting 1 for :

and the tangent line at where the derivative was found to be :

where Ei is the exponential integral.
Additionally, he showed that interpolations between bounds could provide excellent approximations or tighter bounds to the median, including an approximation that is exact at and has a maximum relative error less than 0.6%. Interpolated approximations and bounds are all of the form
where is an interpolating function running monotonially from 0 at low to 1 at high, approximating an ideal, or exact, interpolator :
For the simplest interpolating function considered, a first-order rational function
the tightest lower bound has
and the tightest upper bound has
The interpolated bounds are plotted in the log–log plot shown. Even tighter bounds are available using different interpolating functions, but not usually with closed-form parameters like these.

Summation

If has a distribution for, then
provided all are independent.
For the cases where the are independent but have different scale parameters, see Mathai or Moschopoulos.
The gamma distribution exhibits infinite divisibility.

Scaling

If
then, for any,
by moment generating functions,
or equivalently, if

Indeed, we know that if is an exponential r.v. with rate, then is an exponential r.v. with rate ; the same thing is valid with Gamma variates : multiplication by a positive constant divides the rate.

Exponential family

The gamma distribution is a two-parameter exponential family with natural parameters and, and natural statistics and.
If the shape parameter is held fixed, the resulting one-parameter family of distributions is a natural exponential family.

Logarithmic expectation and variance

One can show that
or equivalently,
where is the digamma function. Likewise,
where is the trigamma function.
This can be derived using the exponential family formula for the moment generating function of the sufficient statistic, because one of the sufficient statistics of the gamma distribution is.

Information entropy

The information entropy is
In the, parameterization, the information entropy is given by

Kullback–Leibler divergence

[Image:Gamma-KL-3D.png|thumb|right|320px|Illustration of the Kullback–Leibler (KL) divergence for two gamma PDFs. Here which are set to and . The typical asymmetry for the KL divergence is clearly visible.]
The Kullback–Leibler divergence, of from is given by
Written using the, parameterization, the KL-divergence of from is given by

Laplace transform

The Laplace transform of the gamma PDF, which is the moment-generating function of the gamma distribution, is
.

Related distributions

General

Compound gamma

If the shape parameter of the gamma distribution is known, but the inverse-scale parameter is unknown, then a gamma distribution for the inverse scale forms a conjugate prior. The compound distribution, which results from integrating out the inverse scale, has a closed-form solution known as the compound gamma distribution.
If, instead, the shape parameter is known but the mean is unknown, with the prior of the mean being given by another gamma distribution, then it results in K-distribution.

Statistical inference

Parameter estimation

Maximum likelihood estimation

The likelihood function for 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 estimator of the parameter, which equals the sample mean divided by the shape parameter :
Substituting this into the log-likelihood function gives
We need at least two samples:, because for, the function increases without bounds as. For, it can be verified that is strictly concave, by using inequality properties of the polygamma function. Finding the maximum with respect to by taking the derivative and setting it equal to zero yields
where is the digamma function and is the sample mean of. There is no closed-form solution for. 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 can be found either using the method of moments, or using the approximation
If we let
then is approximately
which is within 1.5% of the correct value. An explicit form for the Newton–Raphson update of this initial guess is:
At the maximum-likelihood estimate, the expected values for and agree with the empirical averages:
Caveat for small shape parameter
For data,, that is represented in a floating point format that underflows to 0 for values smaller than, the logarithms that are needed for the maximum-likelihood estimate will cause failure if there are any underflows. If we assume the data was generated by a gamma distribution with cdf, then the probability that there is at least one underflow is:
This probability will approach 1 for small and large. For example, at, and,. A workaround is to instead have the data in logarithmic format.
In order to test an implementation of a maximum-likelihood estimator that takes logarithmic data as input, it is useful to be able to generate non-underflowing logarithms of random gamma variates, when. Following the implementation in scipy.stats.loggamma, this can be done as follows: sample and independently. Then the required logarithmic sample is, so that.

Closed-form estimators

There exist consistent closed-form estimators of and that are derived from the likelihood of the generalized gamma distribution.
The estimate for the shape is
and the estimate for the scale is
Using the sample mean of, the sample mean of, and the sample mean of the product simplifies the expressions to:
If the rate parameterization is used, the estimate of.
These estimators are not strictly maximum likelihood estimators, but are instead referred to as mixed type log-moment estimators. They have however similar efficiency as the maximum likelihood estimators.
Although these estimators are consistent, they have a small bias. A bias-corrected variant of the estimator for the scale is
A bias correction for the shape parameter is given as

Bayesian minimum mean squared error

With known and unknown, the posterior density function for theta is
Denoting
where the constant does not depend on. The form of the posterior density reveals that is gamma-distributed with shape parameter and rate parameter. Integration with respect to can be carried out using a change of variables to find the integration constant
The moments can be computed by taking the ratio
which shows that the mean ± standard deviation estimate of the posterior distribution for is

Bayesian inference

Conjugate prior

In Bayesian inference, the gamma distribution is the conjugate prior to many likelihood distributions: the Poisson, exponential, normal, Pareto, gamma with known shape, inverse gamma with known shape parameter, and Gompertz with known scale parameter.
The gamma distribution's conjugate prior is:
where is the normalizing constant with no closed-form solution.
The posterior distribution can be found by updating the parameters as follows:
where is the number of observations, and is the -th observation from the gamma distribution.

Occurrence and applications

Consider a sequence of events, with the waiting time for each event being an exponential distribution with rate. Then the waiting time for the -th event to occur is the gamma distribution with integer shape. This construction of the gamma distribution allows it to model a wide variety of phenomena where several sub-events, each taking time with exponential distribution, must happen in sequence for a major event to occur. Examples include the waiting time of cell-division events, number of compensatory mutations for a given mutation, waiting time until a repair is necessary for a hydraulic system, and so on.
In biophysics, the dwell time between steps of a molecular motor like ATP synthase is nearly exponential at constant ATP concentration, revealing that each step of the motor takes a single ATP hydrolysis. If there were n ATP hydrolysis events, then it would be a gamma distribution with degree n.
The gamma distribution has been used to model the size of insurance claims and rainfalls. This means that aggregate insurance claims and the amount of rainfall accumulated in a reservoir are modelled by a gamma process – much like the exponential distribution generates a Poisson process.
The gamma distribution is also used to model errors in multi-level Poisson regression models because a mixture of Poisson distributions with gamma-distributed rates has a known closed form distribution, called negative binomial.
In wireless communication, the gamma distribution is used to model the multi-path fading of signal power; see also Rayleigh distribution and Rician distribution.
In oncology, the age distribution of cancer incidence often follows the gamma distribution, wherein the shape and scale parameters predict, respectively, the number of driver events and the time interval between them.
In neuroscience, the gamma distribution is often used to describe the distribution of inter-spike intervals.
In bacterial gene expression where protein production can occur in bursts, the copy number of a given protein often follows the gamma distribution, where the shape and scale parameters are, respectively, the mean number of bursts per cell cycle and the mean number of protein molecules produced per burst.
In genomics, the gamma distribution was applied in peak calling step in ChIP-chip and ChIP-seq data analysis.
In Bayesian statistics, the gamma distribution is widely used as a conjugate prior. It is the conjugate prior for the precision of a normal distribution. It is also the conjugate prior for the exponential distribution.
In phylogenetics, the gamma distribution is the most commonly used approach to model among-sites rate variation when maximum likelihood, Bayesian, or distance matrix methods are used to estimate phylogenetic trees. Phylogenetic analyzes that use the gamma distribution to model rate variation estimate a single parameter from the data because they limit consideration to distributions where. This parameterization means that the mean of this distribution is 1 and the variance is. Maximum likelihood and Bayesian methods typically use a discrete approximation to the continuous gamma distribution.

Random variate generation

Given the scaling property above, it is enough to generate gamma variables with, as we can later convert to any value of with a simple division.
Suppose we wish to generate random variables from, where n is a non-negative integer and. Using the fact that a distribution is the same as an distribution, and noting the method of generating exponential variables, we conclude that if is uniformly distributed on. Now, using the "-addition" property of gamma distribution, we expand this result:
where are all uniformly distributed on, or transformation method when. Also see Cheng and Feast Algorithm GKM 3 or Marsaglia's squeeze method.
The following is a version of the Ahrens-Dieter acceptance–rejection method:
  1. Generate, and as iid uniform and the are all independent.
While the above approach is technically correct, Devroye notes that it is linear in the value of and generally is not a good choice. Instead, he recommends using either rejection-based or table-based methods, depending on context.
For example, Marsaglia's simple transformation-rejection method relying on one normal variate and one uniform variate :
  1. Set and.
  2. Set.
  3. If and return, else go back to step 2.
With generates a gamma distributed random number in time that is approximately constant with. The acceptance rate does depend on, with an acceptance rate of 0.95, 0.98, and 0.99 for α = 1, 2, and 4. For, one can use to boost to be usable with this method.
In Matlab numbers can be generated using the function gamrnd, which uses the α, θ representation.