Gamma distribution: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
No edit summary
removed a paragraph of redundant and clearly AI-generated text
 
Line 3: Line 3:
| name      = Gamma
| name      = Gamma
| type      = density
| type      = density
| pdf_image  = [[Image:Gammapdf252.svg|325px|Probability density plots of gamma distributions]]
| pdf_image  = [[Image:Gammapdf252.svg|325px|class=skin-invert-image|Probability density plots of gamma distributions]]
| cdf_image  = [[Image:Gammacdf252.svg|325px|Cumulative distribution plots of gamma distributions]]
| cdf_image  = [[Image:Gammacdf252.svg|325px|class=skin-invert-image|Cumulative distribution plots of gamma distributions]]
| parameters =
| parameters =
* {{math|''α'' > 0}} [[shape parameter|shape]]
* {{math|''α'' > 0}} [[shape parameter|shape]]
Line 53: Line 53:
In each of these forms, both parameters are positive real numbers.
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.<ref>{{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 }}</ref> 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.<ref>{{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}}</ref>
The distribution has important applications in various fields, including [[econometrics]], [[Bayesian statistics]], and life testing.<ref>{{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 }}</ref> 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]] (both with respect to a uniform base measure and a <math>1/x</math> 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]]).<ref>{{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 }}</ref>
The gamma distribution is the [[maximum entropy probability distribution]] (both with respect to a uniform base measure and a <math>1/x</math> 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]]).<ref>{{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 }}</ref>


== Definitions ==
== 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 [[Accelerated life testing|life testing]], the waiting time until death is a [[random variable]] that is frequently modeled with a gamma distribution. See Hogg and Craig<ref>{{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}}</ref>  for an explicit motivation.
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 [[Accelerated life testing|life testing]], the waiting time until death is a [[random variable]] that is frequently modeled with a gamma distribution. See Hogg and Craig<ref>{{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=0-02-355710-9|pages=Remark 3.3.1}}</ref>  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]]<ref>{{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}}</ref> – 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]].
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]]<ref>{{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}}</ref> – 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]].
Line 88: Line 88:
If {{mvar|α}} is a positive [[integer]] (i.e., the distribution is an [[Erlang distribution]]), the cumulative distribution function has the following series expansion:<ref name="Papoulis"/>
If {{mvar|α}} is a positive [[integer]] (i.e., the distribution is an [[Erlang distribution]]), the cumulative distribution function has the following series expansion:<ref name="Papoulis"/>


<math display=block>F(x;\alpha,\lambda) = 1-\sum_{i=0}^{\alpha-1} \frac{(\lambda x)^i}{i!} e^{-\lambda x} = e^{-\lambda x} \sum_{i=\alpha}^\infty \frac{(\lambda x)^i}{i!}.</math>
<math display="block">\begin{align}
F(x;\alpha,\lambda) &= 1-\sum_{i=0}^{\alpha-1} \frac{\left(\lambda x\right)^i}{i!} e^{-\lambda x} \\[1ex]
&= e^{-\lambda x} \sum_{i=\alpha}^\infty \frac{\left(\lambda x\right)^i}{i!}.
\end{align}</math>


=== Characterization using shape ''α'' and scale ''θ'' ===
=== Characterization using shape ''α'' and scale ''θ'' ===
Line 105: Line 108:
The [[cumulative distribution function]] is the regularized gamma function:
The [[cumulative distribution function]] is the regularized gamma function:


<math display=block> F(x;\alpha,\theta) = \int_0^x f(u;\alpha,\theta)\,du = \frac{\gamma\left(\alpha, \frac{x}{\theta}\right)}{\Gamma(\alpha)},</math>
<math display="block"> F(x;\alpha,\theta) = \int_0^x f(u;\alpha,\theta)\,du
= \frac{\gamma{\left(\alpha, \frac{x}{\theta}\right)}}{\Gamma(\alpha)},</math>


where <math>\gamma\left(\alpha, \frac{x}{\theta}\right)</math> is the lower [[incomplete gamma function]].
where <math display="inline">\gamma{\left(\alpha, \frac{x}{\theta}\right)}</math> 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]]):<ref name="Papoulis">Papoulis, Pillai, ''Probability, Random Variables, and Stochastic Processes'', Fourth Edition</ref>
It can also be expressed as follows, if {{mvar|α}} is a positive [[integer]] (i.e., the distribution is an [[Erlang distribution]]):<ref name="Papoulis">Papoulis, Pillai, ''Probability, Random Variables, and Stochastic Processes'', Fourth Edition</ref>
Line 130: Line 134:
=== Higher moments ===
=== Higher moments ===


The {{mvar|n}}-th [[raw moment]] is given by:
The {{mvar|r}}-th [[raw moment]] is given by:
<math display=block>
: <math>\mathrm{E}[X^r] = \theta^r \frac{\Gamma(\alpha+r)}{\Gamma(\alpha)} = \theta^r \alpha^\overline{r}</math>
\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.
with <math>\alpha^\overline{r}</math> the [[rising factorial]].
</math>


===Median approximations and bounds===
===Median approximations and bounds===
Line 142: Line 145:


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 <math>\theta = 1</math>)
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 <math>\theta = 1</math>)
<math display=block> \alpha - \frac{1}{3} < \nu(\alpha) < \alpha, </math>
<math display="block"> \alpha - \tfrac{1}{3} < \nu(\alpha) < \alpha, </math>
where <math>\mu(\alpha) = \alpha</math> is the mean and <math>\nu(\alpha)</math> is the median of the <math>\text{Gamma}(\alpha,1)</math> distribution.<ref>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}}.</ref>  For other values of the scale parameter, the mean scales to <math>\mu = \alpha\theta</math>, and the median bounds and approximations would be similarly scaled by {{mvar|θ}}.
where <math>\mu(\alpha) = \alpha</math> is the mean and <math>\nu(\alpha)</math> is the median of the <math>\text{Gamma}(\alpha,1)</math> distribution.<ref>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}}.</ref>  For other values of the scale parameter, the mean scales to <math>\mu = \alpha\theta</math>, 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 theta function|Ramanujan's <math> \theta </math> function]].<ref>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.</ref>  Berg and Pedersen found more terms:<ref name="Pedersen, Henrik L.-2006">{{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 }}</ref>
K. P. Choi found the first five terms in a [[Laurent series]] asymptotic approximation of the median by comparing the median to [[Ramanujan theta function|Ramanujan's <math> \theta </math> function]].<ref>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.</ref>  Berg and Pedersen found more terms:<ref name="Pedersen, Henrik L.-2006">{{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 }}</ref>
<math display=block> \nu(\alpha) = \alpha - \frac{1}{3} + \frac{8}{405\alpha} + \frac{184}{25515 \alpha^2} + \frac{2248}{3444525 \alpha^3} - \frac{19006408}{15345358875 \alpha^4} - O\left(\frac{1}{\alpha^5}\right) + \cdots </math>
<math display="block"> \begin{align}
\nu(\alpha) = \alpha & - \frac{1}{3} + \frac{8}{405} \alpha^{-1} + \frac{184}{{25\,515}} \alpha^{-2} + \frac{2248}{{3\,444\,525}} \alpha^{-3} \\[1ex]
& - \frac{19\,006\,408}{{15\,345\,358\,875}} \alpha^{-4} - \mathcal{O}{\left(\alpha^{-5}\right)} + \cdots
\end{align} </math>


[[File:Gamma distribution median Lyon bounds.png|320px|thumb| Two gamma distribution median asymptotes which were proved in 2023 to be bounds (upper solid red and lower dashed red), of the from <math>\nu(\alpha) \approx 2^{-1/\alpha}(A + \alpha)</math>, and an interpolation between them that makes an approximation (dotted red) that is exact at {{math|1=''α'' = 1}} and has maximum relative error of about 0.6%. The cyan shaded region is the remaining gap between upper and lower bounds (or conjectured bounds), including these new bounds and the bounds in the previous figure.]]
[[File:Gamma distribution median Lyon bounds.png|320px|thumb| Two gamma distribution median asymptotes which were proved in 2023 to be bounds (upper solid red and lower dashed red), of the from <math>\nu(\alpha) \approx 2^{-1/\alpha}(A + \alpha)</math>, and an interpolation between them that makes an approximation (dotted red) that is exact at {{math|1=''α'' = 1}} and has maximum relative error of about 0.6%. The cyan shaded region is the remaining gap between upper and lower bounds (or conjectured bounds), including these new bounds and the bounds in the previous figure.]]
Line 156: Line 162:
Berg and Pedersen also proved many properties of the median, showing that it is a convex function of {{mvar|α}},<ref name="Berg">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 }}.</ref> and that the asymptotic behavior near <math>\alpha = 0</math> is <math>\nu(\alpha) \approx e^{-\gamma}2^{-1/\alpha}</math> (where {{mvar|γ}} is the [[Euler–Mascheroni constant]]), and that for all <math>\alpha > 0</math> the median is bounded by <math>\alpha 2^{-1/\alpha} < \nu(\alpha) < k e^{-1/3k}</math>.<ref name="Pedersen, Henrik L.-2006"/>
Berg and Pedersen also proved many properties of the median, showing that it is a convex function of {{mvar|α}},<ref name="Berg">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 }}.</ref> and that the asymptotic behavior near <math>\alpha = 0</math> is <math>\nu(\alpha) \approx e^{-\gamma}2^{-1/\alpha}</math> (where {{mvar|γ}} is the [[Euler–Mascheroni constant]]), and that for all <math>\alpha > 0</math> the median is bounded by <math>\alpha 2^{-1/\alpha} < \nu(\alpha) < k e^{-1/3k}</math>.<ref name="Pedersen, Henrik L.-2006"/>


A closer linear upper bound, for <math>\alpha \ge 1</math> only, was provided in 2021 by Gaunt and Merkle,<ref>{{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 }}</ref> relying on the Berg and Pedersen result that the slope of <math>\nu(\alpha)</math> is everywhere less than 1:
A closer linear upper bound, for <math>\alpha \ge 1</math> only, was provided in 2021 by Gaunt and Merkle,<ref>{{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 |article-number=124508|doi=10.1016/j.jmaa.2020.124508 |arxiv=2002.01884 |s2cid=221103640 }}</ref> relying on the Berg and Pedersen result that the slope of <math>\nu(\alpha)</math> is everywhere less than 1:
<math display=block> \nu(\alpha) \le \alpha - 1 + \log2 ~~</math> for <math>\alpha \ge 1</math> (with equality at <math>\alpha = 1</math>)
<math display=block> \nu(\alpha) \le \alpha - 1 + \log2 ~~</math> for <math>\alpha \ge 1</math> (with equality at <math>\alpha = 1</math>)
which can be extended to a bound for all <math>\alpha > 0</math> by taking the max with the chord shown in the figure, since the median was proved convex.<ref name="Berg"/>
which can be extended to a bound for all <math>\alpha > 0</math> by taking the max with the chord shown in the figure, since the median was proved convex.<ref name="Berg"/>
Line 164: Line 170:
which goes negative for <math>\alpha < 1/9</math>.
which goes negative for <math>\alpha < 1/9</math>.


In 2021, Lyon proposed several approximations of the form <math>\nu(\alpha) \approx 2^{-1/\alpha}(A + B\alpha)</math>.  He conjectured values of {{mvar|A}} and {{mvar|B}} for which this approximation is an asymptotically tight upper or lower bound for all <math>\alpha > 0</math>.<ref name="Lyon-2021a">{{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 }}</ref>  In particular, he proposed these closed-form bounds, which he proved in 2023:<ref name="Lyon-2021b">{{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 }}</ref>
In 2021, Lyon proposed several approximations of the form <math>\nu(\alpha) \approx 2^{-1/\alpha}(A + B\alpha)</math>.  He conjectured values of {{mvar|A}} and {{mvar|B}} for which this approximation is an asymptotically tight upper or lower bound for all <math>\alpha > 0</math>.<ref name="Lyon-2021a">{{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 |article-number=e0251626 |doi=10.1371/journal.pone.0251626 |pmid=33984053 |pmc=8118309 |arxiv=2011.04060 |bibcode=2021PLoSO..1651626L |doi-access=free }}</ref>  In particular, he proposed these closed-form bounds, which he proved in 2023:<ref name="Lyon-2021b">{{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 |article-number=e0288601 |doi=10.1371/journal.pone.0288601  |pmid=37682854 |pmc=10490949 |doi-access=free }}</ref>


<math display=block> \nu_{L\infty}(\alpha) = 2^{-1/\alpha}(\log 2 - \frac{1}{3} + \alpha) \quad</math> is a lower bound, asymptotically tight as <math>\alpha \to \infty</math>
<math display="block"> \nu_{L\infty}(\alpha) = 2^{-1/\alpha} \left(\log 2 - \tfrac{1}{3} + \alpha\right)</math> is a lower bound, asymptotically tight as <math>\alpha \to \infty</math>
<math display=block> \nu_U(\alpha)  = 2^{-1/\alpha}(e^{-\gamma} + \alpha) \quad</math> is an upper bound, asymptotically tight as <math>\alpha \to 0</math>
<math display=block> \nu_U(\alpha)  = 2^{-1/\alpha}(e^{-\gamma} + \alpha) \quad</math> is an upper bound, asymptotically tight as <math>\alpha \to 0</math>


Lyon also showed (informally in 2021, rigorously in 2023) two other lower bounds that are not [[closed-form expression]]s, including this one involving the [[gamma function]], based on solving the integral expression substituting 1 for <math>e^{-x}</math>:
Lyon also showed (informally in 2021, rigorously in 2023) two other lower bounds that are not [[closed-form expression]]s, including this one involving the [[gamma function]], based on solving the integral expression substituting 1 for <math>e^{-x}</math>:
<math display=block>\nu(\alpha) > \left( \frac{2}{\Gamma(\alpha+1)} \right)^{-1/\alpha} \quad</math> (approaching equality as <math>k \to 0</math>)
<math display="block">\nu(\alpha) > \left( \frac{2}{\Gamma(\alpha+1)} \right)^{-1/\alpha}</math> (approaching equality as <math>k \to 0</math>)
and the tangent line at <math>\alpha = 1</math> where the derivative was found to be <math>\nu^\prime(1)  \approx 0.9680448</math>:
and the tangent line at <math>\alpha = 1</math> where the derivative was found to be <math>\nu^\prime(1)  \approx 0.9680448</math>:
<math display=block>\nu(\alpha) \ge \nu(1) + (\alpha-1) \nu^\prime(1) \quad</math> (with equality at <math>k = 1</math>)
<math display=block>\nu(\alpha) \ge \nu(1) + (\alpha-1) \nu^\prime(1) \quad</math> (with equality at <math>k = 1</math>)
<math display=block>\nu(\alpha) \ge \log 2 + (\alpha-1) (\gamma - 2 \operatorname{Ei}(-\log 2) - \log \log 2)</math>
<math display="block">\nu(\alpha) \ge \log 2 + (\alpha-1) \left[\gamma - 2 \operatorname{Ei}(-\log 2) - \log \log 2\right]</math>
where Ei is the [[exponential integral]].<ref name="Lyon-2021a"/><ref name="Lyon-2021b"/>
where Ei is the [[exponential integral]].<ref name="Lyon-2021a"/><ref name="Lyon-2021b"/>


Line 257: Line 263:
The [[Kullback–Leibler divergence]] (KL-divergence), of {{math|Gamma(''α''<sub>''p''</sub>,  ''λ''<sub>''p''</sub>)}} ("true" distribution) from {{math|Gamma(''α''<sub>''q''</sub>, ''λ''<sub>''q''</sub>)}} ("approximating" distribution) is given by<ref>{{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}}</ref>
The [[Kullback–Leibler divergence]] (KL-divergence), of {{math|Gamma(''α''<sub>''p''</sub>,  ''λ''<sub>''p''</sub>)}} ("true" distribution) from {{math|Gamma(''α''<sub>''q''</sub>, ''λ''<sub>''q''</sub>)}} ("approximating" distribution) is given by<ref>{{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}}</ref>


<math display=block>
<math display="block">
\begin{align}
\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) \\
D_{\mathrm{KL}}(\alpha_p,\lambda_p; \alpha_q, \lambda_q) = {} & (\alpha_p-\alpha_q) \psi(\alpha_p) - \log\frac{\Gamma(\alpha_p)}{\Gamma(\alpha_q)} \\
& {} + \alpha_q(\log \lambda_p - \log \lambda_q) + \alpha_p\frac{\lambda_q-\lambda_p}{\lambda_p}.
& {} + \alpha_q \log\frac{\lambda_p}{\lambda_q} + \alpha_p\left(\frac{\lambda_q}{\lambda_p} - 1\right).
\end{align}
\end{align}
</math>
</math>
Line 266: Line 272:
Written using the {{mvar|α}}, {{mvar|θ}} parameterization, the KL-divergence of {{math|Gamma(''α''<sub>''p''</sub>,  ''θ''<sub>''p''</sub>)}} from {{math|Gamma(''α''<sub>''q''</sub>,  ''θ''<sub>''q''</sub>)}} is given by
Written using the {{mvar|α}}, {{mvar|θ}} parameterization, the KL-divergence of {{math|Gamma(''α''<sub>''p''</sub>,  ''θ''<sub>''p''</sub>)}} from {{math|Gamma(''α''<sub>''q''</sub>,  ''θ''<sub>''q''</sub>)}} is given by


<math display=block>
<math display="block">
\begin{align}
\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) \\
D_{\mathrm{KL}}(\alpha_p,\theta_p; \alpha_q, \theta_q) = {} & (\alpha_p-\alpha_q)\psi(\alpha_p) - \log\frac{\Gamma(\alpha_p)}{\Gamma(\alpha_q)} \\
& {} + \alpha_q(\log \theta_q - \log \theta_p) + \alpha_p \frac{\theta_p - \theta_q}{\theta_q}.
& {} + \alpha_q \log\frac{\theta_q}{\theta_p} + \alpha_p \left(\frac{\theta_p}{\theta_q} - 1 \right).
\end{align}
\end{align}
</math>
</math>
Line 276: Line 282:
The [[Laplace transform]] of the gamma PDF, which is the [[moment-generating function]] of the gamma distribution, is
The [[Laplace transform]] of the gamma PDF, which is the [[moment-generating function]] of the gamma distribution, is


<math display="block">F(s) = \operatorname E\left( e^{sX} \right) = \frac1 {(1 - \theta s)^\alpha} = \left( \frac\lambda{ \lambda - s} \right)^\alpha </math>
<math display="block">F(s) = \operatorname E\left[ e^{-sX} \right] = \frac{1}{\left(1 + \theta s\right)^\alpha} = \left( \frac\lambda{ \lambda + s} \right)^\alpha </math>


(where <math display=inline>X</math> is a random variable with that distribution).
(where <math display=inline>X</math> is a random variable with that distribution).
Line 283: Line 289:


===General===
===General===
* Let <math> X_1, X_2, \ldots, X_n </math> be <math> n </math> independent and identically distributed random variables following an [[exponential distribution]] with rate parameter ''λ'', then <math>\sum_i X_i \sim \operatorname{Gamma}(n,\lambda)</math> where ''n'' is the shape parameter and {{mvar|λ}} is the rate, and <math display=inline>\bar{X} = \frac{1}{n} \sum_i  X_i \sim \operatorname{Gamma}(n, n\lambda)</math>.
* Let <math> X_1, X_2, \ldots, X_n </math> be <math> n </math> independent and identically distributed random variables following an [[exponential distribution]] with rate parameter ''λ'', then <math display="inline">\sum_i X_i \sim \operatorname{Gamma}(n,\lambda)</math> where ''n'' is the shape parameter and {{mvar|λ}} is the rate, and <math display=inline>\bar{X} = \frac{1}{n} \sum_i  X_i \sim \operatorname{Gamma}(n, n\lambda)</math>.
* 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(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|''χ''<sup>2</sup>(''ν'')}}, the [[chi-squared distribution]] with {{mvar|ν}} degrees of freedom. Conversely, if {{math|''Q'' ~ ''χ''<sup>2</sup>(''ν'')}} and {{mvar|c}} is a positive constant, then {{math|''cQ'' ~ Gamma(''ν''/2, 2''c'')}}.
* If {{math|''X'' ~ Gamma(''ν''/2, 2)}} (in the shape–scale parametrization), then {{mvar|X}} is identical to {{math|''χ''<sup>2</sup>(''ν'')}}, the [[chi-squared distribution]] with {{mvar|ν}} degrees of freedom. Conversely, if {{math|''Q'' ~ ''χ''<sup>2</sup>(''ν'')}} and {{mvar|c}} is a positive constant, then {{math|''cQ'' ~ Gamma(''ν''/2, 2''c'')}}.
* If {{math|1=''θ'' = 1/''α''}}, one obtains the [[Schulz-Zimm distribution]], which is most prominently used to model polymer chain lengths.
* 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
* 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
::<math>X \sim \Gamma(\alpha \in \mathbf{Z}, \theta), \qquad Y \sim \operatorname{Pois}\left(\frac x \theta \right),</math>
::<math>X \sim \Gamma(\alpha \in \mathbb{Z}, \theta), \qquad Y \sim \operatorname{Pois}\left(\frac x \theta \right),</math>
:then
:then
::<math>P(X > x) = P(Y < \alpha).</math>
::<math>\Pr(X > x) = \Pr(Y < \alpha).</math>
* If {{mvar|X}} has a [[Maxwell–Boltzmann distribution]] with parameter {{mvar|a}}, then
* If {{mvar|X}} has a [[Maxwell–Boltzmann distribution]] with parameter {{mvar|a}}, then
::<math>X^2 \sim \Gamma\left(\frac{3}{2}, 2a^2\right).</math>
::<math>X^2 \sim \Gamma{\left(\tfrac{3}{2}, 2a^2\right)}.</math>
<!--
<!--
* <math>Y \sim N(\mu = \alpha \lambda, \sigma^2 = \alpha \lambda^2)</math> is a [[normal distribution]] as <math>Y = \lim_{\alpha \to \infty} X</math> where {{math|''X'' ~ Gamma(''α'', ''λ'')}}. -->
* <math>Y \sim N(\mu = \alpha \lambda, \sigma^2 = \alpha \lambda^2)</math> is a [[normal distribution]] as <math>Y = \lim_{\alpha \to \infty} X</math> where {{math|''X'' ~ Gamma(''α'', ''λ'')}}. -->
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}}, then <math display=inline>\log X</math> follows an exponential-gamma (abbreviated exp-gamma) distribution.<ref>{{Cite web|url=https://reference.wolfram.com/language/ref/ExpGammaDistribution.html|title = ExpGammaDistribution—Wolfram Language Documentation}}</ref> It is sometimes referred to as the log-gamma distribution.<ref>{{Cite web|url=https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.loggamma.html#scipy.stats.loggamma|title=scipy.stats.loggamma — SciPy v1.8.0 Manual|website=docs.scipy.org}}</ref> Formulas for its mean and variance are in the section [[#Logarithmic expectation and variance]].
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}}, then <math display=inline>\exp X</math> follows a log-gamma distribution.<ref>{{Cite web|url=https://reference.wolfram.com/language/ref/LogGammaDistribution.html|title = LogGammaDistribution—Wolfram Language Documentation}}</ref>
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}}, then <math>\sqrt{X}</math> follows a [[generalized gamma distribution]] with parameters {{math|1=''p'' = 2}}, {{math|1=''d'' = 2''α''}}, and <math>a = \sqrt{\theta}</math> {{citation needed|date=September 2012}}.
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}}, then <math display=inline>\log X</math> follows an exponential-gamma (abbreviated exp-gamma) distribution.<ref>{{Cite web|url=https://reference.wolfram.com/language/ref/ExpGammaDistribution.html|title = ExpGammaDistribution—Wolfram Language Documentation}}</ref> It is sometimes incorrectly referred to as the log-gamma distribution.<ref>{{Cite web|url=https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.loggamma.html#scipy.stats.loggamma|title=scipy.stats.loggamma — SciPy v1.8.0 Manual|website=docs.scipy.org}}</ref> Formulas for its mean and variance are in the section [[#Logarithmic expectation and variance]].
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}}, then <math>\sqrt{X}</math> follows a [[generalized gamma distribution]] with parameters {{math|1=''p'' = 2}}, {{math|1=''d'' = 2''α''}}, and <math>a = \sqrt{\theta}</math>.{{citation needed|date=September 2012}}
* More generally, if {{math|''X'' ~ Gamma(''α'',''θ'')}}, then <math>X^q</math> for <math>q > 0</math> follows a [[generalized gamma distribution]] with parameters {{math|1=''p'' = 1/''q''}}, {{math|1=''d'' = ''α''/''q''}}, and <math>a = \theta^q</math>.
* More generally, if {{math|''X'' ~ Gamma(''α'',''θ'')}}, then <math>X^q</math> for <math>q > 0</math> follows a [[generalized gamma distribution]] with parameters {{math|1=''p'' = 1/''q''}}, {{math|1=''d'' = ''α''/''q''}}, and <math>a = \theta^q</math>.
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}} with shape {{mvar|α}} and scale {{mvar|θ}}, then {{math|1/''X'' ~ Inv-Gamma(''α'', ''θ''<sup>−1</sup>)}} (see [[Inverse-gamma distribution]] for derivation).
* If {{math|''X'' ~ Gamma(''α'', ''θ'')}} with shape {{mvar|α}} and scale {{mvar|θ}}, then {{math|1/''X'' ~ Inv-Gamma(''α'', ''θ''<sup>−1</sup>)}} (see [[Inverse-gamma distribution]] for derivation).
Line 310: Line 317:
* Among the discrete distributions, the [[negative binomial distribution]] is sometimes considered the discrete analog of the gamma distribution.
* Among the discrete distributions, the [[negative binomial distribution]] is sometimes considered the discrete analog of the gamma distribution.
* [[Tweedie distribution]]s – the gamma distribution is a member of the family of Tweedie [[exponential dispersion model]]s.
* [[Tweedie distribution]]s – the gamma distribution is a member of the family of Tweedie [[exponential dispersion model]]s.
* Modified [[Half-normal distribution]] – the Gamma distribution is a member of the family of [[Modified half-normal distribution]].<ref>{{cite journal |last1=Sun |first1=Jingchao |last2=Kong |first2=Maiying |last3=Pal |first3=Subhadip |title=The Modified-Half-Normal distribution: Properties and an efficient sampling scheme |journal=Communications in Statistics - Theory and Methods |date=22 June 2021 |volume=52 |issue=5 |pages=1591–1613 |doi=10.1080/03610926.2021.1934700 |s2cid=237919587 |url=https://figshare.com/articles/journal_contribution/The_Modified-Half-Normal_distribution_Properties_and_an_efficient_sampling_scheme/14825266/1/files/28535884.pdf |issn=0361-0926 |access-date=2 September 2022 |archive-date= |archive-url= |url-status= }}</ref> The corresponding density is <math> f(x\mid \alpha, \lambda, \gamma)= \frac{2\lambda^{\frac{\alpha}{2}} x^{\alpha-1} \exp(-\lambda x^2+ \gamma x )}{\Psi{\left(\frac{\alpha}{2}, \frac{ \gamma}{\sqrt{\lambda}}\right)}}</math>, where <math>\Psi(\alpha,z)={}_1\Psi_1\left(\begin{matrix}\left(\alpha,\frac{1}{2}\right)\\(1,0)\end{matrix};z \right)</math> denotes the [[Fox–Wright Psi function]].
* Modified [[Half-normal distribution]] – the Gamma distribution is a member of the family of [[Modified half-normal distribution]].<ref>{{cite journal |last1=Sun |first1=Jingchao |last2=Kong |first2=Maiying |last3=Pal |first3=Subhadip |title=The Modified-Half-Normal distribution: Properties and an efficient sampling scheme |journal=Communications in Statistics - Theory and Methods |date=22 June 2021 |volume=52 |issue=5 |pages=1591–1613 |doi=10.1080/03610926.2021.1934700 |s2cid=237919587 |url=https://figshare.com/articles/journal_contribution/The_Modified-Half-Normal_distribution_Properties_and_an_efficient_sampling_scheme/14825266/1/files/28535884.pdf |issn=0361-0926 |access-date=2 September 2022 }}</ref> The corresponding density is <math> f(x\mid \alpha, \lambda, \gamma)= \frac{2\lambda^{\frac{\alpha}{2}} x^{\alpha-1} \exp(-\lambda x^2+ \gamma x )}{\Psi{\left(\frac{\alpha}{2}, \frac{ \gamma}{\sqrt{\lambda}}\right)}}</math>, where <math>\Psi(\alpha,z) = {}_1\Psi_1{\left(\begin{matrix}\left(\alpha,\frac{1}{2}\right)\\(1,0)\end{matrix};z \right)}</math> denotes the [[Fox–Wright Psi function]].
* For the shape-scale parameterization <math>x|\theta \sim \Gamma(\alpha,\theta)</math>, if the scale parameter <math>\theta \sim IG(b,1)</math> where <math>IG</math> denotes the [[Inverse-gamma distribution]], then the marginal distribution <math>x \sim \lambda'(\alpha,b)</math> where <math>\lambda'</math> denotes the [[Beta prime distribution]].
* For the shape-scale parameterization <math>x|\theta \sim \Gamma(\alpha,\theta)</math>, if the scale parameter <math>\theta \sim IG(b,1)</math> where <math>IG</math> denotes the [[Inverse-gamma distribution]], then the marginal distribution <math>x \sim \lambda'(\alpha,b)</math> where <math>\lambda'</math> denotes the [[Beta prime distribution]].


Line 317: Line 324:


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]].
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 <math> f(x;\alpha) \, (\alpha > 1) </math> can be expressed as the product distribution of a [[Weibull distribution]] and a variant form of the [[stable count distribution]].
Its shape parameter <math> \alpha </math> can be regarded as the inverse of Lévy's stability parameter in the stable count distribution:
<math display="block">
    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 ,
</math>
where <math>\mathfrak{N}_\alpha(\nu)</math> is a standard stable count distribution of shape <math> \alpha </math>, and <math>W_\alpha(x)</math> is a standard Weibull distribution of shape <math> \alpha </math>.


==Statistical inference==
==Statistical inference==
Line 348: Line 344:
Substituting this into the log-likelihood function gives
Substituting this into the log-likelihood function gives


<math display=block>\ell(\alpha) = (\alpha-1)\sum_{i=1}^N \ln x_i -N\alpha - N\alpha\ln \left(\frac{\sum x_i}{\alpha N} \right) - N\ln \Gamma(\alpha)</math>
<math display="block">\ell(\alpha) = (\alpha-1)\sum_{i=1}^N \ln x_i -N\alpha - N\alpha\ln \frac{\sum_i x_i}{\alpha N} - N\ln \Gamma(\alpha)</math>


We need at least two samples: <math>N\ge2</math>, because for <math>N=1</math>, the function <math>\ell(\alpha)</math> increases without bounds as <math>\alpha\to\infty</math>. For <math>\alpha>0</math>, it can be verified that <math>\ell(\alpha)</math> is strictly [[concave function|concave]], by using [[Polygamma function#Inequalities|inequality properties of the polygamma function]]. Finding the maximum with respect to {{mvar|α}} by taking the derivative and setting it equal to zero yields
We need at least two samples: <math>N\ge2</math>, because for <math>N=1</math>, the function <math>\ell(\alpha)</math> increases without bounds as <math>\alpha\to\infty</math>. For <math>\alpha>0</math>, it can be verified that <math>\ell(\alpha)</math> is strictly [[concave function|concave]], by using [[Polygamma function#Inequalities|inequality properties of the polygamma function]]. Finding the maximum with respect to {{mvar|α}} by taking the derivative and setting it equal to zero yields


<math display=block>\ln \alpha - \psi(\alpha) = \ln\left(\frac{1}{N}\sum_{i=1}^N x_i\right) - \frac 1 N \sum_{i=1}^N \ln x_i = \ln \bar{x} - \overline{\ln x}</math>
<math display="block">\begin{align}
\ln \alpha - \psi(\alpha) &= \ln\left(\frac{1}{N}\sum_{i=1}^N x_i\right) - \frac 1 N \sum_{i=1}^N \ln x_i \\[1ex]
&= \ln \bar{x} - \overline{\ln x}
\end{align}</math>


where {{mvar|ψ}} is the [[digamma function]] and <math>\overline{\ln x}</math> 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 (statistics)|method of moments]], or using the approximation
where {{mvar|ψ}} is the [[digamma function]] and <math>\overline{\ln x}</math> 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 (statistics)|method of moments]], or using the approximation
Line 360: Line 359:
If we let
If we let


<math display=block>s = \ln \left(\frac 1 N \sum_{i=1}^N x_i\right) - \frac 1 N \sum_{i=1}^N \ln x_i = \ln \bar{x} - \overline{\ln x}</math>
<math display="block">\begin{align}
s &= \ln \left(\frac 1 N \sum_{i=1}^N x_i\right) - \frac 1 N \sum_{i=1}^N \ln x_i \\[1ex]
&= \ln \bar{x} - \overline{\ln x}
\end{align}</math>


then {{mvar|α}} is approximately
then {{mvar|α}} is approximately


<math display=block>k \approx \frac{3 - s + \sqrt{(s - 3)^2 + 24s}}{12s}</math>
<math display="block">k \approx \frac{3 - s + \sqrt{\left(s - 3\right)^2 + 24s}}{12s}</math>


which is within 1.5% of the correct value.<ref>{{cite web |last=Minka |first=Thomas P. |year=2002 |title=Estimating a Gamma distribution |url=https://tminka.github.io/papers/minka-gamma.pdf }}</ref> An explicit form for the Newton–Raphson update of this initial guess is:<ref>{{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 }}</ref>
which is within 1.5% of the correct value.<ref>{{cite web |last=Minka |first=Thomas P. |year=2002 |title=Estimating a Gamma distribution |url=https://tminka.github.io/papers/minka-gamma.pdf }}</ref> An explicit form for the Newton–Raphson update of this initial guess is:<ref>{{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 }}</ref>
Line 380: Line 382:
=====Caveat for small shape parameter=====
=====Caveat for small shape parameter=====
For data, <math>(x_1,\ldots,x_N)</math>, that is represented in a [[floating point]] format that underflows to 0 for values smaller than <math>\varepsilon</math>, 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 <math>F(x;\alpha,\theta)</math>, then the probability that there is at least one underflow is:
For data, <math>(x_1,\ldots,x_N)</math>, that is represented in a [[floating point]] format that underflows to 0 for values smaller than <math>\varepsilon</math>, 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 <math>F(x;\alpha,\theta)</math>, then the probability that there is at least one underflow is:
<math display=block>
<math display="block">
P(\text{underflow}) = 1-(1-F(\varepsilon;\alpha,\theta))^N
\Pr(\text{underflow}) = 1-(1-F(\varepsilon;\alpha,\theta))^N
</math>
</math>
This probability will approach 1 for small {{mvar|α}} and  large {{mvar|N}}. For example, at <math>\alpha=10^{-2}</math>,  <math>N=10^4</math> and <math>\varepsilon=2.25\times10^{-308}</math>, <math>P(\text{underflow})\approx 0.9998</math>. A workaround is to instead have the data in logarithmic format.
This probability will approach 1 for small {{mvar|α}} and  large {{mvar|N}}. For example, at <math>\alpha=10^{-2}</math>,  <math>N=10^4</math> and <math>\varepsilon=2.25\times10^{-308}</math>, <math>\Pr(\text{underflow})\approx 0.9998</math>. 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 <math>\alpha<1</math>. Following the implementation in <code>scipy.stats.loggamma</code>, this can be done as follows:<ref name="Marsaglia-2000" /> sample <math>Y\sim\text{Gamma}(\alpha+1,\theta)</math> and <math>U\sim\text{Uniform}</math> independently. Then the required logarithmic sample is <math>Z=\ln(Y)+\ln(U)/\alpha</math>, so that <math>\exp(Z)\sim\text{Gamma}(k,\theta)</math>.
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 <math>\alpha<1</math>. Following the implementation in <code>scipy.stats.loggamma</code>, this can be done as follows:<ref name="Marsaglia-2000" /> sample <math>Y\sim\text{Gamma}(\alpha+1,\theta)</math> and <math>U\sim\text{Uniform}</math> independently. Then the required logarithmic sample is <math>Z=\ln(Y)+\ln(U)/\alpha</math>, so that <math>\exp(Z)\sim\text{Gamma}(k,\theta)</math>.
Line 393: Line 395:
The estimate for the shape {{mvar|α}} is
The estimate for the shape {{mvar|α}} is


<math display=block>\hat{\alpha} = \frac{N \sum_{i=1}^N x_i}{N \sum_{i=1}^N x_i \ln x_i - \sum_{i=1}^N x_i \sum_{i=1}^N \ln x_i} </math>
<math display="block">\hat{\alpha} = \frac{N \sum\limits_{i=1}^N x_i}{N \sum\limits_{i=1}^N x_i \ln x_i - \sum\limits_{i=1}^N x_i \sum\limits_{i=1}^N \ln x_i} </math>


and the estimate for the scale {{mvar|θ}} is
and the estimate for the scale {{mvar|θ}} is
Line 401: Line 403:
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:
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:


<math display=block>\hat{\alpha} = \bar{x} / \hat{\theta}</math>
<math display="block">\hat{\alpha} = \frac{\bar{x}}{\hat{\theta}}</math>
<math display=block>\hat{\theta} = \overline{x\ln x} - \bar{x} \overline{\ln x}.</math>
<math display="block">\hat{\theta} = \overline{x\ln x} - \bar{x} \overline{\ln x}.</math>


If the rate parameterization is used, the estimate of <math>\hat{\lambda} = 1/\hat{\theta}</math>.
If the rate parameterization is used, the estimate of <math>\hat{\lambda} = 1/\hat{\theta}</math>.
Line 419: Line 421:
With known {{mvar|α}} and unknown {{mvar|θ}}, the posterior density function for theta (using the standard scale-invariant [[prior probability|prior]] for {{mvar|θ}}) is
With known {{mvar|α}} and unknown {{mvar|θ}}, the posterior density function for theta (using the standard scale-invariant [[prior probability|prior]] for {{mvar|θ}}) is


<math display=block>P(\theta \mid \alpha, x_1, \dots, x_N) \propto \frac 1 \theta \prod_{i=1}^N f(x_i; \alpha, \theta)</math>
<math display="block">\Pr(\theta \mid \alpha, x_1, \dots, x_N) \propto \frac 1 \theta \prod_{i=1}^N f(x_i; \alpha, \theta)</math>


Denoting
Denoting


<math display=block> y \equiv \sum_{i=1}^Nx_i , \qquad P(\theta \mid \alpha, x_1, \dots, x_N) = C(x_i) \theta^{-N \alpha-1} e^{-y/\theta}</math>
<math display="block"> y \equiv \sum_{i=1}^Nx_i , \qquad \Pr(\theta \mid \alpha, x_1, \dots, x_N) = C(x_i) \theta^{-N \alpha-1} e^{-y/\theta}</math>


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
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


<math display=block>\int_0^\infty \theta^{-N\alpha - 1 + m} e^{-y/\theta}\, d\theta = \int_0^\infty x^{N\alpha - 1 - m} e^{-xy} \, dx = y^{-(N\alpha - m)} \Gamma(N\alpha - m) \!</math>
<math display="block">\begin{align}
\int_0^\infty \theta^{-N\alpha - 1 + m} e^{-y/\theta}\, d\theta &= \int_0^\infty x^{N\alpha - 1 - m} e^{-xy} \, dx \\
&= y^{-(N\alpha - m)} \Gamma(N\alpha - m) \!
\end{align}</math>


The moments can be computed by taking the ratio ({{mvar|m}} by {{math|1=''m'' = 0}})
The moments can be computed by taking the ratio ({{mvar|m}} by {{math|1=''m'' = 0}})
Line 435: Line 440:
which shows that the mean ± standard deviation estimate of the posterior distribution for {{mvar|θ}} is
which shows that the mean ± standard deviation estimate of the posterior distribution for {{mvar|θ}} is


<math display=block> \frac y {N\alpha - 1} \pm \sqrt{\frac {y^2} {(N\alpha - 1)^2 (N\alpha - 2)}}. </math>
<math display="block"> \frac y {N\alpha - 1} \pm \sqrt{\frac {y^2} {\left(N\alpha - 1\right)^2 (N\alpha - 2)}}. </math>


===Bayesian inference===
===Bayesian inference===
Line 459: Line 464:


== Occurrence and applications ==
== 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 <math>\alpha = n</math>. 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.<ref>{{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 }}</ref> Examples include the waiting time of [[Cell division|cell-division events]],<ref>{{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 }}</ref> number of compensatory mutations for a given mutation,<ref>{{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 }}</ref> waiting time until a repair is necessary for a hydraulic system,<ref>{{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 }}</ref> and so on.
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 <math>\alpha = n</math>. 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.<ref>{{Cite book |last=Jessica. |first=Scheiner, Samuel M., 1956- Gurevitch |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 }}</ref> Examples include the waiting time of [[Cell division|cell-division events]],<ref>{{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 |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 }}</ref> number of compensatory mutations for a given mutation,<ref>{{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 |journal=Genetics |volume=170 |issue=3 |pages=1323–1332 |doi=10.1534/genetics.104.037259 |pmid=15879511 |pmc=1451182 |issn=1943-2631 }}</ref> waiting time until a repair is necessary for a hydraulic system,<ref>{{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 |journal=European Journal of Operational Research |volume=116 |issue=1 |pages=139–155 |doi=10.1016/s0377-2217(98)00096-4 |issn=0377-2217 }}</ref> 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.<ref>{{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 }}</ref>
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.<ref>{{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 }}</ref>
Line 469: Line 474:
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 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]] [[Disease incidence|incidence]] often follows the gamma distribution, wherein the shape and scale parameters predict, respectively, the number of [[Carcinogenesis|driver events]] and the time interval between them.<ref>{{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 }}</ref><ref>{{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}}</ref>
In [[oncology]], the age distribution of [[cancer]] [[Disease incidence|incidence]] often follows the gamma distribution, wherein the shape and scale parameters predict, respectively, the number of [[Carcinogenesis|driver events]] and the time interval between them.<ref>{{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 |article-number=12170 |doi=10.1038/s41598-017-12448-7|pmid=28939880 |pmc=5610194 |bibcode=2017NatSR...712170B }}</ref><ref>{{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|article-number=e11976|doi=10.7717/peerj.11976|pmid=34434669|pmc=8351573|issn=2167-8359|doi-access=free}}</ref>


In [[neuroscience]], the gamma distribution is often used to describe the distribution of [[Temporal coding|inter-spike intervals]].<ref name="Robson">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)</ref><ref name="Wright, 2015">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)</ref>
In [[neuroscience]], the gamma distribution is often used to describe the distribution of [[Temporal coding|inter-spike intervals]].<ref name="Robson">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)</ref><ref name="Wright, 2015">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)</ref>
Line 490: Line 495:
where {{math|''U''<sub>''k''</sub>}} are all uniformly distributed on (0, 1] and [[statistical independence|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.
where {{math|''U''<sub>''k''</sub>}} are all uniformly distributed on (0, 1] and [[statistical independence|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,<ref name="Devroye-1986">{{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.</ref>{{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.<ref name="Devroye-1986" />{{Rp|406}} For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter<ref name="Ahrens-1982">{{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.&nbsp;53.</ref> modified acceptance-rejection method Algorithm GD (shape {{math|''α'' ≥ 1}}), or transformation method<ref>{{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 }}</ref> when {{math|0 < ''α'' < 1}}. Also see Cheng and Feast Algorithm GKM 3<ref>{{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 }}</ref> or Marsaglia's squeeze method.<ref>Marsaglia, G. The squeeze method for generating gamma variates. Comput, Math. Appl. 3 (1977), 321–325.</ref>
Random generation of gamma variates is discussed in detail by Devroye,<ref name="Devroye-1986">{{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.</ref>{{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.<ref name="Devroye-1986" />{{Rp|406}} For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter<ref name="Ahrens-1982">{{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.&nbsp;53.</ref> modified acceptance-rejection method Algorithm GD (shape {{math|''α'' ≥ 1}}), or transformation method<ref>{{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 }}</ref> when {{math|0 < ''α'' < 1}}. Also see Cheng and Feast Algorithm GKM 3<ref>{{cite journal |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 }}</ref> or Marsaglia's squeeze method.<ref>Marsaglia, G. The squeeze method for generating gamma variates. Comput, Math. Appl. 3 (1977), 321–325.</ref>


The following is a version of the Ahrens-Dieter [[rejection sampling|acceptance–rejection method]]:<ref name="Ahrens-1982"/>
The following is a version of the Ahrens-Dieter [[rejection sampling|acceptance–rejection method]]:<ref name="Ahrens-1982"/>
Line 511: Line 516:
# If <math>v > 0</math> and <math>\ln U < \frac{X^2}2 + d - dv + d\ln v</math> return <math>dv</math>, else go back to step 2.
# If <math>v > 0</math> and <math>\ln U < \frac{X^2}2 + d - dv + d\ln v</math> return <math>dv</math>, else go back to step 2.


With <math> 1 \le a = \alpha </math> 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 ''α''&nbsp;=&nbsp;1,&nbsp;2,&nbsp;and&nbsp;4.  For {{math|''α'' < 1}}, one can use <math> \gamma_\alpha = \gamma_{1+\alpha} U^{1/\alpha}</math> to boost {{mvar|k}} to be usable with this method.
With <math> 1 \le a = \alpha </math> 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 ''α''&nbsp;=&nbsp;1,&nbsp;2,&nbsp;and&nbsp;4.  For {{math|''α'' < 1}}, one can use <math> \gamma_\alpha = \gamma_{1+\alpha} U^{1/\alpha}</math> to boost {{mvar|k}} to be usable with this method.


In [[Matlab]] numbers can be generated using the function gamrnd(), which uses the ''α'', ''θ'' representation.
In [[Matlab]] numbers can be generated using the function <code>gamrnd()</code>, which uses the ''α'', ''θ'' representation.


== References ==
== References ==

Latest revision as of 17:50, 4 November 2025

Template:Short description Template:Infobox probability distribution 2

In probability theory and statistics, the gamma distribution is a versatile two-parameter family of continuous probability distributions.[1] The exponential distribution, Erlang distribution, and chi-squared distribution are special cases of the gamma distribution.[2] There are two equivalent parameterizations in common use:

  1. With a shape parameter Template:Mvar and a scale parameter Template:Mvar
  2. With a shape parameter α and a rate parameter Template:Tmath

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.[3] 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 (both with respect to a uniform base measure and a 1/x base measure) for a random variable Template:Mvar for which Template:Math is fixed and greater than zero, and Template:Math is fixed (Template:Mvar is the digamma function).[4]

Definitions

The parameterization with Template:Mvar and Template: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[5] for an explicit motivation.

The parameterization with Template:Mvar and Template: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 Template:Mvar of an exponential distribution or a Poisson distribution[6] – or for that matter, the Template: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 Template:Mvar is a positive integer, then the distribution represents an Erlang distribution; i.e., the sum of Template:Mvar independent exponentially distributed random variables, each of which has a mean of Template:Mvar.

Characterization using shape α and rate λ

The gamma distribution can be parameterized in terms of a shape parameter Template:Math and an inverse scale parameter Template:Math, called a rate parameter. A random variable Template:Mvar that is gamma-distributed with shape Template:Mvar and rate Template:Mvar is denoted

XΓ(α,λ)Gamma(α,λ)

The corresponding probability density function in the shape-rate parameterization is

f(x;α,λ)=xα1eλxλαΓ(α) for x>0α,λ>0,

where Γ(α) is the gamma function. For all positive integers, Γ(α)=(α1)!.

The cumulative distribution function is the regularized gamma function:

F(x;α,λ)=0xf(u;α,λ)du=γ(α,λx)Γ(α),

where γ(α,λx) is the lower incomplete gamma function.

If Template:Mvar is a positive integer (i.e., the distribution is an Erlang distribution), the cumulative distribution function has the following series expansion:[7]

F(x;α,λ)=1i=0α1(λx)ii!eλx=eλxi=α(λx)ii!.

Characterization using shape α and scale θ

A random variable Template:Mvar that is gamma-distributed with shape Template:Mvar and scale Template:Mvar is denoted by

XΓ(α,θ)Gamma(α,θ)

File:Gamma-PDF-3D.png
Illustration of the gamma PDF for parameter values over Template:Mvar and Template:Mvar with Template:Mvar set to Template:Math and Template:Math. One can see each Template:Mvar layer by itself here [1] as well as by Template:Mvar [2] and Template:Mvar. [3].

The probability density function using the shape-scale parametrization is

f(x;α,θ)=xα1ex/θθαΓ(α) for x>0 and α,θ>0.

Here Template:Math is the gamma function evaluated at Template:Mvar.

The cumulative distribution function is the regularized gamma function:

F(x;α,θ)=0xf(u;α,θ)du=γ(α,xθ)Γ(α),

where γ(α,xθ) is the lower incomplete gamma function.

It can also be expressed as follows, if Template:Mvar is a positive integer (i.e., the distribution is an Erlang distribution):[7]

F(x;α,θ)=1i=0α11i!(xθ)iex/θ=ex/θi=α1i!(xθ)i.

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: σ2=αθ2=α/λ2 The square root of the inverse shape parameter gives the coefficient of variation: σ/μ=α0.5=1/α

Skewness

The skewness of the gamma distribution only depends on its shape parameter, Template:Mvar, and it is equal to 2/α.

Higher moments

The Template:Mvar-th raw moment is given by:

E[Xr]=θrΓ(α+r)Γ(α)=θrαr

with αr the rising factorial.

Median approximations and bounds

File:Gamma distribution median bounds.png
Bounds and asymptotic approximations to the median of the gamma distribution. The cyan-colored region indicates the large gap between published lower and upper bounds before 2021.

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Γ(α)θα0νxα1ex/θdx=12.

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 θ=1) α13<ν(α)<α, where μ(α)=α is the mean and ν(α) is the median of the Gamma(α,1) distribution.[8] For other values of the scale parameter, the mean scales to μ=αθ, and the median bounds and approximations would be similarly scaled by Template: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.[9] Berg and Pedersen found more terms:[10] ν(α)=α13+8405α1+18425515α2+22483444525α31900640815345358875α4𝒪(α5)+

File:Gamma distribution median Lyon bounds.png
Two gamma distribution median asymptotes which were proved in 2023 to be bounds (upper solid red and lower dashed red), of the from ν(α)21/α(A+α), and an interpolation between them that makes an approximation (dotted red) that is exact at Template:Math and has maximum relative error of about 0.6%. The cyan shaded region is the remaining gap between upper and lower bounds (or conjectured bounds), including these new bounds and the bounds in the previous figure.
File:Gamma distribution median loglog bounds.png
Log–log plot 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 Template:Mvar; they are not plotted in the figure, which is focused on the low-Template: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 Template:Mvar,[11] and that the asymptotic behavior near α=0 is ν(α)eγ21/α (where Template:Mvar is the Euler–Mascheroni constant), and that for all α>0 the median is bounded by α21/α<ν(α)<ke1/3k.[10]

A closer linear upper bound, for α1 only, was provided in 2021 by Gaunt and Merkle,[12] relying on the Berg and Pedersen result that the slope of ν(α) is everywhere less than 1: ν(α)α1+log2 for α1 (with equality at α=1) which can be extended to a bound for all α>0 by taking the max with the chord shown in the figure, since the median was proved convex.[11]

An approximation to the median that is asymptotically accurate at high Template:Mvar and reasonable down to α=0.5 or a bit lower follows from the Wilson–Hilferty transformation: ν(α)=α(119α)3 which goes negative for α<1/9.

In 2021, Lyon proposed several approximations of the form ν(α)21/α(A+Bα). He conjectured values of Template:Mvar and Template:Mvar for which this approximation is an asymptotically tight upper or lower bound for all α>0.[13] In particular, he proposed these closed-form bounds, which he proved in 2023:[14]

νL(α)=21/α(log213+α) is a lower bound, asymptotically tight as α νU(α)=21/α(eγ+α) is an upper bound, asymptotically tight as α0

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 ex: ν(α)>(2Γ(α+1))1/α (approaching equality as k0) and the tangent line at α=1 where the derivative was found to be ν(1)0.9680448: ν(α)ν(1)+(α1)ν(1) (with equality at k=1) ν(α)log2+(α1)[γ2Ei(log2)loglog2] where Ei is the exponential integral.[13][14]

Additionally, he showed that interpolations between bounds could provide excellent approximations or tighter bounds to the median, including an approximation that is exact at α=1 (where ν(1)=log2) and has a maximum relative error less than 0.6%. Interpolated approximations and bounds are all of the form ν(α)g~(α)νL(α)+(1g~(α))νU(α) where g~ is an interpolating function running monotonially from 0 at low Template:Mvar to 1 at high Template:Mvar, approximating an ideal, or exact, interpolator g(α): g(α)=νU(α)ν(α)νU(α)νL(α) For the simplest interpolating function considered, a first-order rational function g~1(α)=αb0+α the tightest lower bound has b0=8405+eγlog2log222eγlog2+13log20.143472 and the tightest upper bound has b0=eγlog2+131eγπ2120.374654 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.[13]

Summation

If Template:Math has a Template:Math distribution for Template:Math (i.e., all distributions have the same scale parameter Template:Mvar), then

i=1NXiGamma(i=1Nαi,θ)

provided all Template:Math are independent.

For the cases where the Template:Math are independent but have different scale parameters, see Mathai [15] or Moschopoulos.[16]

The gamma distribution exhibits infinite divisibility.

Scaling

If XGamma(α,θ),

then, for any Template:Math,

cXGamma(α,cθ), by moment generating functions,

or equivalently, if

XGamma(α,λ) (shape-rate parameterization)

cXGamma(α,λc),

Indeed, we know that if Template:Mvar is an exponential r.v. with rate Template:Mvar, then Template:Math is an exponential r.v. with rate Template:Math; 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 Template:Mvar divides the rate (or, equivalently, multiplies the scale).

Exponential family

The gamma distribution is a two-parameter exponential family with natural parameters Template:Math and Template:Math (equivalently, Template:Math and Template:Math), and natural statistics Template:Mvar and Template:Math.

If the shape parameter Template:Mvar is held fixed, the resulting one-parameter family of distributions is a natural exponential family.

Logarithmic expectation and variance

One can show that

E[lnX]=ψ(α)lnλ

or equivalently,

E[lnX]=ψ(α)+lnθ

where Template:Mvar is the digamma function. Likewise,

var[lnX]=ψ(1)(α)

where ψ(1) 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 Template:Math.

Information entropy

The information entropy is

H(X)=E[lnp(X)]=E[αlnλ+lnΓ(α)(α1)lnX+λX]=αlnλ+lnΓ(α)+(1α)ψ(α).

In the Template:Mvar, Template:Mvar parameterization, the information entropy is given by

H(X)=α+lnθ+lnΓ(α)+(1α)ψ(α).

Kullback–Leibler divergence

File:Gamma-KL-3D.png
Illustration of the Kullback–Leibler (KL) divergence for two gamma PDFs. Here Template:Math which are set to Template:Math and Template:Math. The typical asymmetry for the KL divergence is clearly visible.

The Kullback–Leibler divergence (KL-divergence), of Template:Math ("true" distribution) from Template:Math ("approximating" distribution) is given by[17]

DKL(αp,λp;αq,λq)=(αpαq)ψ(αp)logΓ(αp)Γ(αq)+αqlogλpλq+αp(λqλp1).

Written using the Template:Mvar, Template:Mvar parameterization, the KL-divergence of Template:Math from Template:Math is given by

DKL(αp,θp;αq,θq)=(αpαq)ψ(αp)logΓ(αp)Γ(αq)+αqlogθqθp+αp(θpθq1).

Laplace transform

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

F(s)=E[esX]=1(1+θs)α=(λλ+s)α

(where X is a random variable with that distribution).

Related distributions

General

XΓ(α,θ),YPois(xθ),
then
Pr(X>x)=Pr(Y<α).
X2Γ(32,2a2).

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.[22]

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 Template:Mvar iid observations Template:Math is

L(α,θ)=i=1Nf(xi;α,θ)

from which we calculate the log-likelihood function

(α,θ)=(α1)i=1Nlnxii=1NxiθNαlnθNlnΓ(α)

Finding the maximum with respect to Template:Mvar by taking the derivative and setting it equal to zero yields the maximum likelihood estimator of the Template:Mvar parameter, which equals the sample mean x¯ divided by the shape parameter Template:Mvar:

θ^=1αNi=1Nxi=x¯α

Substituting this into the log-likelihood function gives

(α)=(α1)i=1NlnxiNαNαlnixiαNNlnΓ(α)

We need at least two samples: N2, because for N=1, the function (α) increases without bounds as α. For α>0, it can be verified that (α) is strictly concave, by using inequality properties of the polygamma function. Finding the maximum with respect to Template:Mvar by taking the derivative and setting it equal to zero yields

lnαψ(α)=ln(1Ni=1Nxi)1Ni=1Nlnxi=lnx¯lnx

where Template:Mvar is the digamma function and lnx is the sample mean of Template:Math. There is no closed-form solution for Template: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 Template:Mvar can be found either using the method of moments, or using the approximation

lnαψ(α)12α(1+16α+1)

If we let

s=ln(1Ni=1Nxi)1Ni=1Nlnxi=lnx¯lnx

then Template:Mvar is approximately

k3s+(s3)2+24s12s

which is within 1.5% of the correct value.[23] An explicit form for the Newton–Raphson update of this initial guess is:[24]

ααlnαψ(k)s1αψ(α).

At the maximum-likelihood estimate (α^,θ^), the expected values for Template:Mvar and lnx agree with the empirical averages: α^θ^=x¯andψ(α^)+lnθ^=lnx.

Caveat for small shape parameter

For data, (x1,,xN), 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 F(x;α,θ), then the probability that there is at least one underflow is: Pr(underflow)=1(1F(ε;α,θ))N This probability will approach 1 for small Template:Mvar and large Template:Mvar. For example, at α=102, N=104 and ε=2.25×10308, Pr(underflow)0.9998. 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 α<1. Following the implementation in scipy.stats.loggamma, this can be done as follows:[25] sample YGamma(α+1,θ) and UUniform independently. Then the required logarithmic sample is Z=ln(Y)+ln(U)/α, so that exp(Z)Gamma(k,θ).

Closed-form estimators

There exist consistent closed-form estimators of Template:Mvar and Template:Mvar that are derived from the likelihood of the generalized gamma distribution.[26]

The estimate for the shape Template:Mvar is

α^=Ni=1NxiNi=1Nxilnxii=1Nxii=1Nlnxi

and the estimate for the scale Template:Mvar is

θ^=1N2(Ni=1Nxilnxii=1Nxii=1Nlnxi)

Using the sample mean of Template:Mvar, the sample mean of Template:Math, and the sample mean of the product Template:Math simplifies the expressions to:

α^=x¯θ^ θ^=xlnxx¯lnx.

If the rate parameterization is used, the estimate of λ^=1/θ^.

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 Template:Mvar is

θ~=NN1θ^

A bias correction for the shape parameter Template:Mvar is given as[27]

α~=α^1N(3α^23(α^1+α^)45α^(1+α^)2)

Bayesian minimum mean squared error

With known Template:Mvar and unknown Template:Mvar, the posterior density function for theta (using the standard scale-invariant prior for Template:Mvar) is

Pr(θα,x1,,xN)1θi=1Nf(xi;α,θ)

Denoting

yi=1Nxi,Pr(θα,x1,,xN)=C(xi)θNα1ey/θ

where the Template:Mvar (integration) constant does not depend on Template:Mvar. The form of the posterior density reveals that Template:Math is gamma-distributed with shape parameter Template:Math and rate parameter Template:Mvar. Integration with respect to Template:Mvar can be carried out using a change of variables to find the integration constant

0θNα1+mey/θdθ=0xNα1mexydx=y(Nαm)Γ(Nαm)

The moments can be computed by taking the ratio (Template:Mvar by Template:Math)

E[xm]=Γ(Nαm)Γ(Nα)ym

which shows that the mean ± standard deviation estimate of the posterior distribution for Template:Mvar is

yNα1±y2(Nα1)2(Nα2).

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 Template:Mvar, inverse gamma with known shape parameter, and Gompertz with known scale parameter.

The gamma distribution's conjugate prior is:[28]

p(α,θp,q,r,s)=1Zpα1eθ1qΓ(α)rθαs,

where Template:Mvar is the normalizing constant with no closed-form solution. The posterior distribution can be found by updating the parameters as follows:

p=pixi,q=q+ixi,r=r+n,s=s+n,

where Template:Mvar is the number of observations, and Template:Math is the Template:Mvar-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 Template:Mvar. Then the waiting time for the Template:Mvar-th event to occur is the gamma distribution with integer shape α=n. 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.[29] Examples include the waiting time of cell-division events,[30] number of compensatory mutations for a given mutation,[31] waiting time until a repair is necessary for a hydraulic system,[32] 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.[33]

The gamma distribution has been used to model the size of insurance claims[34] and rainfalls.[35] 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;Script error: No such module "Unsubst". 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.[36][37]

In neuroscience, the gamma distribution is often used to describe the distribution of inter-spike intervals.[38][39]

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.[40]

In genomics, the gamma distribution was applied in peak calling step (i.e., in recognition of signal) in ChIP-chip[41] and ChIP-seq[42] 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[43] 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 Template:Math. This parameterization means that the mean of this distribution is 1 and the variance is Template:Math. Maximum likelihood and Bayesian methods typically use a discrete approximation to the continuous gamma distribution.[44][45]

Random variate generation

Given the scaling property above, it is enough to generate gamma variables with Template:Math, as we can later convert to any value of Template:Mvar with a simple division.

Suppose we wish to generate random variables from Template:Math, where n is a non-negative integer and Template:Math. Using the fact that a Template:Math distribution is the same as an Template:Math distribution, and noting the method of generating exponential variables, we conclude that if Template:Mvar is uniformly distributed on (0, 1], then Template:Math is distributed Template:Math (i.e. inverse transform sampling). Now, using the "Template:Mvar-addition" property of gamma distribution, we expand this result:

k=1nlnUkΓ(n,1)

where Template:Math are all uniformly distributed on (0, 1] and independent. All that is left now is to generate a variable distributed as Template:Math for Template:Math and apply the "Template:Mvar-addition" property once more. This is the most difficult part.

Random generation of gamma variates is discussed in detail by Devroye,[46]Template:Rp noting that none are uniformly fast for all shape parameters. For small values of the shape parameter, the algorithms are often not valid.[46]Template:Rp For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter[47] modified acceptance-rejection method Algorithm GD (shape Template:Math), or transformation method[48] when Template:Math. Also see Cheng and Feast Algorithm GKM 3[49] or Marsaglia's squeeze method.[50]

The following is a version of the Ahrens-Dieter acceptance–rejection method:[47]

  1. Generate Template:Mvar, Template:Mvar and Template:Mvar as iid uniform (0, 1] variates.
  2. If Uee+δ then ξ=V1/δ and η=Wξδ1. Otherwise, ξ=1lnV and η=Weξ.
  3. If η>ξδ1eξ then go to step 1.
  4. Template:Mvar is distributed as Template:Math.

A summary of this is θ(ξi=1αlnUi)Γ(α,θ) where α is the integer part of Template:Mvar, Template:Mvar is generated via the algorithm above with Template:Math (the fractional part of Template:Mvar) and the Template:Math are all independent.

While the above approach is technically correct, Devroye notes that it is linear in the value of Template:Mvar and generally is not a good choice. Instead, he recommends using either rejection-based or table-based methods, depending on context.[46]Template:Rp

For example, Marsaglia's simple transformation-rejection method relying on one normal variate Template:Mvar and one uniform variate Template:Mvar:[25]

  1. Set d=a13 and c=19d.
  2. Set v=(1+cX)3.
  3. If v>0 and lnU<X22+ddv+dlnv return dv, else go back to step 2.

With 1a=α generates a gamma distributed random number in time that is approximately constant with Template:Mvar. The acceptance rate does depend on Template:Mvar, with an acceptance rate of 0.95, 0.98, and 0.99 for α = 1, 2, and 4. For Template:Math, one can use γα=γ1+αU1/α to boost Template:Mvar to be usable with this method.

In Matlab numbers can be generated using the function gamrnd(), which uses the α, θ representation.

References

Template:Reflist

External links

Template:Sister project

Template:ProbDistributions

  1. Script error: No such module "citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "Citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. a b Papoulis, Pillai, Probability, Random Variables, and Stochastic Processes, Fourth Edition
  8. 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, Template:Issn, [4] Template:Webarchive.
  9. Choi, K. P. "On the Medians of the Gamma Distributions and an Equation of Ramanujan" Template:Webarchive, Proceedings of the American Mathematical Society, Vol. 121, No. 1 (May, 1994), pp. 245–251.
  10. a b Script error: No such module "Citation/CS1".
  11. a b Berg, Christian and Pedersen, Henrik L. "Convexity of the median in the gamma distribution" Template:Webarchive.
  12. Script error: No such module "Citation/CS1".
  13. a b c Script error: No such module "Citation/CS1".
  14. a b Script error: No such module "Citation/CS1".
  15. Script error: No such module "Citation/CS1".
  16. Script error: No such module "Citation/CS1".
  17. Script error: No such module "citation/CS1".
  18. Script error: No such module "citation/CS1".
  19. Script error: No such module "citation/CS1".
  20. Script error: No such module "citation/CS1".
  21. Script error: No such module "Citation/CS1".
  22. Script error: No such module "Citation/CS1".
  23. Script error: No such module "citation/CS1".
  24. Script error: No such module "Citation/CS1".
  25. a b Script error: No such module "Citation/CS1".
  26. Script error: No such module "Citation/CS1".
  27. Script error: No such module "Citation/CS1".
  28. Fink, D. 1995 A Compendium of Conjugate Priors. In progress report: Extension and enhancement of methods for setting data quality objectives. (DOE contract 95‑831).
  29. Script error: No such module "citation/CS1".
  30. Script error: No such module "Citation/CS1".
  31. Script error: No such module "Citation/CS1".
  32. Script error: No such module "Citation/CS1".
  33. Script error: No such module "Citation/CS1".
  34. p. 43, Philip J. Boland, Statistical and Probabilistic Methods in Actuarial Science, Chapman & Hall CRC 2007
  35. Script error: No such module "Citation/CS1".
  36. Script error: No such module "Citation/CS1".
  37. Script error: No such module "Citation/CS1".
  38. 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)
  39. 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)
  40. 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.
  41. DJ Reiss, MT Facciotti and NS Baliga (2008) "Model-based deconvolution of genome-wide DNA binding", Bioinformatics, 24, 396–403
  42. MA Mendoza-Parra, M Nowicka, W Van Gool, H Gronemeyer (2013) "Characterising ChIP-seq binding patterns by model-based peak shape deconvolution" Template:Webarchive, BMC Genomics, 14:834
  43. Script error: No such module "Citation/CS1".
  44. Script error: No such module "Citation/CS1".
  45. Script error: No such module "Citation/CS1".
  46. a b c Script error: No such module "citation/CS1". See Chapter 9, Section 3.
  47. a b Script error: No such module "Citation/CS1".. See Algorithm GD, p. 53.
  48. Script error: No such module "Citation/CS1".
  49. Script error: No such module "Citation/CS1".
  50. Marsaglia, G. The squeeze method for generating gamma variates. Comput, Math. Appl. 3 (1977), 321–325.