Derivation of the Gamma Distribution

Deriving Gamma from Poisson waiting times for an integer event count, then extending the shape parameter beyond integers.

Alright, time to move on to the Gamma distribution!

Funny thing — the Γ-distribution is actually a cousin of the exponential distribution!!!!

Why? Well, the exponential distribution was the waiting time until the first Poisson event in a Poisson process with mean λ,

right????????

Poisson process — quick refresher:

For events that happen randomly over time,

  1. the counts of events in non-overlapping intervals are mutually independent, and

  2. the probability that a single event occurs in a tiny time interval is proportional to the length of that interval, and

  3. the probability that two or more events occur in a tiny time interval is negligible, and

  4. the above conditions hold the same way over the entire time span,

then we call it a Poisson process.

The Gamma distribution

for a positive integer $\alpha$, is the waiting-time distribution until the $\alpha$-th event of a homogeneous Poisson process with rate $\lambda>0$!!!! This integer-shape case is also called Erlang. The Gamma density extends to every real $\alpha>0$, but a noninteger shape is not a literal fractional event count.

Let me just drop the definition first,

Equation from the original notes

OK… now let’s derive it real quick!!!!

I’m going to follow the exact same playbook as when I derived the exponential distribution!!

Let’s think about the cumulative distribution.

The Poisson distribution was

Equation from the original notes

that one.

This is “the Poisson distribution that says, on average, λ events happen per unit time,” and

then “the Poisson distribution that says, on average, λt events happen over time t” is

Equation from the original notes

like that, and

inside this distribution, the probability of 0 events, the probability of 1 event, ~~~~~~~~~, the probability of α-1 events, and the probability of α events

are g(0), g(1), ~~~~~~~~~~, g(α-1), g(α).

<Wait!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>

Let me pin something down here.

In the Gamma distribution, what feels meaningful is that

λ is meaningful

AND α is also meaningful!!!!

Which Poisson distribution it came from matters — i.e. how many events on average per time t,

and how many events we’re waiting for ALSO matters!?!??!

I’ll unmask these guys properly at the very end.

OK so — since I want to recast this as “the time until the α-th event happens,”

(same trick as in the exponential derivation) I’ll sum up all the probabilities up through “the α-1-th event has happened.”

Equation from the original notes

What this means is

Equation from the original notes

this is what it’s saying!!!!!!

Now treat the variable as time!!!?

Fewer than $\alpha$ events by time $t$ means the wait is longer than $t$: that sum is the survival probability $P(T_\alpha>t)$. The CDF is its complement, $P(T_\alpha\le t)=1-P(N(t)\lt\alpha)$, as the next formula shows!

OK so let’s call this cumulative probability F(t)!

Equation from the original notes

Differentiate this and bam — it’s the pdf!!!?!??!

Now for the differentiation, bye-bye formula editor~!

I’m switching to photos…….

heh heh heh sorry heh heh heh heh

The formula editor is just too… (T_T).

Equation from the original notes

Equation from the original notes

Equation from the original notes

That’s where I got to!!

If we leave that factorial in the denominator like that, the expression is only defined when (α-1) is 0 or a positive integer,

so let’s bring in the Gamma function and write it more generally!!!

(I derived it over here → Stirling’s Formula and Stirling’s Approximation (Thermal & Statistical Mechanics I Studied #1) !!!!)

Equation from the original notes

I’ll just throw out the definition of the Gamma function here!

Equation from the original notes

There it is. So now the formula above can be rewritten using the Gamma function!

Equation from the original notes

Let me say it one more time!?!?!? What does f(t) mean?!?!?!?!?

It is a probability density, not the probability at the single time $t$. For a tiny interval, $P(t\lt T_\alpha\lt t+dt)\approx f(t)\,dt$; for this continuous wait, $P(T_\alpha=t)=0$.

cf.) With $\alpha=1$, $f(t)=\lambda e^{-\lambda t}$ is the density of the wait until the first event,

i.e. it collapses right back into the exponential distribution… (sob)!

OK, since this is the home stretch, let me finally unmask α and λ.

These are the two ‘parameters’ of the Gamma distribution.

Parameters~??~??~?

What on earth ARE those~?!?

In Korean that was ‘모수 (mosu)? 이게 뭐수 (mwosu)?’ — ‘Parameters? What’s this, then?’ A silly near-rhyme.

Sorry sorry.

How do I put parameters into words???

If I say “the characteristics of the population?” — that doesn’t really land, right?

Take the Gaussian distribution we all know and love — it also has 2 parameters,

namely the mean and the variance (the values of μ and σ in the Gaussian function are what set the shape and the personality of that particular Gaussian, right?)

Same deal here — what fixes the shape and personality of a Gamma distribution is its parameters, which in this case are λ and α!!!

So what I’m trying to say is:

Equation from the original notes

when something follows a Gamma distribution like this,

it means “the random variable t follows a Gamma distribution with parameters (α, λ)” — that’s how we say it~~~

Here $\alpha$ is the shape and $\lambda$ is the rate, with $t\ge0$. If we use a scale instead, it is $\theta=1/\lambda$, as shown in the formula above. Rate and scale are reciprocal, so keep the convention straight!

My original advice was ‘I’ll skip shape and scale — self-study, go go~~~’ lol. The short explanation above saves us from mixing up scale and rate before moving on.

First let’s check that the integral over the whole domain of the Gamma distribution is 1.

The integral of a probability density over its full domain has to be 1, right?!~

Because all the probabilities have to sum to 1! let’s go let’s go let’s go

Equation from the original notes

Equation from the original notes

Equation from the original notes

OK, let me wrap up by talking about ‘additivity’!

We said that if a random variable follows

Equation from the original notes

then “the random variable x follows a Gamma distribution with parameters (α, λ),” right????

And we showed that α=1 collapses it back to the exponential distribution.

For this sum-of-exponential-waits proof, take a positive integer $\alpha$, so there are $\alpha$ random variables X_1, X_2, ….. , X_α,

each one mutually independent and following an exponential distribution with parameter λ!!!

(You can already kinda feel where this is going, right??? If you can feel it — that feeling IS the Gamma distribution….!!! Sorry!!!!!!!!!!!!!!!)

You haven’t forgotten, have you??????

The exponential distribution with parameter λ is

Equation from the original notes

that one!

Eh well… everyone’s already caught on…..

Let me just spoil the conclusion up front,,,,

Equation from the original notes

The random variable Y defined that way follows a Gamma distribution with parameters (α, λ) — that’s the additivity story.

I’ll prove it!

Calling it a “proof” is being generous — it’s super short — but I figured it’d be good to know the principle behind it!!!

Equation from the original notes

Pull out the moment generating function of Y and follow it through,

and from here onwards the formula editor is bye-bye~

Switching to the iPad.

Equation from the original notes

Heads-up. The last green line confuses scaling with adding independent copies. In this rate convention, if $X\sim\mathrm{Gamma}(r,\lambda)$ and $c>0$, then $cX\sim\mathrm{Gamma}(r,\lambda/c)$: shape stays $r$. A sum of $c$ independent copies instead has shape $cr$ and rate $\lambda$, when $c$ is a positive integer. The displayed MGFs use an auxiliary argument $t\lt \lambda$; for $cX$ its domain is $t\lt \lambda/c$.

Done~~~~

↓ Cleaned up just a little bit nicer on the iPad! heh

Equation from the original notes

Equation from the original notes

Equation from the original notes

Equation from the original notes

Heads-up. The repeated green scaling line has the same slip: $cX\sim\mathrm{Gamma}(r,\lambda/c)$ for $c>0$. Shape $cr$ with rate $\lambda$ belongs to a sum of $c$ independent copies for positive integer $c$, not a constant multiple. The MGF argument must remain in its domain as explained above.

import numpy as np
import matplotlib.pyplot as plt
import os
import scipy.stats as sc
pdp = []
alpha = 1.0
llambda = 0.5
scale= 1./llambda
x = np.linspace(0, 30, 100)
y = sc.gamma.pdf(x, a=alpha, scale=scale)
plt.plot(x, y, linewidth=2.0, label = r'$\alpha =$1   $\lambda =$0.5')
pdp = []
alpha = 2.0
llambda = 0.5
scale = 1./llambda
x = np.linspace(0, 30, 100)
y = sc.gamma.pdf(x, a=alpha, scale=scale)
plt.plot(x, y, linewidth=2.0, label=r'$\alpha =$2   $\lambda =$0.5')
pdp = []
alpha = 3.0
llambda = 0.5
loc = alpha / llambda
scale = 1./llambda
x = np.linspace(0, 30, 100)
y = sc.gamma.pdf(x, a=alpha, scale=scale)
plt.plot(x, y, linewidth=2.0, label=r'$\alpha =$3   $\lambda =$0.5')
pdp = []
alpha = 5.0
llambda = 1.0
scale = 1./llambda
x = np.linspace(0, 30, 100)
y = sc.gamma.pdf(x, a=alpha, scale=scale)
plt.plot(x, y, linewidth=2.0, label=r'$\alpha =$5   $\lambda =$1')
pdp = []
alpha = 9.0
llambda = 2.0
scale = 1./llambda
x = np.linspace(0, 30, 100)
y = sc.gamma.pdf(x, a=alpha, scale=scale)
plt.plot(x, y, linewidth=2.0, label=r'$\alpha =$9   $\lambda =$2')
plt.grid(True)
plt.legend()
plt.ylabel('p(x)')
plt.xlabel('x')
plt.title('Gamma Distribution')
plt.savefig('3.Gamma Distribution.jpeg')

Equation from the original notes

Questions or corrections?

Did a step lose you, or does a number look off? Email me or use the contact page. Include the note title and the step or figure you mean.

Feedback goes to me privately by email; it is not posted as a public comment.