The moment-generating function of the gamma distribution is . Such a friendly little guy. Not what you would expect when you start with this:

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

Multiply in the exponential by , add the two terms together and factor out :

Now we’re ready to do so substitution in the integral. Let . That means we have . Now solve those for x and dx, respectively. We get and . Now substitute those in the integral to see something that looks truly awful:

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

Using the rules of exponents we see that which can be moved out of the integral since it doesn’t have in it:

Using the rules of exponents again we see that :

Now notice we can cancel out the two terms:

The integral is now the gamma function: . Make that substitution:

Cancel out the terms and we have our nice-looking moment-generating function:

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

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 () and we’re interested in the distribution of times until 4 events occur (), it seems reasonable to think the mean wait time to observe the 4th event would be 8 minutes ().

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:

Now find the variance:

Going back to our example with (number of events) and (mean time between events), we have as our variance . 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")