# What are the mean and variance for the Gamma distribution?

There are two forms for the Gamma distribution, each with different definitions for the shape and scale parameters. Rather than asking what the form is used for the gsl_ran_gamma implementation, it's probably easier to ask for the associated definitions for the mean and standard deviation in terms of the shape and scale parameters.

Any pointers to definitions would be appreciated.

• Ambiguous (or missing) documentation is a red flag, because it suggests the implementers are too inexperienced to be aware there are differing conventions and that theirs needs detailed documentation. Thus, in addition to figuring out what convention is used, you would be wise to conduct thorough tests of the implementation. – whuber Jun 30 '11 at 19:19
• @whuber: the documentation provides the form of the pdf explicitly. In this case, the form given is the same as the one used in, e.g., Wikipedia. – cardinal Jun 30 '11 at 19:37
• @whuber: The GSL documentation is clear and unambiguous; user error. The HTML version I rec'd came out clear enough that I didn't suspect a problem. – Aengus Jun 30 '11 at 21:10
• @cardinal Thanks. My comment was phrased generally but responded specifically to Googling for information on "gsl_ran_gamma". The first half page of hits turned up only the vaguest sort of documentation (and the second half page turned up bunches of bug reports, albeit old ones). Perhaps you could provide a link to the pdf for the record? – whuber Jun 30 '11 at 21:31
• @whuber: I had placed a reference in the comments to the answer. But, it's currently hidden under the fold. The documentation for the gamma distribution can be found on page 230 of the current GNU Scientific Library reference manual. – cardinal Jul 1 '11 at 4:34

If the shape parameter is $k>0$ and the scale is $\theta>0$, one parameterization has density function

$$p(x) = x^{k-1} \frac{ e^{-x/\theta} }{\theta^{k} \Gamma(k)}$$

where the argument, $x$, is non-negative. A random variable with this density has mean $k \theta$ and variance $k \theta^{2}$ (this parameterization is the one used on the wikipedia page about the gamma distribution).

An alternative parameterization uses $\vartheta = 1/\theta$ as the rate parameter (inverse scale parameter) and has density

$$p(x) = x^{k-1} \frac{ \vartheta^{k} e^{-x \vartheta} }{\Gamma(k)}$$

Under this choice, the mean is $k/\vartheta$ and the variance is $k/\vartheta^{2}$.

• thanks for the quick response; any idea which form is used in gsl_ran_gamma? – Aengus Jun 30 '11 at 19:02
• No, but you could just simulate some for given values of the shape and scale and see whether the sample mean is closer to $k \theta$ or $k/\vartheta$. – Macro Jun 30 '11 at 19:12
• @Aengus: As per the documentation, GSL uses the parameterization with mean $k\theta$. In the notation of the documentation the mean would be $ab$. – cardinal Jun 30 '11 at 19:27
• @cardinal: Many thanks, I did not see that in the documentation. Very much appreciate the answer, but can you point me toward a link, etc. My search for gsl_ran_gamma was pretty unsatisfying. Absolutely not questioning the answer, but just so I don't ask something so simple again. – Aengus Jun 30 '11 at 19:43
• @Aengus: Section 20.14 of the GSL 1.14 documentation (postscript) is what I looked at. It's on page 229. Not sure if that's the most recent version, as it's from March 2010. – cardinal Jun 30 '11 at 19:51

actually, in addition to what Macro said, there is a third form for the gamma distribution With a shape parameter $v$ and a mean parameter $\mu$

$p(x\mid \mu,v) = constant \times x^{\frac{v-2}{2}} e^{-\frac{xv}{2\mu}}$

if $x \sim G(\mu,v)$ then $E(x) = \mu$ and $var(x) =\dfrac{2\mu^2}{v}$