Skip to content
AI360Xpert
Beta

Moments and Moment Generating Functions

Moments are a distribution's vital signs: center, spread, lean, and tail weight. The generating function packs all of them into one machine.

The Bernoulli generating function 0.7 plus 0.3 e to the t leaves the point (0, 1) with slope 0.3, which is the mean, and its bend gives the variance
The Bernoulli generating function 0.7 plus 0.3 e to the t leaves the point (0, 1) with slope 0.3, which is the mean, and its bend gives the variance

Why Does This Exist?

Full distributions are heavy objects: densities, tables, or samplers you must carry everywhere. Most decisions need only a few summaries. Where is the center, how wide is the spread, does it lean, how heavy are the tails? Moments answer exactly those four questions, in order, and entire fields run on the first two: portfolio theory is mean versus variance, and the central limit theorem says large sums forget everything but their first two moments.

Moment generating functions earn their place by making moments mechanical. Instead of integrating xkx^k against the density separately for each kk, differentiate one function at zero and read the answers off. They also prove distribution facts cleanly: sums of independent variables multiply MGFs, which is the two-line reason normals add to normals. The mean and variance groundwork is expectation, variance and covariance; the Fourier sibling that always exists is characteristic functions.

The one idea you need first

The kk-th raw moment is E[Xk]E[X^k]: the average of the kk-th power. The kk-th central moment recenters first: E[(X−μ)k]E[(X - \mu)^k]. So the mean is the first raw moment, the variance is the second central moment, skewness standardizes the third, and kurtosis standardizes the fourth. Each moment sees one more shape of the distribution than the last.

Think of It Like This

A sprinter's stat card

A stat card never lists every race. It gives the average time, the spread of times, whether slow races outnumber fast ones, and whether disasters strike. Four numbers stand in for a career.

Moments are a distribution's stat card. The mean places it, the variance paces its wobble, skewness reports the lean, kurtosis warns about the tails. And the generating function is the card printer: feed it an integer kk by differentiating kk times, and it stamps out the kk-th moment. The card stops where the printer jams, since some distributions have moments only up to a point, and heavy tails tear the card entirely.

How It Actually Works

The moment generating function is the expectation of the exponential tilt:

MX(t)=E[etX]M_X(t) = E[e^{tX}]

In plain words: weight each outcome by etxe^{tx} and average. Differentiating under the expectation pulls down one XX per derivative, so MX(k)(0)=E[Xk]M_X^{(k)}(0) = E[X^k], the kk-th raw moment. Mean from one derivative, second moment from two, variance from their combination Var(X)=M′′(0)−M′(0)2\text{Var}(X) = M''(0) - M'(0)^2.

Three properties do the heavy lifting. First, sums of independent variables multiply MGFs: MX+Y=MXMYM_{X+Y} = M_X M_Y, which is why the normal family, the Poisson family, and the gamma family with shared rate all stay in the family under addition. Second, matching MGFs near zero identify the distribution, so proving convergence of MGFs proves convergence in distribution. Third, the log-MGF generates cumulants, where the normal keeps only two nonzero terms and every extra term measures non-Gaussianity.

Worked example

Take a Bernoulli with p=0.3p = 0.3. Its MGF is M(t)=0.7+0.3etM(t) = 0.7 + 0.3e^t: still 0 with chance 0.7, tilted by ete^t with chance 0.3.

First derivative: M′(t)=0.3etM'(t) = 0.3e^t, so M′(0)=0.3M'(0) = 0.3, the mean. Second: M′′(t)=0.3etM''(t) = 0.3e^t, so M′′(0)=0.3M''(0) = 0.3, the second moment. Variance is their combination: 0.3−0.32=0.3−0.09=0.210.3 - 0.3^2 = 0.3 - 0.09 = 0.21. The diagram draws this MGF leaving (0,1)(0, 1) with slope 0.30.3, and that slope is the mean made visible.

Code

Two derivatives of the Bernoulli MGF by finite differences, recovering the mean and variance without any integration.

import math
p = 0.3

def mgf(t: float) -> float:    return (1 - p) + p * math.exp(t)  # Bernoulli MGF

h = 1e-5mean = (mgf(h) - mgf(-h)) / (2 * h)second = (mgf(h) - 2 * mgf(0) + mgf(-h)) / h**2print(round(mean, 6))          # -> 0.3print(round(second - mean**2, 3))  # -> 0.21

The prints give 0.3 and 0.21, matching the hand derivation. Differentiation at zero replaced two expectation integrals, which is the whole point of the machine.

Watch Out For

Assuming every distribution has an MGF

The expectation E[etX]E[e^{tX}] must converge near zero, and heavy tails break it: the lognormal and Cauchy have no MGF in any neighborhood of zero. Reaching for MGF machinery there produces divergent integrals disguised as answers. The characteristic function E[eitX]E[e^{itX}] always exists and is the safe fallback; its complex values are the price of universality.

Believing moments pin down the distribution

Distinct distributions can share every moment: the classic lognormal has moment-doppelgangers that no moment sequence separates. Matching means and variances across train and test never proves matching distributions, and two models with identical moment profiles can fail on entirely different inputs. Moments summarize; only the full distribution identifies.

The Quick Version

  • Moments are shape summaries in order: center, spread, lean, tail weight.
  • The MGF packs them into one function, with the k-th derivative at zero giving the k-th moment.
  • MGFs multiply across independent sums, which is why some families stay closed under addition.
  • Bernoulli 0.3 yields mean 0.3 and variance 0.21 from two derivatives.
  • Heavy-tailed distributions may have no MGF, and moments alone never identify a distribution.