The moment generating function of the gamma

The moment-generating function of the gamma distribution is M(t)=(1θt)α. Such a friendly little guy. Not what you would expect when you start with this:

M(t)=0etx1Γ(α)θαxα1ex/θdx

How do we get there? First let’s combine the two exponential terms and move the gamma fraction out of the integral:

M(t)=1Γ(α)θα0xα1etxx/θdx

Multiply tx in the exponential by θθ=1, add the two terms together and factor out x:

M(t)=1Γ(α)θα0xα1ex(1θt)/θdx

Now we’re ready to do so substitution in the integral. Let u=x(1θt)θ. That means we have du=1θtθdx. Now solve those for x and dx, respectively. We get x=θu1θt and dx=θ1θtdu. Now substitute those in the integral to see something that looks truly awful:

M(t)=1Γ(α)θα0θu1θtα1euθ1θtdu

If re-write everything inside the integral with exponents we can do some cancellation and make this integral more attractive:

M(t)=1Γ(α)θα0(1θt)α+1(1θt)1(θu)α1θeudu

Using the rules of exponents we see that (1θt)α+1(1θt)1=(1θt)α which can be moved out of the integral since it doesn’t have u in it:

M(t)=(1θt)αΓ(α)θα0(θu)α1θeudu

Using the rules of exponents again we see that θα1θ=θα:

M(t)=(1θt)αΓ(α)θα0θαuα1eudu

Now notice we can cancel out the two θα terms:

M(t)=(1θt)αΓ(α)0uα1eudu

The integral is now the gamma function: Γ(α)=0uα1eudu. Make that substitution:

M(t)=(1θt)αΓ(α)Γ(α)

Cancel out the Γ(α) terms and we have our nice-looking moment-generating function:

M(t)=(1θt)α

If we take the derivative of this function and evaluate at 0 we get the mean of the gamma distribution:

M(t)=α(1θt)α1(θ)

M(0)=α(10)α1(θ)=αθ=E(X)

Recall that θ is the mean time between events and α is the number of events. Multiply them together and you have the mean. This makes sense. If the mean wait time between events is 2 minutes (θ=2) and we’re interested in the distribution of times until 4 events occur (α=4), it seems reasonable to think the mean wait time to observe the 4th event would be 8 minutes (4(2)).

If we take the second derivative of the moment-generating function and evaluate at 0, we get the second moment about the origin which we can use to find the variance:

M(t)=(α1)θα(1θt)α2(θ)

M(0)=(α1)θα(10)α2(θ)=(α1)(θ2)α

Now find the variance:

Var(X)=(α1)(θ2)α(αθ)2

Var(X)=α2θ2+αθ2α2θ2

Var(X)=αθ2

Going back to our example with α=4 (number of events) and θ=2 (mean time between events), we have as our variance 4(22)=16. The square root of that gives our standard deviation as 4.

Plugging the mean and standard deviation into the dgamma function in R, we can plot this particular gamma distribution:

xval <- seq(0,30, by = 0.01)
ga.4 <- dgamma(xval, shape=4, scale=2)
plot(xval,ga.4,col=1, type = "l", ylab="f(x)", xlab="x")
title(main="Gamma Distribution, scale = 2, shape = 4")

gamma with scale = 2 and shape = 4

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.