Gamma distribution
Template:Short description Template:Infobox probability distribution 2</math> | kurtosis = <math>\frac{6}{\alpha}</math> | entropy = <math>\begin{align}
\alpha &+ \ln\theta + \ln\Gamma(\alpha)\\ &+ (1 - \alpha)\psi(\alpha) \end{align}</math>
| mgf = <math>(1 - \theta t)^{-\alpha} \text{ for } t < \frac{1}{\theta}</math> | char = <math>(1 - \theta it)^{-\alpha}</math> | parameters2 = Template:Bulleted list | support2 = <math>x \in (0, \infty)</math> | pdf2 = <math>f(x)=\frac{\lambda^\alpha}{\Gamma(\alpha)} x^{\alpha - 1} e^{-\lambda x }</math> | cdf2 = <math>F(x)=\frac{1}{\Gamma(\alpha)} \gamma(\alpha, \lambda x)</math> | mean2 = <math>\frac{\alpha}{\lambda}</math> | median2 = No simple closed form | mode2 = <math>\frac{\alpha - 1}{\lambda} \text{ for } \alpha \geq 1\text{, }0 \text{ for } \alpha < 1</math> | variance2 = <math>\frac{\alpha}{\lambda^2}</math> | skewness2 = <math>\frac{2}{\sqrt{\alpha}}</math> | kurtosis2 = <math>\frac{6}{\alpha}</math> | entropy2 = <math>\begin{align}
\alpha &- \ln \lambda + \ln\Gamma(\alpha)\\ &+ (1 - \alpha)\psi(\alpha) \end{align}</math>
| mgf2 = <math>\left(1 - \frac{t}{\lambda}\right)^{-\alpha} \text{ for } t < \lambda</math> | char2 = <math>\left(1 - \frac{it}{\lambda}\right)^{-\alpha}</math> | moments = <math> \alpha = \frac{E[X]^2}{V[X]}, </math> <math> \theta = \frac{V[X]}{E[X]} \quad \quad</math> | moments2 = <math> \alpha = \frac{E[X]^2}{V[X]}, </math> <math>\lambda = \frac{E[X]}{V[X]} </math> | fisher = <math>I(\alpha, \theta) = \begin{pmatrix}\psi^{(1)}(\alpha) & \theta^{-1} \\ \theta^{-1} & \alpha \theta^{-2}\end{pmatrix}</math> | fisher2 = <math>I(\alpha, \lambda) = \begin{pmatrix}\psi^{(1)}(\alpha) & -\lambda^{-1} \\ -\lambda^{-1} & \alpha \lambda^{-2}\end{pmatrix}</math> }}
In probability theory and statistics, the gamma distribution is a versatile two-parameter family of continuous probability distributions.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The exponential distribution, Erlang distribution, and chi-squared distribution are special cases of the gamma distribution.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> There are two equivalent parameterizations in common use:
- With a shape parameter Template:Mvar and a scale parameter Template:Mvar
- With a shape parameter <math>\alpha</math> 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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</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>{{#invoke:citation/CS1|citation |CitationClass=web }}</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 Template:Mvar for which Template:Math is fixed and greater than zero, and Template:Math is fixed (Template:Mvar is the digamma function).<ref>Template:Cite journal</ref>
DefinitionsEdit
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<ref>Template:Cite book</ref> 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<ref>Template:Cite arXiv</ref> – 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 λEdit
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
<math display=block>X \sim \Gamma(\alpha, \lambda) \equiv \operatorname{Gamma}(\alpha,\lambda)</math>
The corresponding probability density function in the shape-rate parameterization is
<math display=block> \begin{align} f(x;\alpha,\lambda) & = \frac{ x^{\alpha-1} e^{-\lambda x} \lambda^\alpha}{\Gamma(\alpha)} \quad \text{ for } x > 0 \quad \alpha, \lambda > 0, \\[6pt] \end{align} </math>
where <math>\Gamma(\alpha)</math> is the gamma function. For all positive integers, <math>\Gamma(\alpha)=(\alpha-1)!</math>.
The cumulative distribution function is the regularized gamma function:
<math display=block> F(x;\alpha,\lambda) = \int_0^x f(u;\alpha,\lambda)\,du= \frac{\gamma(\alpha, \lambda x)}{\Gamma(\alpha)},</math>
where <math>\gamma(\alpha, \lambda x)</math> 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:<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>
Characterization using shape α and scale θEdit
A random variable Template:Mvar that is gamma-distributed with shape Template:Mvar and scale Template:Mvar is denoted by
<math display=block>X \sim \Gamma(\alpha, \theta) \equiv \operatorname{Gamma}(\alpha, \theta)</math>
The probability density function using the shape-scale parametrization is
<math display=block>f(x;\alpha,\theta) = \frac{x^{\alpha-1}e^{-x/\theta}}{\theta^\alpha\Gamma(\alpha)} \quad \text{ for } x > 0 \text{ and } \alpha, \theta > 0.</math>
Here Template:Math is the gamma function evaluated at Template:Mvar.
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>
where <math>\gamma\left(\alpha, \frac{x}{\theta}\right)</math> 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):<ref name="Papoulis">Papoulis, Pillai, Probability, Random Variables, and Stochastic Processes, Fourth Edition</ref>
<math display=block>F(x;\alpha,\theta) = 1-\sum_{i=0}^{\alpha-1} \frac{1}{i!} \left(\frac{x}{\theta} \right)^i e^{-x/\theta} = e^{-x/\theta} \sum_{i=\alpha}^\infty \frac{1}{i!} \left( \frac{x}{\theta} \right)^i.</math>
Both parametrizations are common because either can be more convenient depending on the situation.
PropertiesEdit
Mean and varianceEdit
The mean of gamma distribution is given by the product of its shape and scale parameters: <math display=block>\mu = \alpha\theta = \alpha/\lambda</math> The variance is: <math display=block>\sigma^2 = \alpha \theta^2 = \alpha/\lambda^2</math> The square root of the inverse shape parameter gives the coefficient of variation: <math display=block>\sigma/\mu = \alpha^{-0.5} = 1/\sqrt{\alpha}</math>
SkewnessEdit
The skewness of the gamma distribution only depends on its shape parameter, Template:Mvar, and it is equal to <math>2/\sqrt{\alpha}.</math>
Higher momentsEdit
The Template:Mvar-th raw moment is given by: <math display=block> \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. </math>
Median approximations and boundsEdit
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 <math>\nu</math> such that <math display=block>\frac{1}{\Gamma(\alpha) \theta^\alpha} \int_0^{\nu} x^{\alpha - 1} e^{-x/\theta} dx = \frac{1}{2}.</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> 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, Template:Issn, [4] Template:Webarchive.</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 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 <math> \theta </math> function.<ref>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.</ref> Berg and Pedersen found more terms:<ref name="Pedersen, Henrik L.-2006">Template:Cite journal</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>
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,<ref name="Berg">Berg, Christian and Pedersen, Henrik L. "Convexity of the median in the gamma distribution" Template:Webarchive.</ref> and that the asymptotic behavior near <math>\alpha = 0</math> is <math>\nu(\alpha) \approx e^{-\gamma}2^{-1/\alpha}</math> (where Template: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>Template:Cite journal</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>) 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"/>
An approximation to the median that is asymptotically accurate at high Template:Mvar and reasonable down to <math>\alpha = 0.5</math> or a bit lower follows from the Wilson–Hilferty transformation: <math display=block> \nu(\alpha) = \alpha \left( 1 - \frac{1}{9\alpha} \right)^3 </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 Template:Mvar and Template:Mvar for which this approximation is an asymptotically tight upper or lower bound for all <math>\alpha > 0</math>.<ref name="Lyon-2021a">Template:Cite journal</ref> In particular, he proposed these closed-form bounds, which he proved in 2023:<ref name="Lyon-2021b">Template:Cite journal</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_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 expressions, 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>) 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 \log 2 + (\alpha-1) (\gamma - 2 \operatorname{Ei}(-\log 2) - \log \log 2)</math> where Ei is the exponential integral.<ref name="Lyon-2021a"/><ref name="Lyon-2021b"/>
Additionally, he showed that interpolations between bounds could provide excellent approximations or tighter bounds to the median, including an approximation that is exact at <math>\alpha = 1</math> (where <math>\nu(1) = \log 2</math>) and has a maximum relative error less than 0.6%. Interpolated approximations and bounds are all of the form <math display=block>\nu(\alpha) \approx \tilde{g}(\alpha)\nu_{L\infty}(\alpha) + (1 - \tilde{g}(\alpha)) \nu_U(\alpha)</math> where <math>\tilde{g}</math> is an interpolating function running monotonially from 0 at low Template:Mvar to 1 at high Template:Mvar, approximating an ideal, or exact, interpolator <math>g(\alpha)</math>: <math display=block>g(\alpha) = \frac{\nu_U(\alpha) - \nu(\alpha)}{\nu_U(\alpha) - \nu_{L\infty}(\alpha)}</math> For the simplest interpolating function considered, a first-order rational function <math display=block>\tilde{g}_1(\alpha) = \frac{\alpha}{b_0 + \alpha}</math> the tightest lower bound has <math display=block>b_0 = \frac{\frac{8}{405} + e^{-\gamma} \log 2 - \frac{\log^2 2}{2}}{e^{-\gamma} - \log 2 + \frac{1}{3}} - \log 2 \approx 0.143472</math> and the tightest upper bound has <math display=block>b_0 = \frac{e^{-\gamma} - \log 2 + \frac{1}{3}}{1 - \frac{e^{-\gamma} \pi^2}{12}} \approx 0.374654</math> 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.<ref name="Lyon-2021a"/>
SummationEdit
If Template:Math has a Template:Math distribution for Template:Math (i.e., all distributions have the same scale parameter Template:Mvar), then
<math display=block> \sum_{i=1}^N X_i \sim\mathrm{Gamma} \left( \sum_{i=1}^N \alpha_i, \theta \right)</math>
provided all Template:Math are independent.
For the cases where the Template:Math are independent but have different scale parameters, see Mathai <ref>Template:Cite journal</ref> or Moschopoulos.<ref>Template:Cite journal</ref>
The gamma distribution exhibits infinite divisibility.
ScalingEdit
If <math display=block>X \sim \mathrm{Gamma}(\alpha, \theta),</math>
then, for any Template:Math,
<math display=block>cX \sim \mathrm{Gamma}(\alpha, c\,\theta),</math> by moment generating functions,
or equivalently, if
<math display=block>X \sim \mathrm{Gamma}\left( \alpha,\lambda \right)</math> (shape-rate parameterization)
<math display=block>cX \sim \mathrm{Gamma}\left( \alpha, \frac \lambda c \right),</math>
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 familyEdit
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 varianceEdit
One can show that
<math display=block>\operatorname{E}[\ln X] = \psi(\alpha) - \ln \lambda</math>
or equivalently,
<math display=block>\operatorname{E}[\ln X] = \psi(\alpha) + \ln \theta</math>
where Template:Mvar is the digamma function. Likewise,
<math display="block">\operatorname{var}[\ln X] = \psi^{(1)}(\alpha)</math>
where <math>\psi^{(1)}</math> 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 entropyEdit
The information entropy is
<math display=block> \begin{align} \operatorname{H}(X) & = \operatorname{E}[-\ln p(X)] \\[4pt] & = \operatorname{E}[-\alpha \ln \lambda + \ln \Gamma(\alpha) - (\alpha-1)\ln X + \lambda X] \\[4pt] & = \alpha - \ln \lambda + \ln \Gamma(\alpha) + (1-\alpha)\psi(\alpha). \end{align} </math>
In the Template:Mvar, Template:Mvar parameterization, the information entropy is given by
<math display=block>\operatorname{H}(X) =\alpha + \ln \theta + \ln \Gamma(\alpha) + (1-\alpha)\psi(\alpha).</math>
Kullback–Leibler divergenceEdit
The Kullback–Leibler divergence (KL-divergence), of Template:Math ("true" distribution) from Template:Math ("approximating" distribution) is given by<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
<math display=block> \begin{align} D_{\mathrm{KL}}(\alpha_p,\lambda_p; \alpha_q, \lambda_q) = {} & (\alpha_p-\alpha_q) \psi(\alpha_p) - \log\Gamma(\alpha_p) + \log\Gamma(\alpha_q) \\ & {} + \alpha_q(\log \lambda_p - \log \lambda_q) + \alpha_p\frac{\lambda_q-\lambda_p}{\lambda_p}. \end{align} </math>
Written using the Template:Mvar, Template:Mvar parameterization, the KL-divergence of Template:Math from Template:Math is given by
<math display=block> \begin{align} D_{\mathrm{KL}}(\alpha_p,\theta_p; \alpha_q, \theta_q) = {} & (\alpha_p-\alpha_q)\psi(\alpha_p) - \log\Gamma(\alpha_p) + \log\Gamma(\alpha_q) \\ & {} + \alpha_q(\log \theta_q - \log \theta_p) + \alpha_p \frac{\theta_p - \theta_q}{\theta_q}. \end{align} </math>
Laplace transformEdit
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>
(where <math display=inline>X</math> is a random variable with that distribution).
Related distributionsEdit
GeneralEdit
- 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 Template: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 Template:Math (in the shape–rate parametrization), then Template:Mvar has an exponential distribution with rate parameter Template:Mvar. In the shape-scale parametrization, Template:Math has an exponential distribution with rate parameter Template:Math.
- If Template:Math (in the shape–scale parametrization), then Template:Mvar is identical to Template:Math, the chi-squared distribution with Template:Mvar degrees of freedom. Conversely, if Template:Math and Template:Mvar is a positive constant, then Template:Math.
- If Template:Math, one obtains the Schulz-Zimm distribution, which is most prominently used to model polymer chain lengths.
- If Template:Mvar is an integer, the gamma distribution is an Erlang distribution and is the probability distribution of the waiting time until the Template:Mvar-th "arrival" in a one-dimensional Poisson process with intensity Template:Math. If
- <math>X \sim \Gamma(\alpha \in \mathbf{Z}, \theta), \qquad Y \sim \operatorname{Pois}\left(\frac x \theta \right),</math>
- then
- <math>P(X > x) = P(Y < \alpha).</math>
- If Template:Mvar has a Maxwell–Boltzmann distribution with parameter Template:Mvar, then
- <math>X^2 \sim \Gamma\left(\frac{3}{2}, 2a^2\right).</math>
- If Template:Math, then <math display=inline>\log X</math> follows an exponential-gamma (abbreviated exp-gamma) distribution.<ref>{{#invoke:citation/CS1|citation
|CitationClass=web }}</ref> It is sometimes referred to as the log-gamma distribution.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Formulas for its mean and variance are in the section #Logarithmic expectation and variance.
- If Template:Math, then <math>\sqrt{X}</math> follows a generalized gamma distribution with parameters Template:Math, Template:Math, and <math>a = \sqrt{\theta}</math> Template:Citation needed.
- More generally, if Template:Math, then <math>X^q</math> for <math>q > 0</math> follows a generalized gamma distribution with parameters Template:Math, Template:Math, and <math>a = \theta^q</math>.
- If Template:Math with shape Template:Mvar and scale Template:Mvar, then Template:Math (see Inverse-gamma distribution for derivation).
- Parametrization 1: If <math>X_k \sim \Gamma(\alpha_k,\theta_k)\,</math> are independent, then <math> \frac{\alpha_2\theta_2 X_1}{\alpha_1\theta_1 X_2} \sim \mathrm{F}(2\alpha_1, 2\alpha_2)</math>, or equivalently, <math>\frac{X_1}{X_2} \sim \lambda'\left(\alpha_1, \alpha_2, 1, \frac{\theta_1}{\theta_2}\right)</math>
- Parametrization 2: If <math>X_k \sim \Gamma(\alpha_k,\lambda_k)\,</math> are independent, then <math> \frac{\alpha_2\lambda_1 X_1}{\alpha_1\lambda_2 X_2} \sim \mathrm{F}(2\alpha_1, 2\alpha_2)</math>, or equivalently, <math>\frac{X_1}{X_2} \sim \lambda'\left(\alpha_1, \alpha_2, 1, \frac{\lambda_2}{\lambda_1}\right)</math>
- If Template:Math and Template:Math are independently distributed, then Template:Math has a beta distribution with parameters Template:Mvar and Template:Mvar, and Template:Math is independent of Template:Math, which is Template:Math-distributed.
- If <math>X_n \sim \text{Beta}(\alpha,n\lambda)\,</math> and <math>Y_n = nX_n</math>, then <math>Y_n</math> converges in distribution to <math>\text{Gamma}(\alpha,\lambda)</math> defined under parametrization 2.
- If Template:Math are independently distributed, then the vector (Template:Math, where Template:Math, follows a Dirichlet distribution with parameters Template:Math.
- For large Template:Mvar the gamma distribution converges to normal distribution with mean Template:Math and variance Template:Math.
- The gamma distribution is the conjugate prior for the precision of the normal distribution with known mean.
- The matrix gamma distribution and the Wishart distribution are multivariate generalizations of the gamma distribution (samples are positive-definite matrices rather than positive real numbers).
- The gamma distribution is a special case of the generalized gamma distribution, the generalized integer gamma distribution, and the generalized inverse Gaussian distribution.
- Among the discrete distributions, the negative binomial distribution is sometimes considered the discrete analog of the gamma distribution.
- Tweedie distributions – the gamma distribution is a member of the family of Tweedie exponential dispersion models.
- Modified Half-normal distribution – the Gamma distribution is a member of the family of Modified half-normal distribution.<ref>Template:Cite journal</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.
Compound gammaEdit
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.<ref name="Dubey-1970">Template:Cite journal</ref>
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 countEdit
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 inferenceEdit
Parameter estimationEdit
Maximum likelihood estimationEdit
The likelihood function for Template:Mvar iid observations Template:Math is
<math display=block>L(\alpha, \theta) = \prod_{i=1}^N f(x_i;\alpha,\theta)</math>
from which we calculate the log-likelihood function
<math display=block>\ell(\alpha, \theta) = (\alpha - 1) \sum_{i=1}^N \ln x_i - \sum_{i=1}^N \frac{x_i} \theta - N\alpha\ln \theta - N\ln \Gamma(\alpha)</math>
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 <math>\bar{x}</math> divided by the shape parameter Template:Mvar:
<math display=block>\hat{\theta} = \frac{1}{\alpha N}\sum_{i=1}^N x_i = \frac{\bar{x}}{\alpha}</math>
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>
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, 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
<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>
where Template:Mvar is the digamma function and <math>\overline{\ln x}</math> 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
<math display=block>\ln \alpha - \psi(\alpha) \approx \frac{1}{2\alpha}\left(1 + \frac{1}{6\alpha + 1} \right)</math>
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>
then Template:Mvar is approximately
<math display=block>k \approx \frac{3 - s + \sqrt{(s - 3)^2 + 24s}}{12s}</math>
which is within 1.5% of the correct value.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> An explicit form for the Newton–Raphson update of this initial guess is:<ref>Template:Cite journal</ref>
<math display=block>\alpha \leftarrow \alpha - \frac{ \ln \alpha - \psi(k) - s }{ \frac 1 \alpha - \psi\prime(\alpha) }.</math>
At the maximum-likelihood estimate <math>(\hat \alpha,\hat\theta)</math>, the expected values for Template:Mvar and <math>\ln x</math> agree with the empirical averages: <math display=block> \begin{align} \hat \alpha\hat\theta &= \bar x &&\text{and} & \psi(\hat \alpha)+\ln \hat\theta &= \overline{\ln x}. \end{align} </math>
Caveat for small shape parameterEdit
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> P(\text{underflow}) = 1-(1-F(\varepsilon;\alpha,\theta))^N </math> This probability will approach 1 for small Template:Mvar and large Template:Mvar. 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.
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 scipy.stats.loggamma
, 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>.
Closed-form estimatorsEdit
There exist consistent closed-form estimators of Template:Mvar and Template:Mvar that are derived from the likelihood of the generalized gamma distribution.<ref>Template:Cite journal</ref>
The estimate for the shape Template: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>
and the estimate for the scale Template:Mvar is
<math display=block>\hat{\theta} = \frac{1}{N^2} \left(N \sum_{i=1}^N x_i \ln x_i - \sum_{i=1}^N x_i \sum_{i=1}^N \ln x_i\right) </math>
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:
<math display=block>\hat{\alpha} = \bar{x} / \hat{\theta}</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>.
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
<math display=block>\tilde{\theta} = \frac{N}{N - 1} \hat{\theta}</math>
A bias correction for the shape parameter Template:Mvar is given as<ref>Template:Cite journal</ref>
<math display=block>\tilde{\alpha} = \hat{\alpha} - \frac{1}{N} \left(3 \hat{\alpha} - \frac{2}{3} \left(\frac{\hat{\alpha}}{1 + \hat{\alpha}}\right) - \frac{4}{5} \frac{\hat{\alpha}}{(1 + \hat{\alpha})^2} \right) </math>
Bayesian minimum mean squared errorEdit
With known Template:Mvar and unknown Template:Mvar, the posterior density function for theta (using the standard scale-invariant prior for Template: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>
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>
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
<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>
The moments can be computed by taking the ratio (Template:Mvar by Template:Math)
<math display=block>\operatorname{E} [x^m] = \frac {\Gamma (N\alpha - m)} {\Gamma(N\alpha)} y^m</math>
which shows that the mean ± standard deviation estimate of the posterior distribution for Template:Mvar is
<math display=block> \frac y {N\alpha - 1} \pm \sqrt{\frac {y^2} {(N\alpha - 1)^2 (N\alpha - 2)}}. </math>
Bayesian inferenceEdit
Conjugate priorEdit
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:<ref name="Fink">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).</ref>
<math display=block>p(\alpha,\theta \mid p, q, r, s) = \frac{1}{Z} \frac{p^{\alpha-1} e^{-\theta^{-1} q}}{\Gamma(\alpha)^r \theta^{\alpha s}},</math>
where Template:Mvar is the normalizing constant with no closed-form solution. The posterior distribution can be found by updating the parameters as follows:
<math display=block>\begin{align}
p' &= p\prod\nolimits_i x_i,\\ q' &= q + \sum\nolimits_i x_i,\\ r' &= r + n,\\ s' &= s + n,
\end{align}</math>
where Template:Mvar is the number of observations, and Template:Math is the Template:Mvar-th observation from the gamma distribution.
Occurrence and applicationsEdit
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 <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>Template:Cite book</ref> Examples include the waiting time of cell-division events,<ref>Template:Cite journal</ref> number of compensatory mutations for a given mutation,<ref>Template:Cite journal</ref> waiting time until a repair is necessary for a hydraulic system,<ref>Template:Cite journal</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>Template:Cite journal</ref>
The gamma distribution has been used to model the size of insurance claims<ref>p. 43, Philip J. Boland, Statistical and Probabilistic Methods in Actuarial Science, Chapman & Hall CRC 2007</ref> and rainfalls.<ref>Template:Cite journal</ref> 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;Template:Citation needed 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.<ref>Template:Cite journal</ref><ref>Template:Cite journal</ref>
In neuroscience, the gamma distribution is often used to describe the distribution of 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 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.<ref name="Friedman">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.</ref>
In genomics, the gamma distribution was applied in peak calling step (i.e., in recognition of signal) in ChIP-chip<ref name="DJ Reiss">DJ Reiss, MT Facciotti and NS Baliga (2008) "Model-based deconvolution of genome-wide DNA binding", Bioinformatics, 24, 396–403</ref> and ChIP-seq<ref name="MA Mendoza">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</ref> 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<ref>Template:Cite journal</ref> 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.<ref>Template:Cite journal</ref><ref>Template:Cite journal</ref>
Random variate generationEdit
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:
<math display=block>-\sum_{k=1}^n \ln U_k \sim \Gamma(n, 1)</math>
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,<ref name="Devroye-1986">Template:Cite book See Chapter 9, Section 3.</ref>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.<ref name="Devroye-1986" />Template:Rp For arbitrary values of the shape parameter, one can apply the Ahrens and Dieter<ref name="Ahrens-1982">Template:Cite journal. See Algorithm GD, p. 53.</ref> modified acceptance-rejection method Algorithm GD (shape Template:Math), or transformation method<ref>Template:Cite journal</ref> when Template:Math. Also see Cheng and Feast Algorithm GKM 3<ref>Template:Cite journal</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 acceptance–rejection method:<ref name="Ahrens-1982"/>
- Generate Template:Mvar, Template:Mvar and Template:Mvar as iid uniform (0, 1] variates.
- If <math>U\le\frac e {e+\delta}</math> then <math>\xi=V^{1/\delta}</math> and <math>\eta=W\xi^{\delta-1}</math>. Otherwise, <math>\xi=1-\ln V</math> and <math>\eta=We^{-\xi}</math>.
- If <math>\eta>\xi^{\delta-1}e^{-\xi}</math> then go to step 1.
- Template:Mvar is distributed as Template:Math.
A summary of this is <math display=block> \theta \left( \xi - \sum_{i=1}^{\lfloor \alpha \rfloor} \ln U_i \right) \sim \Gamma (\alpha, \theta)</math> where <math>\scriptstyle \lfloor \alpha \rfloor</math> 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.<ref name="Devroye-1986"/>Template:Rp
For example, Marsaglia's simple transformation-rejection method relying on one normal variate Template:Mvar and one uniform variate Template:Mvar:<ref name="Marsaglia-2000">Template:Cite journal</ref>
- Set <math>d = a - \frac13</math> and <math>c = \frac1{\sqrt{9d}}</math>.
- Set <math>v=(1+cX)^3</math>.
- 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 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 <math> \gamma_\alpha = \gamma_{1+\alpha} U^{1/\alpha}</math> to boost Template:Mvar to be usable with this method.
In Matlab numbers can be generated using the function gamrnd(), which uses the α, θ representation.
ReferencesEdit
External linksEdit
- Template:Springer
- {{#invoke:Template wrapper|{{#if:|list|wrap}}|_template=cite web
|_exclude=urlname, _debug, id |url = https://mathworld.wolfram.com/{{#if:GammaDistribution%7CGammaDistribution.html}} |title = Gamma distribution |author = Weisstein, Eric W. |website = MathWorld |access-date = |ref = Template:SfnRef }}