Moment Generating Function

Use an MGF to find raw moments, recover the mean and variance, and combine independent random variables—with the conditions that make those steps valid.

So you get a bundle of data. What do you do with it? You compute stuff — mean, variance, that kind of thing.

It’s just… you’re trying to pull out the characteristics of the data, right? So… calculating the mean and the variance and whatever doesn’t feel weird at all.

But here’s the thing — “mean” is actually called the first moment (1st moment). And “variance” is called the second central moment (the 2nd moment, taken around the mean).

For now, think of a discrete random variable $X$ taking values $x_i$ with probabilities $f(x_i)=P(X=x_i)$. The weights add to 1. These are distribution moments; a data set gives empirical versions when we use its relative frequencies as the weights.

So what’s that 1 and that 2 hooked to? The definition of the mean is

The definition of the mean, mu = sum of x_i^1 f(x_i), with the exponent 1 colored red

this, right? And it’s tied to that ‘1’ I colored red up there.

And the definition of variance is

The definition of variance, sigma^2 = sum of (x_i - mu)^2 f(x_i), with the exponent 2 colored red

this, and turns out it’s tied to the ‘2’ I colored red.

OK so far I’ve only talked up to the 2nd moment — and that’s where high school stops.

But if there’s a 1 and there’s a 2, then what about 3? What about 4? What about $n$?!

Yep! They exist.

Skewness written as sum of (x_i - mu)^3 f(x_i), with the exponent 3 colored red

Kurtosis written as sum of (x_i - mu)^4 f(x_i), with the exponent 4 colored red

Those two original labels need a qualification right here: the formulas show the third and fourth central moments, not standardized skewness and kurtosis themselves. When $\sigma>0$ and the needed moments are finite,

$$\text{skewness}=\frac{E[(X-\mu)^3]}{\sigma^3},\qquad \text{kurtosis}=\frac{E[(X-\mu)^4]}{\sigma^4}.$$

Subtract 3 from the latter if you want excess kurtosis. The fourth power gives far-from-the-mean outcomes a lot of weight; kurtosis is not simply the height of the peak.

⋮

The n-th moment, sum of (x_i - mu)^n f(x_i), with the exponent n colored red

And this is the ‘moment’ part of moment generating function! But watch the centre: the picture just above shows $E[(X-\mu)^n]$, a central moment. The MGF directly generates raw moments, $E[X^n]$, measured from zero. We can then use those to calculate central moments such as the variance.

The MGF is written as M_X(t) and the definition is

M_X(t) = E(e^(tX))

The important condition for the differentiation and uniqueness results below is that $M_X(t)$ is finite throughout some open interval $-h\lt t\lt h$ with $h>0$. Not every distribution has such an MGF. $M_X(0)=E[1]=1$ always, but being finite only at zero is not enough!

For our discrete case, $M_X(t)=\sum_i e^{t x_i}f(x_i)$. For a continuous variable with density $f$, use $M_X(t)=\int_{-\infty}^{\infty}e^{tx}f(x)\,dx$. Same expectation, different way of adding the probability weights.

You’re asking why it’s defined like this?!

Super simple. E(e^(tX)), by the definition of expected value, is

E(e^(tX)) = sum of e^(t X_i) f(X_i) = e^(t X_1) f(X_1) + e^(t X_2) f(X_2) + e^(t X_3) f(X_3) +

That is,

M_X(t) = e^(t X_1) f(X_1) + e^(t X_2) f(X_2) + e^(t X_3) f(X_3) +

and there it is.

Differentiate both sides with respect to $t$:

M_X’(t) = X_1 e^(t X_1) f(X_1) + X_2 e^(t X_2) f(X_2) + X_3 e^(t X_3) f(X_3) +

Differentiate both sides one more time with respect to $t$:

M_X’’(t) = X_1^2 e^(t X_1) f(X_1) + X_2^2 e^(t X_2) f(X_2) + X_3^2 e^(t X_3) f(X_3) +

Now — shall we plug $t=0$ into each of those?

M_X’(0) = X_1 e^(0 X_1) f(X_1) + X_2 e^(0 X_2) f(X_2) + X_3 e^(0 X_3) f(X_3) + … = sum of X_i f(X_i)

M_X’’(t) = X_1^2 e^(0 X_1) f(X_1) + X_2^2 e^(0 X_2) f(X_2) + X_3^2 e^(0 X_3) f(X_3) + … = sum of X_i^2 f(X_i), with t still written on the left side

In the second-derivative picture just above, the left side should say $M_X''(0)$, because we have already substituted $t=0$.

Why does this work? Differentiating $e^{t x_i}$ $n$ times brings down $x_i^n$; then setting $t=0$ turns the remaining exponential into 1. For a finite sum, that is ordinary differentiation. With infinitely many outcomes or an integral, the neighborhood-of-zero condition is what justifies exchanging differentiation with the expectation.

The thing that has these characteristics is the moment generating function.

OK so to summarize before moving on — it’s all because of this property:

The m-th derivative of M_X at 0 equals E(X^m)

One small example: moments are not all variances

Let $X$ be 1 with probability $1/4$ and 0 with probability $3/4$. Then

$$M_X(t)=\frac34+\frac14e^t,\qquad M_X'(0)=\frac14,\qquad M_X''(0)=\frac14.$$

So the mean is $1/4$, but the variance is

$$\operatorname{Var}(X)=M_X''(0)-[M_X'(0)]^2 =\frac14-\frac1{16}=\frac3{16}.$$

The second derivative gave $E[X^2]$, not the variance straight away. That little subtraction is the whole distinction!

Why an MGF can identify a distribution

Boom! But honestly, the real reason I’m pinning the MGF down here is a different property of it that we’ll use later on.

What property?

If $M_X(t)=M_Y(t)$ throughout an open interval around 0 where both are finite, then $X$ and $Y$ have the same probability distribution: $P(X\le x)=P(Y\le x)$ for every real $x$. They need not be the same random variable, independent, or even defined on the same underlying probability space. Matching just a few moments does not give this conclusion.

That is — if the MGF exists, there is one and only one probability distribution that corresponds to it!

Also, side note — say you’ve got mutually independent random variables $X, Y, Z$.

Then each one’s MGF is written as M_X(t), M_Y(t), M_Z(t) — right?

But in this case — the MGF of the random variable $X+Y+Z$ is

M_(X+Y+Z)(t) = M_X(t) M_Y(t) M_Z(t)

that’s the fact. I used 3 as an example, but it works for any $n$ too.

M_(X+Y+Z)(t) = E(e^(t(X+Y+Z))) = E(e^(tX) e^(tY) e^(tZ)) = E(e^(tX)) E(e^(tY)) E(e^(tZ)) = M_X(t) M_Y(t) M_Z(t)

That factoring step uses mutual independence. It is not a general rule that an expectation of a product equals a product of expectations! Use a common interval where the individual MGFs are finite.

For example, three independent copies of our 0-or-1 variable have sum $S$ with

$$M_S(t)=\left(\frac34+\frac14e^t\right)^3.$$

Differentiating gives $E[S]=3/4$ and $E[S^2]=9/8$, so $\operatorname{Var}(S)=9/8-(3/4)^2=9/16$. We combined three distributions without listing all eight outcomes. That’s a good reason to keep this tool handy!

Next time — we’re kicking off with ‘distributions’!


Heads-up. The figures here are the original notes, slips and all. A few things to watch for:

  • The pictures labelled skewness and kurtosis show the third and fourth central moments; skewness and kurtosis divide them by $\sigma^3$ and $\sigma^4$.
  • The $n$-th moment picture shows the central moment, taken around $\mu$. The MGF produces the raw moments, taken around 0: $M_X^{(n)}(0) = E(X^n) = \sum x_i^n f(x_i)$.
  • In the second-derivative picture with $t = 0$ already plugged in, the left side should read $M_X''(0)$.

For the MGF rules, see University of Toronto, Moment-generating Functions . The standardized skewness and kurtosis conventions are described in the NIST statistical handbook .

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.