Gamma | |||||||
Type: | density | ||||||
Parameters: | |||||||
Support: | x\in(0,infty) | ||||||
Pdf: |
xke-x/\theta | ||||||
Cdf: |
\gamma\left(k,
\right) | ||||||
Mean: | k\theta | ||||||
Median: | No simple closed form | ||||||
Mode: | (k-1)\thetafork\geq1 0fork<1 | ||||||
Variance: | k\theta2 | ||||||
Skewness: |
| ||||||
Kurtosis: |
| ||||||
Entropy: | \begin{align} k&+ln\theta+ln\Gamma(k)\\ &+(1-k)\psi(k) \end{align} | ||||||
Mgf: | (1-\thetat)-kfort<
| ||||||
Char: | (1-\thetait)-k | ||||||
Support2: | x\in(0,infty) | ||||||
Pdf2: |
x\alphae-\beta | ||||||
Cdf2: |
\gamma(\alpha,\betax) | ||||||
Mean2: |
| ||||||
Median2: | No simple closed form | ||||||
Mode2: |
for\alpha\geq1,0for\alpha<1 | ||||||
Variance2: |
| ||||||
Skewness2: |
| ||||||
Kurtosis2: |
| ||||||
Entropy2: | \begin{align} \alpha&-ln\beta+ln\Gamma(\alpha)\\ &+(1-\alpha)\psi(\alpha) \end{align} | ||||||
Mgf2: | \left(1-
\right)-\alphafort<\beta | ||||||
Char2: | \left(1-
\right)-\alpha | ||||||
Moments: | k=
\theta=
| ||||||
Moments2: | \alpha=
\beta=
| ||||||
Fisher: | I(k,\theta)=\begin{pmatrix}\psi(1)(k)&\theta-1\ \theta-1&k\theta-2\end{pmatrix} | ||||||
Fisher2: | I(\alpha,\beta)=\begin{pmatrix}\psi(1)(\alpha)&-\beta-1\ -\beta-1&\alpha\beta-2\end{pmatrix} |
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:
\alpha=k
The distribution has important applications in various fields, including econometrics, Bayesian statistics, life testing. In econometrics, the (k, θ) 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 k values. Bayesian statistics prefer the (α, β) parameterization, utilizing the gamma distribution as a conjugate prior for several inverse scale parameters, facilitating analytical tractability in posterior distribution computations. The probability density and cumulative distribution functions of the gamma distribution vary based on the chosen parameterization, both offering insights into the behavior of gamma-distributed random variables. The gamma distribution is integral to modeling a range of phenomena due to its flexible shape, which can capture various statistical distributions, including the exponential and chi-squared distributions under specific conditions. Its mathematical properties, such as mean, variance, skewness, and higher moments, provide a toolset for statistical analysis and inference. Practical applications of the distribution span several disciplines, underscoring its importance in theoretical and applied statistics.
The gamma distribution is the maximum entropy probability distribution (both with respect to a uniform base measure and a
1/x
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[2] 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 (rate) parameters, such as the of an exponential distribution or a Poisson distribution[3] – 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 .
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
X\sim\Gamma(\alpha,\beta)\equiv\operatorname{Gamma}(\alpha,\beta)
The corresponding probability density function in the shape-rate parameterization is
\begin{align} f(x;\alpha,\beta)&=
x\alpha-1e-\beta\beta\alpha | |
\Gamma(\alpha) |
forx>0 \alpha,\beta>0,\\[6pt] \end{align}
where
\Gamma(\alpha)
\Gamma(\alpha)=(\alpha-1)!
The cumulative distribution function is the regularized gamma function:
F(x;\alpha,\beta)=
x | |
\int | |
0 |
f(u;\alpha,\beta)du=
\gamma(\alpha,\betax) | |
\Gamma(\alpha) |
,
where
\gamma(\alpha,\betax)
If is a positive integer (i.e., the distribution is an Erlang distribution), the cumulative distribution function has the following series expansion:
F(x;\alpha,\beta)=
\alpha-1 | |
1-\sum | |
i=0 |
(\betax)i | |
i! |
e-\beta=e-\beta
infty | |
\sum | |
i=\alpha |
(\betax)i | |
i! |
.
A random variable that is gamma-distributed with shape and scale is denoted by
X\sim\Gamma(k,\theta)\equiv\operatorname{Gamma}(k,\theta)
The probability density function using the shape-scale parametrization is
f(x;k,\theta)=
xk-1e-x/\theta | |
\thetak\Gamma(k) |
forx>0andk,\theta>0.
Here is the gamma function evaluated at .
The cumulative distribution function is the regularized gamma function:
F(x;k,\theta)=
x | |
\int | |
0 |
f(u;k,\theta)du=
| ||||||
\Gamma(k) |
,
where
\gamma\left(k,
x | |
\theta |
\right)
It can also be expressed as follows, if is a positive integer (i.e., the distribution is an Erlang distribution):[4]
F(x;k,\theta)=
k-1 | |
1-\sum | |
i=0 |
1 | \left( | |
i! |
x | |
\theta |
\right)ie-x/\theta=e-x/\theta
infty | |
\sum | |
i=k |
1 | |
i! |
\left(
x | |
\theta |
\right)i.
Both parametrizations are common because either can be more convenient depending on the situation.
The mean of gamma distribution is given by the product of its shape and scale parameters:
\mu=k\theta=\alpha/\beta
\sigma2=k\theta2=\alpha/\beta2
\sigma/\mu=k-0.5=1/\sqrt{\alpha}
The skewness of the gamma distribution only depends on its shape parameter,, and it is equal to
2/\sqrt{k}.
The -th raw moment is given by:
E[Xn]=\thetan
\Gamma(k+n) | |
\Gamma(k) |
=\thetan
n(k+i-1) | |
\prod | |
i=1 |
forn=1,2,\ldots.
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
1 | |
\Gamma(k)\thetak |
\nu | |
\int | |
0 |
xke-x/\thetadx=
1 | |
2 |
.
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 (for
\theta=1
k-
1 | |
3 |
<\nu(k)<k,
\mu(k)=k
\nu(k)
Gamma(k,1)
\mu=k\theta
K. P. Choi found the first five terms in a Laurent series asymptotic approximation of the median by comparing the median to Ramanujan's \theta
\nu(k)=k-
1 | |
3 |
+
8 | |
405k |
+
184 | |
25515k2 |
+
2248 | |
3444525k3 |
-
19006408 | |
15345358875k4 |
-O\left(
1 | |
k5 |
\right)+ …
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,[8] and that the asymptotic behavior near
k=0
\nu(k) ≈ e-\gamma2-1/k
k>0
k2-1/k<\nu(k)<ke-1/3k
A closer linear upper bound, for
k\ge1
\nu(k)
\nu(k)\lek-1+log2~~
k\ge1
k=1
k>0
An approximation to the median that is asymptotically accurate at high and reasonable down to
k=0.5
\nu(k)=k\left(1-
1 | |
9k |
\right)3
k<1/9
In 2021, Lyon proposed several approximations of the form
\nu(k) ≈ 2-1/k(A+Bk)
k>0
\nuLinfty(k)=2-1/k(log2-
1 | |
3 |
+k)
k\toinfty
\nuU(k)=2-1/k(e-\gamma+k)
k\to0
Lyon also showed (informally in 2021, rigorously in 2023) 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
e-x
\nu(k)>\left(
2 | |
\Gamma(k+1) |
\right)-1/k
k\to0
k=1
\nu\prime(1) ≈ 0.9680448
\nu(k)\ge\nu(1)+(k-1)\nu\prime(1)
k=1
\nu(k)\gelog2+(k-1)(\gamma-2\operatorname{Ei}(-log2)-loglog2)
Additionally, he showed that interpolations between bounds could provide excellent approximations or tighter bounds to the median, including an approximation that is exact at
k=1
\nu(1)=log2
\nu(k) ≈ \tilde{g}(k)\nuLinfty(k)+(1-\tilde{g}(k))\nuU(k)
\tilde{g}
g(k)
g(k)=
\nuU(k)-\nu(k) | |
\nuU(k)-\nuLinfty(k) |
\tilde{g}1(k)=
k | |
b0+k |
b0=
| |||||||||
|
-log2 ≈ 0.143472
b0=
| ||||||||||
|
≈ 0.374654
If has a distribution for (i.e., all distributions have the same scale parameter), then
N | |
\sum | |
i=1 |
Xi\simGamma\left(
N | |
\sum | |
i=1 |
ki,\theta\right)
provided all are independent.
For the cases where the are independent but have different scale parameters, see Mathai [12] or Moschopoulos.[13]
The gamma distribution exhibits infinite divisibility.
If
X\simGamma(k,\theta),
then, for any,
cX\simGamma(k,c\theta),
or equivalently, if
X\simGamma\left(\alpha,\beta\right)
cX\simGamma\left(\alpha,
\beta | |
c |
\right),
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 (and this can be checked using the moment-generating function, see, e.g.,these notes, 10.4-(ii)): multiplication by a positive constant divides the rate (or, equivalently, multiplies the scale).
The gamma distribution is a two-parameter exponential family with natural parameters and (equivalently, and), and natural statistics and .
If the shape parameter is held fixed, the resulting one-parameter family of distributions is a natural exponential family.
One can show that
\operatorname{E}[lnX]=\psi(\alpha)-ln\beta
or equivalently,
\operatorname{E}[lnX]=\psi(k)+ln\theta
where is the digamma function. Likewise,
\operatorname{var}[lnX]=\psi(1)(\alpha)=\psi(1)(k)
where
\psi(1)
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 .
The information entropy is
\begin{align} \operatorname{H}(X)&=\operatorname{E}[-lnp(X)]\\[4pt] &=\operatorname{E}[-\alphaln\beta+ln\Gamma(\alpha)-(\alpha-1)lnX+\betaX]\\[4pt] &=\alpha-ln\beta+ln\Gamma(\alpha)+(1-\alpha)\psi(\alpha). \end{align}
In the, parameterization, the information entropy is given by
\operatorname{H}(X)=k+ln\theta+ln\Gamma(k)+(1-k)\psi(k).
The Kullback–Leibler divergence (KL-divergence), of ("true" distribution) from ("approximating" distribution) is given by[14]
\begin{align} DKL(\alphap,\betap;\alphaq,\betaq)={}&(\alphap-\alphaq)\psi(\alphap)-log\Gamma(\alphap)+log\Gamma(\alphaq)\\ &{}+\alphaq(log\betap-log\betaq)+
\alpha | ||||
|
. \end{align}
Written using the, parameterization, the KL-divergence of from is given by
\begin{align} DKL(kp,\thetap;kq,\thetaq)={}&(kp-kq)\psi(kp)-log\Gamma(kp)+log\Gamma(kq)\\ &{}+kq(log\thetaq-log\thetap)+kp
\thetap-\thetaq | |
\thetaq |
. \end{align}
The Laplace transform of the gamma PDF is
F(s)=(1+\thetas)-k=
\beta\alpha | |
(s+\beta)\alpha |
.
X1,X2,\ldots,Xn
n
\sumiXi
X\sim\Gamma(k\inZ,\theta), Y\sim\operatorname{Pois}\left(
x | |
\theta |
\right),
then
P(X>x)=P(Y<k).
X2\sim\Gamma\left(
3 | |
2 |
,2a2\right).
\sqrt{X}
a=\sqrt{\theta}
Xq
q>0
a=\thetaq
Xk\sim\Gamma(\alphak,\thetak)
\alpha2\theta2X1 | |
\alpha1\theta1X2 |
\simF(2\alpha1,2\alpha2)
X1 | |
X2 |
\sim\beta'\left(\alpha1,\alpha2,1,
\theta1 | |
\theta2 |
\right)
Xk\sim\Gamma(\alphak,\betak)
\alpha2\beta1X1 | |
\alpha1\beta2X2 |
\simF(2\alpha1,2\alpha2)
X1 | |
X2 |
\sim\beta'\left(\alpha1,\alpha2,1,
\beta2 | |
\beta1 |
\right)
f(x\mid\alpha,\beta,\gamma)=
| ||||||||||
|
\right)}}
\Psi(\alpha,z)={}1\Psi
|
\right)\\(1,0)\end{matrix};z\right)
x|\theta\sim\Gamma(k,\theta)
\theta\simIG(b,1)
IG
x\sim\beta'(k,b)
\beta'
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.[18]
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.
The gamma distribution
f(x;k)(k>1)
k
ak{N}\alpha(\nu)
\alpha=1/k
Wk(x)
k
The likelihood function for iid observations is
L(k,\theta)=
N | |
\prod | |
i=1 |
f(xi;k,\theta)
from which we calculate the log-likelihood function
\ell(k,\theta)=(k-1)
N | |
\sum | |
i=1 |
lnxi-
N | |
\sum | |
i=1 |
xi | |
\theta |
-Nkln\theta-Nln\Gamma(k)
\bar{x}
\hat{\theta}=
1 | |
kN |
N | |
\sum | |
i=1 |
xi=
\bar{x | |
Substituting this into the log-likelihood function gives
\ell(k)=
N | |
(k-1)\sum | |
i=1 |
lnxi-Nk-Nkln\left(
\sumxi | |
kN |
\right)-Nln\Gamma(k)
We need at least two samples:
N\ge2
N=1
\ell(k)
k\toinfty
k>0
\ell(k)
lnk-\psi(k)=ln\left(
1 | |
N |
N | |
\sum | |
i=1 |
xi\right)-
1 | |
N |
N | |
\sum | |
i=1 |
lnxi=ln\bar{x}-\overline{lnx}
where is the digamma function and
\overline{lnx}
lnk-\psi(k) ≈
1 | |
2k |
\left(1+
1 | |
6k+1 |
\right)
If we let
s=ln\left(
1 | |
N |
N | |
\sum | |
i=1 |
xi\right)-
1 | |
N |
N | |
\sum | |
i=1 |
lnxi=ln\bar{x}-\overline{lnx}
then is approximately
k ≈
3-s+\sqrt{(s-3)2+24s | |
which is within 1.5% of the correct value.[19] An explicit form for the Newton–Raphson update of this initial guess is:[20]
k\leftarrowk-
lnk-\psi(k)-s | |||||
|
.
At the maximum-likelihood estimate
(\hatk,\hat\theta)
lnx
\begin{align} \hatk\hat\theta&=\barx&&and& \psi(\hatk)+ln\hat\theta&=\overline{lnx}. \end{align}
For data,
(x1,\ldots,xN)
\varepsilon
F(x;k,\theta)
P(underflow)=1-(1-F(\varepsilon;k,\theta))N
k=10-2
N=104
\varepsilon=2.25 x 10-308
P(underflow) ≈ 0.9998
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
k<1
scipy.stats.loggamma
, this can be done as follows: sample Y\simGamma(k+1,\theta)
U\simUniform
Z=ln(Y)+ln(U)/k
\exp(Z)\simGamma(k,\theta)
There exist consistent closed-form estimators of and that are derived from the likelihood of the generalized gamma distribution.[21]
The estimate for the shape is
\hat{k}=
| ||||||||||||||||||||
|
and the estimate for the scale is
\hat{\theta}=
1 | |
N2 |
\left(N
N | |
\sum | |
i=1 |
xilnxi-
N | |
\sum | |
i=1 |
xi
N | |
\sum | |
i=1 |
lnxi\right)
Using the sample mean of, the sample mean of, and the sample mean of the product simplifies the expressions to:
\hat{k}=\bar{x}/\hat{\theta}
\hat{\theta}=\overline{xln{x}}-\bar{x}\overline{ln{x}}.
If the rate parameterization is used, the estimate of
\hat{\beta}=1/\hat{\theta}
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
\tilde{\theta}=
N | |
N-1 |
\hat{\theta}
A bias correction for the shape parameter is given as[22]
\tilde{k}=\hat{k}-
1 | |
N |
\left(3\hat{k}-
2 | \left( | |
3 |
\hat{k | |
With known and unknown, the posterior density function for theta (using the standard scale-invariant prior for) is
P(\theta\midk,x1,...,xN)\propto
1 | |
\theta |
N | |
\prod | |
i=1 |
f(xi;k,\theta)
Denoting
y\equiv
Nx | |
\sum | |
i |
, P(\theta\midk,x1,...,xN)=C(xi)\theta-Ne-y/\theta
Integration with respect to can be carried out using a change of variables, revealing that is gamma-distributed with parameters, .
infty | |
\int | |
0 |
\theta-Nke-y/\thetad\theta=
infty | |
\int | |
0 |
xNke-xydx=y-(Nk\Gamma(Nk-m)
The moments can be computed by taking the ratio (by)
\operatorname{E}[xm]=
\Gamma(Nk-m) | |
\Gamma(Nk) |
ym
which shows that the mean ± standard deviation estimate of the posterior distribution for is
y | |
Nk-1 |
\pm\sqrt{
y2 | |
(Nk-1)2(Nk-2) |
In Bayesian inference, the gamma distribution is the conjugate prior to many likelihood distributions: the Poisson, exponential, normal (with known mean), Pareto, gamma with known shape, inverse gamma with known shape parameter, and Gompertz with known scale parameter.
The gamma distribution's conjugate prior is:[23]
p(k,\theta\midp,q,r,s)=
1 | |
Z |
| |||||||||||
\Gamma(k)r\thetak |
,
where is the normalizing constant with no closed-form solution.The posterior distribution can be found by updating the parameters as follows:
\begin{align} p'&=p\prod\nolimitsixi,\\ q'&=q+\sum\nolimitsixi,\\ r'&=r+n,\\ s'&=s+n, \end{align}
where is the number of observations, and is the -th observation.
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
\alpha=n
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.[28]
The gamma distribution has been used to model the size of insurance claims[29] and rainfalls.[30] 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.[31] [32]
In neuroscience, the gamma distribution is often used to describe the distribution of inter-spike intervals.[33] [34]
In bacterial gene expression, the copy number of a constitutively expressed protein often follows the gamma distribution, where the scale and shape parameter are, respectively, the mean number of bursts per cell cycle and the mean number of protein molecules produced by a single mRNA during its lifetime.[35]
In genomics, the gamma distribution was applied in peak calling step (i.e., in recognition of signal) in ChIP-chip[36] and ChIP-seq[37] data analysis.
In Bayesian statistics, the gamma distribution is widely used as a conjugate prior. It is the conjugate prior for the precision (i.e. inverse of the variance) 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[38] 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.[39] [40]
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 (0, 1], then is distributed (i.e. inverse transform sampling). Now, using the "-addition" property of gamma distribution, we expand this result:
n | |
-\sum | |
k=1 |
lnUk\sim\Gamma(n,1)
where are all uniformly distributed on (0, 1] and independent. All that is left now is to generate a variable distributed as for and apply the "-addition" property once more. This is the most difficult part.
Random generation of gamma variates is discussed in detail by Devroye,[41] noting that none are uniformly fast for all shape parameters. For small values of the shape parameter, the algorithms are often not valid. For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter[42] modified acceptance-rejection method Algorithm GD (shape), or transformation method[43] when . Also see Cheng and Feast Algorithm GKM 3[44] or Marsaglia's squeeze method.[45]
The following is a version of the Ahrens-Dieter acceptance–rejection method:[42]
U\le | e |
e+\delta |
\xi=V1/\delta
η=W\xi\delta-1
\xi=1-lnV
η=We-\xi
η>\xi\delta-1e-\xi
A summary of this is
\theta\left(\xi-
\lfloork\rfloor | |
\sum | |
i=1 |
lnUi\right)\sim\Gamma(k,\theta)
\scriptstyle\lfloork\rfloor
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.[41]
For example, Marsaglia's simple transformation-rejection method relying on one normal variate and one uniform variate :[46]
d=a-
13 | |
c=
1{\sqrt{9d}} | |
v=(1+cX)3
v>0
lnU<
X2 | |
2 |
+d-dv+dlnv
dv
With
1\lea=\alpha=k
\gamma\alpha=\gamma1+\alphaU1/\alpha
In Matlab numbers can be generated using the function gamrnd, which uses the k, θ representation.