gamma distribution
{{Short description|Probability distribution}}
{{Infobox probability distribution 2
| name = Gamma
| type = density
| pdf_image = Image:Gammapdf252.svg
| cdf_image = Image:Gammacdf252.svg
| parameters =
| support =
| pdf =
| cdf =
| mean =
| median = No simple closed form
| mode = ,
| variance =
| skewness =
| kurtosis =
| entropy =
\alpha &+ \ln\theta + \ln\Gamma(\alpha)\\
&+ (1 - \alpha)\psi(\alpha)
\end{align}
| mgf =
| char =
| parameters2 = {{bulleted list
| {{math|α > 0}} shape
| {{math|λ > 0}} rate
}}
| support2 =
| pdf2 =
| cdf2 =
| mean2 =
| median2 = No simple closed form
| mode2 =
| variance2 =
| skewness2 =
| kurtosis2 =
| entropy2 =
\alpha &- \ln \lambda + \ln\Gamma(\alpha)\\
&+ (1 - \alpha)\psi(\alpha)
\end{align}
| mgf2 =
| char2 =
| moments =
| moments2 =
| fisher =
| fisher2 =
}}
In probability theory and statistics, the gamma distribution is a versatile two-parameter family of continuous probability distributions.{{Cite web |title=Gamma distribution {{!}} Probability, Statistics, Distribution {{!}} Britannica |url=https://www.britannica.com/science/gamma-distribution |access-date=2024-10-09 |website=www.britannica.com |language=en |archive-date=2024-05-19 |archive-url=https://web.archive.org/web/20240519084458/https://www.britannica.com/science/gamma-distribution |url-status=live }} The exponential distribution, Erlang distribution, and chi-squared distribution are special cases of the gamma distribution.{{Cite web |last=Weisstein |first=Eric W. |title=Gamma Distribution |url=https://mathworld.wolfram.com/GammaDistribution.html |access-date=2024-10-09 |website=mathworld.wolfram.com |language=en |archive-date=2024-05-28 |archive-url=https://web.archive.org/web/20240528053806/https://mathworld.wolfram.com/GammaDistribution.html |url-status=live }} There are two equivalent parameterizations in common use:
- With a shape parameter {{mvar|α}} and a scale parameter {{mvar|θ}}
- With a shape parameter and a rate parameter {{tmath|1=\lambda = 1/ \theta}}
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.{{Cite web |title=Gamma Distribution {{!}} Gamma Function {{!}} Properties {{!}} PDF |url=https://www.probabilitycourse.com/chapter4/4_2_4_Gamma_distribution.php |access-date=2024-10-09 |website=www.probabilitycourse.com |archive-date=2024-06-13 |archive-url=https://web.archive.org/web/20240613044322/https://www.probabilitycourse.com/chapter4/4_2_4_Gamma_distribution.php |url-status=live }} 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 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.{{Cite web |date=2019-03-11 |title=4.5: Exponential and Gamma Distributions |url=https://stats.libretexts.org/Courses/Saint_Mary's_College_Notre_Dame/MATH_345__-_Probability_(Kuter)/4:_Continuous_Random_Variables/4.5:_Exponential_and_Gamma_Distributions |access-date=2024-10-10 |website=Statistics LibreTexts |language=en}}
The gamma distribution is the maximum entropy probability distribution (both with respect to a uniform base measure and a base measure) for a random variable {{mvar|X}} for which {{math|1=E[X] = αθ = α/λ}} is fixed and greater than zero, and {{math|1=E[ln X] = ψ(α) + ln θ = ψ(α) − ln λ}} is fixed ({{mvar|ψ}} is the digamma function).{{cite journal |last1=Park |first1=Sung Y. |last2=Bera |first2=Anil K. |year=2009 |title=Maximum entropy autoregressive conditional heteroskedasticity model |journal=Journal of Econometrics |volume=150 |issue=2 |pages=219–230 |url=http://www.wise.xmu.edu.cn/Master/Download/..%5C..%5CUploadFiles%5Cpaper-masterdownload%5C2009519932327055475115776.pdf |access-date=2011-06-02 |doi=10.1016/j.jeconom.2008.12.014 |citeseerx=10.1.1.511.9750 |archive-url=https://web.archive.org/web/20160307144515/http://wise.xmu.edu.cn/uploadfiles/paper-masterdownload/2009519932327055475115776.pdf |archive-date=2016-03-07 |url-status=dead }}
Definitions
The parameterization with {{mvar|α}} and {{mvar|θ}} 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{{cite book |author-link=Robert V. Hogg |first1=R. V. |last1=Hogg |first2=A. T. |last2=Craig |year=1978 |title=Introduction to Mathematical Statistics |edition=4th |location=New York |publisher=Macmillan |isbn=0023557109|pages=Remark 3.3.1}} for an explicit motivation.
The parameterization with {{mvar|α}} and {{mvar|λ}} 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 {{mvar|λ}} of an exponential distribution or a Poisson distribution{{Cite arXiv |eprint=1311.1704 |class=cs.IR |first1=Prem |last1=Gopalan |first2=Jake M. |last2=Hofman |title=Scalable Recommendation with Poisson Factorization |last3=Blei |first3=David M. |year=2013 |author3-link=David Blei}} – or for that matter, the {{mvar|λ}} 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 {{mvar|α}} is a positive integer, then the distribution represents an Erlang distribution; i.e., the sum of {{mvar|α}} independent exponentially distributed random variables, each of which has a mean of {{mvar|θ}}.
= Characterization using shape ''α'' and rate ''λ'' =
The gamma distribution can be parameterized in terms of a shape parameter {{math|1=α}} and an inverse scale parameter {{math|1=λ = 1/θ}}, called a rate parameter. A random variable {{mvar|X}} that is gamma-distributed with shape {{mvar|α}} and rate {{mvar|λ}} is denoted
The corresponding probability density function in the shape-rate parameterization is
\begin{align}
f(x;\alpha,\lambda) & = \frac{ x^{\alpha-1} e^{-\lambda x} \lambda^\alpha}{\Gamma(\alpha)} \quad \text{ for } x > 0 \quad \alpha, \lambda > 0, \\[6pt]
\end{align}
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 {{mvar|α}} is a positive integer (i.e., the distribution is an Erlang distribution), the cumulative distribution function has the following series expansion:
= Characterization using shape ''α'' and scale ''θ'' =
A random variable {{mvar|X}} that is gamma-distributed with shape {{mvar|α}} and scale {{mvar|θ}} is denoted by
The probability density function using the shape-scale parametrization is
Here {{math|Γ(α)}} is the gamma function evaluated at {{mvar|α}}.
The cumulative distribution function is the regularized gamma function:
where is the lower incomplete gamma function.
It can also be expressed as follows, if {{mvar|α}} is a positive integer (i.e., the distribution is an Erlang distribution):Papoulis, Pillai, Probability, Random Variables, and Stochastic Processes, Fourth Edition
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, {{mvar|α}}, and it is equal to
= Higher moments =
The {{mvar|n}}-th raw moment is given by:
\mathrm{E}[X^n] = \theta^n \frac{\Gamma(\alpha+n)}{\Gamma(\alpha)} = \theta^n \prod_{i=1}^n(\alpha+i-1) \; \text{ for } n=1, 2, \ldots.
=Median approximations and bounds=
File:Gamma distribution median bounds.png
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 (for )
where is the mean and is the median of the distribution.Jeesen Chen, Herman Rubin, Bounds for the difference between median and mean of gamma and Poisson distributions, Statistics & Probability Letters, Volume 4, Issue 6, October 1986, Pages 281–283, {{issn|0167-7152}}, [https://dx.doi.org/10.1016/0167-7152(86)90044-1] {{Webarchive|url=https://web.archive.org/web/20241009203229/https://www.sciencedirect.com/unsupported_browser|date=2024-10-09}}. For other values of the scale parameter, the mean scales to , and the median bounds and approximations would be similarly scaled by {{mvar|θ}}.
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.Choi, K. P. [https://www.ams.org/journals/proc/1994-121-01/S0002-9939-1994-1195477-8/S0002-9939-1994-1195477-8.pdf "On the Medians of the Gamma Distributions and an Equation of Ramanujan"] {{Webarchive|url=https://web.archive.org/web/20210123121523/https://www.ams.org/journals/proc/1994-121-01/S0002-9939-1994-1195477-8/S0002-9939-1994-1195477-8.pdf |date=2021-01-23 }}, Proceedings of the American Mathematical Society, Vol. 121, No. 1 (May, 1994), pp. 245–251. Berg and Pedersen found more terms:{{cite journal |author=Berg, Christian |author2=Pedersen, Henrik L. |name-list-style=amp |title=The Chen–Rubin conjecture in a continuous setting |journal=Methods and Applications of Analysis |date=March 2006 |volume=13 |issue=1 |pages=63–88 |doi=10.4310/MAA.2006.v13.n1.a4 |s2cid=6704865 |url=https://www.intlpress.com/site/pub/files/_fulltext/journals/maa/2006/0013/0001/MAA-2006-0013-0001-a004.pdf |access-date=1 April 2020 |doi-access=free |archive-date=16 January 2021 |archive-url=https://web.archive.org/web/20210116114105/https://www.intlpress.com/site/pub/files/_fulltext/journals/maa/2006/0013/0001/MAA-2006-0013-0001-a004.pdf |url-status=live }}
File:Gamma distribution median Lyon bounds.png
File:Gamma distribution median loglog bounds.png of upper (solid) and lower (dashed) bounds to the median of a gamma distribution and the gaps between them. The green, yellow, and cyan regions represent the gap before the Lyon 2021 paper. The green and yellow narrow that gap with the lower bounds that Lyon proved. Lyon's bounds proved in 2023 further narrow the yellow. Mostly within the yellow, closed-form rational-function-interpolated conjectured bounds are plotted along with the numerically calculated median (dotted) value. Tighter interpolated bounds exist but are not plotted, as they would not be resolved at this scale.]]
Partial sums of these series are good approximations for high enough {{mvar|α}}; they are not plotted in the figure, which is focused on the low-{{mvar|α}} region that is less well approximated.
Berg and Pedersen also proved many properties of the median, showing that it is a convex function of {{mvar|α}},Berg, Christian and Pedersen, Henrik L. [https://arxiv.org/abs/math/0609442 "Convexity of the median in the gamma distribution"] {{Webarchive|url=https://web.archive.org/web/20230526181721/https://arxiv.org/abs/math/0609442 |date=2023-05-26 }}. and that the asymptotic behavior near is (where {{mvar|γ}} is the Euler–Mascheroni constant), and that for all the median is bounded by .
A closer linear upper bound, for only, was provided in 2021 by Gaunt and Merkle,{{cite journal |last1=Gaunt, Robert E., and Milan Merkle |title=On bounds for the mode and median of the generalized hyperbolic and related distributions |journal=Journal of Mathematical Analysis and Applications |date=2021 |volume=493 |issue=1 |pages=124508|doi=10.1016/j.jmaa.2020.124508 |arxiv=2002.01884 |s2cid=221103640 }} relying on the Berg and Pedersen result that the slope of is everywhere less than 1:
for (with equality at )
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 {{mvar|α}} 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 {{mvar|A}} and {{mvar|B}} for which this approximation is an asymptotically tight upper or lower bound for all .{{cite journal |last1=Lyon |first1=Richard F. |title=On closed-form tight bounds and approximations for the median of a gamma distribution |journal=PLOS One |date=13 May 2021 |volume=16 |issue=5 |pages=e0251626 |doi=10.1371/journal.pone.0251626 |pmid=33984053 |pmc=8118309 |arxiv=2011.04060 |bibcode=2021PLoSO..1651626L |doi-access=free }} In particular, he proposed these closed-form bounds, which he proved in 2023:{{cite journal |last1=Lyon |first1=Richard F. |title=Tight bounds for the median of a gamma distribution |journal=PLOS One |date=13 May 2021 |volume=18 |issue=9 |pages=e0288601 |doi=10.1371/journal.pone.0288601 |pmid=37682854 |pmc=10490949 |doi-access=free }}
is a lower bound, asymptotically tight as
is an upper bound, asymptotically tight as
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 :
(approaching equality as )
and the tangent line at where the derivative was found to be :
(with equality at )
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 (where ) 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 {{mvar|α}} to 1 at high {{mvar|α}}, 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 (mostly inside the yellow region) 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 {{math|Xi}} has a {{math|Gamma(αi, θ)}} distribution for {{math|1=i = 1, 2, ..., N}} (i.e., all distributions have the same scale parameter {{mvar|θ}}), then
provided all {{math|Xi}} are independent.
For the cases where the {{math|Xi}} are independent but have different scale parameters, see Mathai {{Cite journal|last=Mathai|first=A. M.|title=Storage capacity of a dam with gamma type inputs|journal=Annals of the Institute of Statistical Mathematics|language=en|volume=34|issue=3|pages=591–597|doi=10.1007/BF02481056|issn=0020-3157|year=1982|s2cid=122537756}} or Moschopoulos.{{cite journal |first=P. G. |last=Moschopoulos |year=1985 |title=The distribution of the sum of independent gamma random variables |journal=Annals of the Institute of Statistical Mathematics |volume=37 |issue=3 |pages=541–544 |doi=10.1007/BF02481123 |s2cid=120066454 }}
The gamma distribution exhibits infinite divisibility.
=Scaling=
If
then, for any {{math|c > 0}},
by moment generating functions,
or equivalently, if
(shape-rate parameterization)
Indeed, we know that if {{mvar|X}} is an exponential r.v. with rate {{mvar|λ}}, then {{math|cX}} is an exponential r.v. with rate {{math|λ/c}}; the same thing is valid with Gamma variates (and this can be checked using the moment-generating function, see, e.g.,[http://www.stat.washington.edu/thompson/S341_10/Notes/week4.pdf these notes], 10.4-(ii)): multiplication by a positive constant {{mvar|c}} divides the rate (or, equivalently, multiplies the scale).
=Exponential family=
The gamma distribution is a two-parameter exponential family with natural parameters {{math|α − 1}} and {{math|−1/θ}} (equivalently, {{math|α − 1}} and {{math|−λ}}), and natural statistics {{mvar|X}} and {{math|ln X}}.
If the shape parameter {{mvar|α}} 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 {{mvar|ψ}} 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 {{math|ln x}}.
=Information entropy=
The information entropy is
\begin{align}
\operatorname{H}(X) & = \operatorname{E}[-\ln p(X)] \\[4pt]
& = \operatorname{E}[-\alpha \ln \lambda + \ln \Gamma(\alpha) - (\alpha-1)\ln X + \lambda X] \\[4pt]
& = \alpha - \ln \lambda + \ln \Gamma(\alpha) + (1-\alpha)\psi(\alpha).
\end{align}
In the {{mvar|α}}, {{mvar|θ}} parameterization, the information entropy is given by
=Kullback–Leibler divergence=
The Kullback–Leibler divergence (KL-divergence), of {{math|Gamma(αp, λp)}} ("true" distribution) from {{math|Gamma(αq, λq)}} ("approximating" distribution) is given by{{cite web|first=W. D.|last=Penny|url=https://www.fil.ion.ucl.ac.uk/~wpenny/publications/densities.ps|title= KL-Divergences of Normal, Gamma, Dirichlet, and Wishart densities}}
\begin{align}
D_{\mathrm{KL}}(\alpha_p,\lambda_p; \alpha_q, \lambda_q) = {} & (\alpha_p-\alpha_q) \psi(\alpha_p) - \log\Gamma(\alpha_p) + \log\Gamma(\alpha_q) \\
& {} + \alpha_q(\log \lambda_p - \log \lambda_q) + \alpha_p\frac{\lambda_q-\lambda_p}{\lambda_p}.
\end{align}
Written using the {{mvar|α}}, {{mvar|θ}} parameterization, the KL-divergence of {{math|Gamma(αp, θp)}} from {{math|Gamma(αq, θq)}} is given by
\begin{align}
D_{\mathrm{KL}}(\alpha_p,\theta_p; \alpha_q, \theta_q) = {} & (\alpha_p-\alpha_q)\psi(\alpha_p) - \log\Gamma(\alpha_p) + \log\Gamma(\alpha_q) \\
& {} + \alpha_q(\log \theta_q - \log \theta_p) + \alpha_p \frac{\theta_p - \theta_q}{\theta_q}.
\end{align}
=Laplace transform=
The Laplace transform of the gamma PDF, which is the moment-generating function of the gamma distribution, is
(where is a random variable with that distribution).
Related distributions
=General=
- Let be independent and identically distributed random variables following an exponential distribution with rate parameter λ, then where n is the shape parameter and {{mvar|λ}} is the rate, and .
- If {{math|X ~ Gamma(1, λ)}} (in the shape–rate parametrization), then {{mvar|X}} has an exponential distribution with rate parameter {{mvar|λ}}. In the shape-scale parametrization, {{math|X ~ Gamma(1, θ)}} has an exponential distribution with rate parameter {{math|1/θ}}.
- If {{math|X ~ Gamma(ν/2, 2)}} (in the shape–scale parametrization), then {{mvar|X}} is identical to {{math|χ2(ν)}}, the chi-squared distribution with {{mvar|ν}} degrees of freedom. Conversely, if {{math|Q ~ χ2(ν)}} and {{mvar|c}} is a positive constant, then {{math|cQ ~ Gamma(ν/2, 2c)}}.
- If {{math|1=θ = 1/α}}, one obtains the Schulz-Zimm distribution, which is most prominently used to model polymer chain lengths.
- If {{mvar|α}} is an integer, the gamma distribution is an Erlang distribution and is the probability distribution of the waiting time until the {{mvar|α}}-th "arrival" in a one-dimensional Poisson process with intensity {{math|1/θ}}. If
::
:then
::
- If {{mvar|X}} has a Maxwell–Boltzmann distribution with parameter {{mvar|a}}, then
::
=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.{{cite journal|last=Dubey|first=Satya D. | title=Compound gamma, beta and F distributions|journal=Metrika|date=December 1970|volume=16|issue=1 |pages=27–31 |doi=10.1007/BF02613934|s2cid=123366328 }}
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.
=Weibull and stable count=
The gamma distribution can be expressed as the product distribution of a Weibull distribution and a variant form of the stable count distribution.
Its shape parameter can be regarded as the inverse of Lévy's stability parameter in the stable count distribution:
f(x;\alpha) =
\int_0^\infty \frac{1}{u} \, W_k\left(\frac{x}{u}\right)
\left[ k u^{\alpha-1} \, \mathfrak{N}_{\frac{1}{\alpha}}\left(u^\alpha\right) \right] \, du ,
where is a standard stable count distribution of shape , and is a standard Weibull distribution of shape .
Statistical inference
=Parameter estimation=
==Maximum likelihood estimation==
The likelihood function for {{mvar|N}} iid observations {{math|(x1, ..., xN)}} is
from which we calculate the log-likelihood function
Finding the maximum with respect to {{mvar|θ}} by taking the derivative and setting it equal to zero yields the maximum likelihood estimator of the {{mvar|θ}} parameter, which equals the sample mean divided by the shape parameter {{mvar|α}}:
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 {{mvar|α}} by taking the derivative and setting it equal to zero yields
where {{mvar|ψ}} is the digamma function and is the sample mean of {{math|ln x}}. There is no closed-form solution for {{mvar|α}}. 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 {{mvar|k}} can be found either using the method of moments, or using the approximation
If we let
then {{mvar|α}} is approximately
which is within 1.5% of the correct value.{{cite web |last=Minka |first=Thomas P. |year=2002 |title=Estimating a Gamma distribution |url=https://tminka.github.io/papers/minka-gamma.pdf }} An explicit form for the Newton–Raphson update of this initial guess is:{{cite journal |last1=Choi |first1=S. C. |last2=Wette |first2=R. |year=1969 |title=Maximum Likelihood Estimation of the Parameters of the Gamma Distribution and Their Bias |journal=Technometrics |volume=11 |issue=4 |pages=683–690 |doi=10.1080/00401706.1969.10490731 }}
At the maximum-likelihood estimate , the expected values for {{mvar|x}} and agree with the empirical averages:
\begin{align}
\hat \alpha\hat\theta &= \bar x &&\text{and} &
\psi(\hat \alpha)+\ln \hat\theta &= \overline{\ln x}.
\end{align}
===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:
P(\text{underflow}) = 1-(1-F(\varepsilon;\alpha,\theta))^N
This probability will approach 1 for small {{mvar|α}} and large {{mvar|N}}. 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 {{mvar|α}} and {{mvar|θ}} that are derived from the likelihood of the generalized gamma distribution.{{cite journal | url=https://amstat.tandfonline.com/doi/abs/10.1080/00031305.2016.1209129 | doi=10.1080/00031305.2016.1209129 | title=Closed-Form Estimators for the Gamma Distribution Derived from Likelihood Equations | year=2017 | last1=Ye | first1=Zhi-Sheng | last2=Chen | first2=Nan | journal=The American Statistician | volume=71 | issue=2 | pages=177–181 | s2cid=124682698 | access-date=2019-07-27 | archive-date=2023-05-26 | archive-url=https://web.archive.org/web/20230526181723/https://amstat.tandfonline.com/doi/abs/10.1080/00031305.2016.1209129 | url-status=live | url-access=subscription }}
The estimate for the shape {{mvar|α}} is
and the estimate for the scale {{mvar|θ}} is
Using the sample mean of {{mvar|x}}, the sample mean of {{math|ln x}}, and the sample mean of the product {{math|x·ln x}} 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 {{mvar|θ}} is
==Bayesian minimum mean squared error==
With known {{mvar|α}} and unknown {{mvar|θ}}, the posterior density function for theta (using the standard scale-invariant prior for {{mvar|θ}}) is
Denoting
where the {{mvar|C}} (integration) constant does not depend on {{mvar|θ}}. The form of the posterior density reveals that {{math|1 / θ}} is gamma-distributed with shape parameter {{math|Nα + 2}} and rate parameter {{mvar|y}}. Integration with respect to {{mvar|θ}} can be carried out using a change of variables to find the integration constant
The moments can be computed by taking the ratio ({{mvar|m}} by {{math|1=m = 0}})
which shows that the mean ± standard deviation estimate of the posterior distribution for {{mvar|θ}} is
=Bayesian inference=
==Conjugate prior==
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 {{mvar|σ}}, inverse gamma with known shape parameter, and Gompertz with known scale parameter.
The gamma distribution's conjugate prior is:Fink, D. 1995 [http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.157.5540&rep=rep1&type=pdf A Compendium of Conjugate Priors]. In progress report: Extension and enhancement of methods for setting data quality objectives. (DOE contract 95‑831).
where {{mvar|Z}} is the normalizing constant with no closed-form solution.
The posterior distribution can be found by updating the parameters as follows:
p' &= p\prod\nolimits_i x_i,\\
q' &= q + \sum\nolimits_i x_i,\\
r' &= r + n,\\
s' &= s + n,
\end{align}
where {{mvar|n}} is the number of observations, and {{math|xi}} is the {{mvar|i}}-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 {{mvar|λ}}. Then the waiting time for the {{mvar|n}}-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.{{Cite book |last=Jessica. |first=Scheiner, Samuel M., 1956- Gurevitch |url=http://worldcat.org/oclc/43694448 |title=Design and analysis of ecological experiments |date=2001 |publisher=Oxford University Press |isbn=0-19-513187-8 |chapter=13. Failure-time analysis |oclc=43694448 |chapter-url=https://books.google.com/books?id=AgsTDAAAQBAJ&dq=gamma+distribution+failure+waiting+time&pg=PA235 |access-date=2022-05-26 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203230/https://search.worldcat.org/title/43694448 |url-status=live }} Examples include the waiting time of cell-division events,{{Cite journal |last=Golubev |first=A. |date=March 2016 |title=Applications and implications of the exponentially modified gamma distribution as a model for time variabilities related to cell proliferation and gene expression |url=http://dx.doi.org/10.1016/j.jtbi.2015.12.027 |journal=Journal of Theoretical Biology |volume=393 |pages=203–217 |doi=10.1016/j.jtbi.2015.12.027 |pmid=26780652 |bibcode=2016JThBi.393..203G |issn=0022-5193 |access-date=2022-05-26 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203230/https://www.sciencedirect.com/unsupported_browser |url-status=live |url-access=subscription }} number of compensatory mutations for a given mutation,{{Cite journal |last1=Poon |first1=Art |last2=Davis |first2=Bradley H |last3=Chao |first3=Lin |date=2005-07-01 |title=The Coupon Collector and the Suppressor Mutation |url=http://dx.doi.org/10.1534/genetics.104.037259 |journal=Genetics |volume=170 |issue=3 |pages=1323–1332 |doi=10.1534/genetics.104.037259 |pmid=15879511 |pmc=1451182 |issn=1943-2631 |access-date=2022-05-26 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203231/https://academic.oup.com/genetics/article/170/3/1323/6060337 |url-status=live }} waiting time until a repair is necessary for a hydraulic system,{{Cite journal |last1=Vineyard |first1=Michael |last2=Amoako-Gyampah |first2=Kwasi |last3=Meredith |first3=Jack R |date=July 1999 |title=Failure rate distributions for flexible manufacturing systems: An empirical study |url=http://dx.doi.org/10.1016/s0377-2217(98)00096-4 |journal=European Journal of Operational Research |volume=116 |issue=1 |pages=139–155 |doi=10.1016/s0377-2217(98)00096-4 |issn=0377-2217 |access-date=2022-05-26 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203230/https://www.sciencedirect.com/unsupported_browser |url-status=live |url-access=subscription }} 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.{{Cite journal |last1=Rief |first1=Matthias |last2=Rock |first2=Ronald S. |last3=Mehta |first3=Amit D. |last4=Mooseker |first4=Mark S. |last5=Cheney |first5=Richard E. |last6=Spudich |first6=James A. |date=2000-08-15 |title=Myosin-V stepping kinetics: A molecular model for processivity |journal=Proceedings of the National Academy of Sciences |language=en |volume=97 |issue=17 |pages=9482–9486 |doi=10.1073/pnas.97.17.9482 |issn=0027-8424 |pmc=16890 |pmid=10944217 |doi-access=free |bibcode=2000PNAS...97.9482R }}
The gamma distribution has been used to model the size of insurance claimsp. 43, Philip J. Boland, Statistical and Probabilistic Methods in Actuarial Science, Chapman & Hall CRC 2007 and rainfalls.{{Cite journal |last=Wilks |first=Daniel S. |date=1990 |title=Maximum Likelihood Estimation for the Gamma Distribution Using Data Containing Zeros |journal=Journal of Climate |volume=3 |issue=12 |pages=1495–1501 |doi=10.1175/1520-0442(1990)003<1495:MLEFTG>2.0.CO;2 |jstor=26196366 |bibcode=1990JCli....3.1495W |issn=0894-8755|doi-access=free }} 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;{{citation needed|date=May 2019}} 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.{{cite journal |last1=Belikov |first1=Aleksey V. |title=The number of key carcinogenic events can be predicted from cancer incidence |journal=Scientific Reports |date=22 September 2017 |volume=7 |issue=1 |pages=12170 |doi=10.1038/s41598-017-12448-7|pmid=28939880 |pmc=5610194 |bibcode=2017NatSR...712170B }}{{Cite journal|last1=Belikov|first1=Aleksey V.|last2=Vyatkin|first2=Alexey|last3=Leonov|first3=Sergey V.|date=2021-08-06|title=The Erlang distribution approximates the age distribution of incidence of childhood and young adulthood cancers|journal=PeerJ|language=en|volume=9|pages=e11976|doi=10.7717/peerj.11976|pmid=34434669|pmc=8351573|issn=2167-8359|doi-access=free}}
In neuroscience, the gamma distribution is often used to describe the distribution of inter-spike intervals.J. G. Robson and J. B. Troy, "Nature of the maintained discharge of Q, X, and Y retinal ganglion cells of the cat", J. Opt. Soc. Am. A 4, 2301–2307 (1987)M.C.M. Wright, I.M. Winter, J.J. Forster, S. Bleeck "Response to best-frequency tone bursts in the ventral cochlear nucleus is governed by ordered inter-spike interval statistics", Hearing Research 317 (2014)
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.N. Friedman, L. Cai and X. S. Xie (2006) "Linking stochastic dynamics to population distribution: An analytical framework of gene expression", Phys. Rev. Lett. 97, 168302.
In genomics, the gamma distribution was applied in peak calling step (i.e., in recognition of signal) in ChIP-chipDJ Reiss, MT Facciotti and NS Baliga (2008) [https://web.archive.org/web/20121117144623/http://bioinformatics.oxfordjournals.org/content/24/3/396.full.pdf+html "Model-based deconvolution of genome-wide DNA binding"], Bioinformatics, 24, 396–403 and ChIP-seqMA Mendoza-Parra, M Nowicka, W Van Gool, H Gronemeyer (2013) [http://www.biomedcentral.com/1471-2164/14/834 "Characterising ChIP-seq binding patterns by model-based peak shape deconvolution"] {{Webarchive|url=https://web.archive.org/web/20241009203230/https://bmcgenomics.biomedcentral.com/articles/10.1186/1471-2164-14-834 |date=2024-10-09 }}, BMC Genomics, 14:834 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{{Cite journal |last=Yang |first=Ziheng |date=September 1996 |title=Among-site rate variation and its impact on phylogenetic analyses |url=https://linkinghub.elsevier.com/retrieve/pii/0169534796100410 |journal=Trends in Ecology & Evolution |language=en |volume=11 |issue=9 |pages=367–372 |doi=10.1016/0169-5347(96)10041-0 |pmid=21237881 |bibcode=1996TEcoE..11..367Y |access-date=2023-09-06 |archive-date=2024-04-12 |archive-url=https://web.archive.org/web/20240412001342/https://linkinghub.elsevier.com/retrieve/pii/0169534796100410 |url-status=live |citeseerx=10.1.1.19.99 }} 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 {{math|1=α = λ}}. This parameterization means that the mean of this distribution is 1 and the variance is {{math|1/α}}. Maximum likelihood and Bayesian methods typically use a discrete approximation to the continuous gamma distribution.{{Cite journal |last=Yang |first=Ziheng |date=September 1994 |title=Maximum likelihood phylogenetic estimation from DNA sequences with variable rates over sites: Approximate methods |url=http://link.springer.com/10.1007/BF00160154 |journal=Journal of Molecular Evolution |language=en |volume=39 |issue=3 |pages=306–314 |doi=10.1007/BF00160154 |pmid=7932792 |bibcode=1994JMolE..39..306Y |s2cid=17911050 |issn=0022-2844 |access-date=2023-09-06 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203844/https://link.springer.com/article/10.1007/BF00160154 |url-status=live |citeseerx=10.1.1.19.6626 }}{{Cite journal |last=Felsenstein |first=Joseph |date=2001-10-01 |title=Taking Variation of Evolutionary Rates Between Sites into Account in Inferring Phylogenies |url=http://link.springer.com/10.1007/s002390010234 |journal=Journal of Molecular Evolution |volume=53 |issue=4–5 |pages=447–455 |doi=10.1007/s002390010234 |pmid=11675604 |bibcode=2001JMolE..53..447F |s2cid=9791493 |issn=0022-2844 |access-date=2023-09-06 |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009203754/https://link.springer.com/article/10.1007/s002390010234 |url-status=live |url-access=subscription }}
Random variate generation
Given the scaling property above, it is enough to generate gamma variables with {{math|1=θ = 1}}, as we can later convert to any value of {{mvar|λ}} with a simple division.
Suppose we wish to generate random variables from {{math|Gamma(n + δ, 1)}}, where n is a non-negative integer and {{math|0 < δ < 1}}. Using the fact that a {{math|Gamma(1, 1)}} distribution is the same as an {{math|Exp(1)}} distribution, and noting the method of generating exponential variables, we conclude that if {{mvar|U}} is uniformly distributed on (0, 1], then {{math|−ln U}} is distributed {{math|Gamma(1, 1)}} (i.e. inverse transform sampling). Now, using the "{{mvar|α}}-addition" property of gamma distribution, we expand this result:
where {{math|Uk}} are all uniformly distributed on (0, 1] and independent. All that is left now is to generate a variable distributed as {{math|Gamma(δ, 1)}} for {{math|0 < δ < 1}} and apply the "{{mvar|α}}-addition" property once more. This is the most difficult part.
Random generation of gamma variates is discussed in detail by Devroye,{{cite book |publisher=Springer-Verlag |location=New York |year=1986 |last=Devroye |first=Luc |url=http://luc.devroye.org/rnbookindex.html |title=Non-Uniform Random Variate Generation |isbn=978-0-387-96305-1 |access-date=2012-02-26 |archive-date=2012-07-17 |archive-url=https://web.archive.org/web/20120717112308/http://luc.devroye.org/rnbookindex.html |url-status=live }} See Chapter 9, Section 3.{{Rp|401–428}} noting that none are uniformly fast for all shape parameters. For small values of the shape parameter, the algorithms are often not valid.{{Rp|406}} For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter{{Cite journal |last1=Ahrens |first1=J. H. |last2=Dieter |first2=U |date=January 1982 |title=Generating gamma variates by a modified rejection technique |journal=Communications of the ACM |volume=25 |issue=1 |pages=47–54 |doi=10.1145/358315.358390|s2cid=15128188 |doi-access=free }}. See Algorithm GD, p. 53. modified acceptance-rejection method Algorithm GD (shape {{math|α ≥ 1}}), or transformation method{{cite journal |last1=Ahrens |first1=J. H. |last2=Dieter |first2=U. |year=1974 |title=Computer methods for sampling from gamma, beta, Poisson and binomial distributions |journal=Computing |volume=12 |issue=3 |pages=223–246 |citeseerx=10.1.1.93.3828 |doi=10.1007/BF02293108|s2cid=37484126 }} when {{math|0 < α < 1}}. Also see Cheng and Feast Algorithm GKM 3{{cite journal |url=https://www.jstor.org/stable/2347200|jstor=2347200 |title=Some Simple Gamma Variate Generators |last1=Cheng |first1=R. C. H. |last2=Feast |first2=G. M. |journal=Journal of the Royal Statistical Society. Series C (Applied Statistics) |year=1979 |volume=28 |issue=3 |pages=290–295 |doi=10.2307/2347200 |url-access=subscription }} or Marsaglia's squeeze method.Marsaglia, G. The squeeze method for generating gamma variates. Comput, Math. Appl. 3 (1977), 321–325.
The following is a version of the Ahrens-Dieter acceptance–rejection method:
- Generate {{mvar|U}}, {{mvar|V}} and {{mvar|W}} as iid uniform (0, 1] variates.
- If then and . Otherwise, and .
- If then go to step 1.
- {{mvar|ξ}} is distributed as {{math|Γ(δ, 1)}}.
A summary of this is
where is the integer part of {{mvar|α}}, {{mvar|ξ}} is generated via the algorithm above with {{math|1=δ = {{mset|α}}}} (the fractional part of {{mvar|α}}) and the {{math|Uk}} are all independent.
While the above approach is technically correct, Devroye notes that it is linear in the value of {{mvar|α}} and generally is not a good choice. Instead, he recommends using either rejection-based or table-based methods, depending on context.{{Rp|401–428}}
For example, Marsaglia's simple transformation-rejection method relying on one normal variate {{mvar|X}} and one uniform variate {{mvar|U}}:{{cite journal |last1=Marsaglia|first1=G. |last2=Tsang |first2=W. W. |year=2000 |title=A simple method for generating gamma variables|journal=ACM Transactions on Mathematical Software|volume=26 |issue=3 |pages=363–372 |doi=10.1145/358407.358414|s2cid=2634158 }}
- Set and .
- Set .
- If and return , else go back to step 2.
With generates a gamma distributed random number in time that is approximately constant with {{mvar|&alpha}}. The acceptance rate does depend on {{mvar|α}}, with an acceptance rate of 0.95, 0.98, and 0.99 for α = 1, 2, and 4. For {{math|α < 1}}, one can use to boost {{mvar|k}} to be usable with this method.
In Matlab numbers can be generated using the function gamrnd(), which uses the α, θ representation.
References
{{Reflist|30em}}
External links
{{Wikibooks|Statistics|Distributions/Gamma|Gamma distribution}}
- {{springer|title=Gamma-distribution|id=p/g043300}}
- {{MathWorld|urlname=GammaDistribution|title=Gamma distribution}}
- ModelAssist (2017) [http://www.epixanalytics.com/modelassist/AtRisk/Model_Assist.htm#Distributions/Continuous_distributions/Gamma.htm Uses of the gamma distribution in risk modeling, including applied examples in Excel] {{Webarchive|url=https://web.archive.org/web/20170509042425/http://www.epixanalytics.com/modelassist/AtRisk/Model_Assist.htm#Distributions/Continuous_distributions/Gamma.htm |date=2017-05-09 }}.
- [http://www.itl.nist.gov/div898/handbook/eda/section3/eda366b.htm Engineering Statistics Handbook]
{{ProbDistributions|continuous-semi-infinite}}
{{DEFAULTSORT:Gamma Distribution}}
Category:Continuous distributions
Category:Factorial and binomial topics
Category:Conjugate prior distributions
Category:Exponential family distributions