Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

You have seen in exercises that a non-negative random variable XX has the gamma (r,λ)(r, \lambda) distribution for two positive parameters rr and λ\lambda if the density of XX is given by

fX(x) = λrΓ(r)xr1eλx,     x0f_X(x) ~ = ~ \frac{\lambda^r}{\Gamma(r)} x^{r-1}e^{-\lambda x}, ~~~~~ x \ge 0

Here

Γ(r) = 0xr1exdx\Gamma(r) ~ = ~ \int_0^\infty x^{r-1}e^{-x} dx

is the Gamma function applied to rr, and is part of the constant that makes the density integrate to 1.

As you have shown, the key fact about the Gamma function is the recursion

Γ(r+1) = rΓ(r),    r>0\Gamma(r+1) ~ = ~ r\Gamma (r), ~~~~ r > 0

which implies in particular that

Γ(r) = (r1)!    if r is a positive integer\Gamma(r) ~ = ~ (r-1)! ~~~~ \text{if } r \text{ is a positive integer}

You have put all this together to show that

E(X) = rλ              SD(X) = rλE(X) ~ = ~ \frac{r}{\lambda} ~~~~~~~~~~~~~~ SD(X) ~ = ~ \frac{\sqrt{r}}{\lambda}

You have observed that the square of a standard normal variable has the gamma (1/2,1/2)(1/2, 1/2) distribution, and that the exponential (λ)(\lambda) distribution is the same as the gamma (1,λ)(1, \lambda) distribution.

18.3.1The Rate λ\lambda

For fixed rr, the larger λ\lambda is, the smaller XX is expected to be. Also like the exponential, the parameter λ\lambda essentially identifies the units of measurement – for a positive constant cc, the random variable Y=cXY = cX has the gamma (r,λ/c)(r, \lambda/c) distribution. You can see this by applying the linear change of variable formula for densities. For positive yy, the density of YY is

fY(y) = fX(yc)1c = (λ/c)rΓ(r)yr1e(λ/c)yf_Y(y) ~ = ~ f_X(\frac{y}{c}) \cdot \frac{1}{c} ~ = ~ \frac{(\lambda/c)^r}{\Gamma(r)} y^{r-1}e^{-(\lambda/c) y}

SciPy calls 1/λ1/\lambda the “scale” parameter of the gamma distribution. Because the parameter just determines the scale on the horizontal axis of the graph of the density, it is often taken to be 1. That’s what we will do to study the other parameter rr.

18.3.2The Shape Parameter rr

Here are the graphs of the gamma (r,1)(r, 1) densities for r=1r = 1, 1.5, and 2.

<matplotlib.figure.Figure at 0x106f88dd8>

When r=1r = 1 the density is exponential. As rr gets larger the density moves to the right and flattens out, consistent with the increasing mean rr and SD r\sqrt{r}.

You can see why the gamma family is used for modeling right-skewed distributions. However, when r=10r = 10, the gamma density looks almost normal. To see why, we will examine sums of independent gamma variables.

<matplotlib.figure.Figure at 0x1a15498358>

18.3.3Sums of Independent Gamma Variables with the Same Rate

If XX has the gamma (r,λ)(r, \lambda) distribution and YY independent of XX has the gamma (s,λ)(s, \lambda) distribution, then X+YX+Y has the gamma (r+s,λ)(r+s, \lambda) distribution.

Note that for the result to apply, the rate parameter has to be the same for XX and YY. The rate parameter turns out to be the same for X+YX+Y as well, and the shape parameters add up.

We will prove this result in the next chapter along with the corresponding result for sums of independent normal variables. For now, let’s test out the result by simulation just as we did with the sums of normals. The first three lines in the cell below set the values of λ\lambda, rr, and ss. The rest simulates 10000 values of X+YX+Y and plots the gamma (r+s,λ)(r+s, \lambda) density over the simulated values.

# Change these three parameters as you wish.
lam = 1
r = 3
s = 7

# Leave the rest of the code alone.
x = stats.gamma.rvs(r, scale=1/lam, size=10000)
y = stats.gamma.rvs(s, scale=1/lam, size=10000)
w = x+y
Table().with_column('X+Y', w).hist(bins=20)
t = np.arange(min(w), max(w)+0.1, (max(w) - min(w))/100)
dens = stats.gamma.pdf(t, r+s, scale=1/lam)
plt.plot(t, dens, color='red', lw=2, label='gamma $(r+s, \lambda)$')
plt.legend()
plt.title('$X$ is gamma$(r, \lambda)$; $Y$ is gamma$(s, \lambda)$ independent of $X$');
<matplotlib.figure.Figure at 0x1a1593c7f0>
🎥 See More
Loading...

18.3.4Integer Shape Parameter

One of the two most important branches of the gamma family consists of gamma distributions that have an integer as the shape parameter.

Suppose T1,T2,T3,T_1, T_2, T_3, \ldots are i.i.d. exponential (λ)(\lambda) variables. Then each of them has the gamma (1,λ)(1, \lambda) distribution. These are the fundamental members of the “integer shape parameter” branch.

By the fact we observed about sums of independent gamma variables, for all integers rr the sum Sr=T1+T2++TrS_r = T_1 + T_2 + \cdots + T_r has the gamma (r,λ)(r, \lambda) distribution. These are the other members of the branch.

You can now see why the gamma (r,λ)(r, \lambda) distribution is approximately normal for large rr. For integer rr, the sum of rr i.i.d. exponential (λ)(\lambda) random variables has the gamma (r,λ)(r, \lambda) distribution. For fixed λ\lambda and large rr, the Central Limit Theorem says the distribution of the sum is approximately normal.

Gamma distributions with integer shape parameter are a fundamental part of a stochastic process called a Poisson process which you will examine in exercises.

The other important branch of the gamma family is the topic of the next section.