# Generating Functions

The moment-generating function of a random variable is an alternative specification of its probability distribution. Thus, it provides the basis of an alternative route to analytical results compared with working directly with probability density functions or cumulative distribution functions. There are particularly simple results for the moment-generating functions of distributions defined by the weighted sums of random variables. Note, however, that not all random variables have moment-generating functions.

In addition to univariate distributions, moment-generating functions can be defined for vector- or matrix-valued random variables, and can even be extended to more general cases.

The moment-generating function does not always exist even for real-valued arguments, unlike the characteristic function. There are relations between the behavior of the moment-generating function of a distribution and properties of the distribution, such as the existence of moments.

The probability generating function of a discrete random variable is a power series representation (the generating function) of the probability mass functionof the random variable. Probability generating functions are often employed for their succinct description of the sequence of probabilities $\operatorname{P}(X=i)$ in the probability mass function for a random variable $X$, and to make available the well-developed theory of power series with non-negative coefficients.

## The Moment Generating Function

### Definition

In probability theory and statistics, the moment-generating function of a random variable $X$ is

[$] M_X(t) := \operatorname{E}\!\left[e^{tX}\right], \quad t \in \mathbb{R}, [$]

wherever this expectation exists. In other terms, the moment-generating function can be interpreted as the expectation of the random variable $e^{tX}$.

A key problem with moment-generating functions is that moments and the moment-generating function may not exist, as the integrals need not converge absolutely. By contrast, the characteristic function always exists and thus may be used instead.

The reason for defining this function is that it can be used to find all the moments of the distribution. The series expansion of $e^{tX}$ is:

[$] e^{t\,X} = 1 + t\,X + \frac{t^2\,X^2}{2!} + \cdots +\frac{t^n\,X^n}{n!} + \cdots. [$]

Hence:

[] \begin{align*} M_X(t) = \operatorname{E}\left[e^{t\,X}\right] = \sum_{n=0}^\infty \frac{\operatorname{E}[X^n]}{n!} = \sum_{n=0}^\infty \frac{t^nm_n}{n!} \end{align*} []

where $m_n$ is the $n$th moment. Differentiating $M_X(t)$ $i$ times with respect to $t$ and setting $t=0$ we obtain the $i$th moment about the origin, $m_i$, see Calculations of moments below.

### Calculation

The moment-generating function is the expectation of a function of the random variable, it can be written as:

Case Calculation
General $M_X(t) = \int_{-\infty}^\infty e^{tx}\,dF(x)$, using the Riemann–Stieltjes integral, and where $F$ is the cumulative distribution function
Discrete probability mass function $M_X(t)=\sum_{i=1}^\infty e^{tx_i}\, p_i$
Continuous probability density function $M_X(t) = \int_{-\infty}^\infty e^{tx} f(x)\,dx$

#### Sum of independent random variables

If $S_n = \sum_{i=1}^{n} a_i X_i$, where the $X_i$ are independent random variables and the $a_i$ are constants, then the probability density function for $S_n$ is the convolution of the probability density functions of each of the $X_i$, and the moment-generating function for $S_n$ is given by

[$] M_{S_n}(t)=M_{X_1}(a_1t)M_{X_2}(a_2t)\cdots M_{X_n}(a_nt) \, . [$]

#### Calculations of moments

The moment-generating function is so called because if it exists on an open interval around $t=0$ then it is the exponential generating function of the moments of the probability distribution:

[$]m_n = E \left( X^n \right) = M_X^{(n)}(0) = \frac{d^n M_X}{dt^n}(0).[$]

Here $n$ must be a nonnegative integer.

### Relation to other functions

Related to the moment-generating function are a number of other transforms that are common in probability theory:

Function Description
Characteristic function The characteristic function $\varphi_X(t)$ is related to the moment-generating function via $\varphi_X(t) = M_{iX}(t) = M_X(it):$ the characteristic function is the moment-generating function of iX or the moment generating function of $X$ evaluated on the imaginary axis. This function can also be viewed as the Fourier transform of the probability density function, which can therefore be deduced from it by inverse Fourier transform.
Cumulant-generating function The cumulant-generating function is defined as the logarithm of the moment-generating function; some instead define the cumulant-generating function as the logarithm of the characteristic function, while others call this latter the second cumulant-generating function.
Probability generating functions The probability-generating function is defined as $G(z) = E[z^X].\,$ This immediately implies that $G(e^t) = E[e^{tX}] = M_X(t).\,$

### Examples

Here are some examples of the moment generating function and the characteristic function for comparison. It can be seen that the characteristic function is a Wick rotation of the moment generating function Mx(t) when the latter exists.

Distribution Moment-generating function M$X$($t$) Characteristic function φ(t)
Bernoulli $\, \operatorname{P}(X=1)=p$   $\, 1-p+pe^t$   $\, 1-p+pe^{it}$
Geometric $(1 - p)^{k-1}\,p\!$   $\frac{p e^t}{1-(1-p) e^t}\!$
$\forall t\lt-\ln(1-p)\!$
$\frac{p e^{it}}{1-(1-p)\,e^{it}}\!$
Binomial $B(n, p)$   $\, (1-p+pe^t)^n$   $\, (1-p+pe^{it})^n$
Poisson Pois($λ$)   $\, e^{\lambda(e^t-1)}$   $\, e^{\lambda(e^{it}-1)}$
Uniform (continuous) $U(a, b)$   $\, \frac{e^{tb} - e^{ta}}{t(b-a)}$   $\, \frac{e^{itb} - e^{ita}}{it(b-a)}$
Uniform (discrete) $U(a, b)$   $\, \frac{e^{at} - e^{(b+1)t}}{(b-a+1)(1-e^{t})}$   $\, \frac{e^{ait} - e^{(b+1)it}}{(b-a+1)(1-e^{it})}$
Normal $N(\mu, \sigma^2)$   $\, e^{t\mu + \frac{1}{2}\sigma^2t^2}$   $\, e^{it\mu - \frac{1}{2}\sigma^2t^2}$
Chi-squared $\chi^2_k$   $\, (1 - 2t)^{-k/2}$   $\, (1 - 2it)^{-k/2}$
Gamma $\Gamma(k, \theta)$   $\, (1 - t\theta)^{-k}$   $\, (1 - it\theta)^{-k}$
Exponential Exp($λ$)   $\, (1-t\lambda^{-1})^{-1}, \, (t\lt\lambda)$   $\, (1 - it\lambda^{-1})^{-1}$
Multivariate normal $N(\mu, \Sigma)$   $\, e^{t^\mathrm{T} \mu + \frac{1}{2} t^\mathrm{T} \Sigma t}$   $\, e^{i t^\mathrm{T} \mu - \frac{1}{2} t^\mathrm{T} \Sigma t}$
Degenerate δa   $\, e^{ta}$   $\, e^{ita}$
Laplace $L(μ, b)$   $\, \frac{e^{t\mu}}{1 - b^2t^2}$   $\, \frac{e^{it\mu}}{1 + b^2t^2}$
Negative Binomial $NB(r, p)$   $\, \frac{(1-p)^r}{(1-pe^t)^r}$   $\, \frac{(1-p)^r}{(1-pe^{it})^r}$
Cauchy Cauchy($μ, θ$) does not exist   $\, e^{it\mu -\theta|t|}$

## The Probability Generating Function

### Definition

If $X$ is a discrete random variable taking values in the non-negative integers {0,1, ...}, then the probability generating function of $X$ is defined as 

[$]G(z) = \operatorname{E} (z^X) = \sum_{x=0}^{\infty}p(x)z^x,[$]

where $p$ is the probability mass function of $X$. Note that the subscripted notations $G_X$ and $p_X$ are often used to emphasize that these pertain to a particular random variable $X$, and to its distribution. The power series converges absolutely at least for all complex numbers $z \leq 1$; in many examples the radius of convergence is larger.

### Properties

#### Power series

Probability generating functions obey all the rules of power series with non-negative coefficients. In particular, $G(1^{-})=1$, where

[$] \lim_{z \uparrow 1} G(z) = G(z^{-}) [$]

, since the probabilities must sum to one. So the radius of convergence of any probability generating function must be at least 1, by Abel's theorem for power series with non-negative coefficients.

#### Probabilities and expectations

The following properties allow the derivation of various basic quantities related to $X$:

1. The probability mass function of $X$ is recovered by taking derivatives of $G$:

[$] p(k) = \operatorname{P}(X = k) = \frac{G^{(k)}(0)}{k!}.[$]

2. It follows from Property 1 that if $X$ and $Y$ have identical probability generating functions, then they have identical distributions.

3. The normalization of the probability density function can be expressed in terms of the generating function by

[$]\operatorname{E}(1)=G(1^-)=\sum_{i=0}^\infty f(i)=1.[$]

The expectation of $X$ is given by

[$] \operatorname{E}\left(X\right) = G'(1^-).[$]

More generally, the $k$th factorial moment, $\textrm{E}(X(X - 1) \cdots (X - k + 1))$ of $X$ is given by

[$]\textrm{E}\left(\frac{X!}{(X-k)!}\right) = G^{(k)}(1^-), \quad k \geq 0.[$]

So the variance of $X$ is given by

[$]\operatorname{Var}(X)=G''(1^-) + G'(1^-) - \left [G'(1^-)\right ]^2.[$]

4. $G_X(e^{t}) = M_X(t)$ where $X$ is a random variable, $G_X(t)$ is the probability generating function (of $X$) and $M_X(t)$ is the moment generating function (of $X$) .

#### Functions of independent random variables

Probability generating functions are particularly useful for dealing with functions of independent random variables. For example:

• If $X_1, X_2, \ldots, X_n$ is a sequence of independent (and not necessarily identically distributed) random variables, and

[$]S_n = \sum_{i=1}^n a_i X_i,[$]

where the $a_i$ are constants, then the probability generating function is given by

[$] G_{S_n}(z) = \operatorname{E}(z^{S_n}) = \operatorname{E}(z^{\sum_{i=1}^n a_i X_i,}) = G_{X_1}(z^{a_1})G_{X_2}(z^{a_2})\cdots G_{X_n}(z^{a_n}). [$]

For example, if $S_n = \sum_{i=1}^n X_i,$ then the probability generating function, GSn(z), is given by

[$]G_{S_n}(z) = G_{X_1}(z)G_{X_2}(z)\cdots G_{X_n}(z).[$]

It also follows that the probability generating function of the difference of two independent random variables $S$ = $X$1$X$2 is

[$]G_S(z) = G_{X_1}(z)G_{X_2}(1/z).[$]

• Suppose that $n$ is also an independent, discrete random variable taking values on the non-negative integers, with probability generating function $G_n$. If the $X_1,X_2, \ldots, X_N$ are independent and identically distributed with common probability generating function $G_X$, then $G_{S_N}(z) = G_N(G_X(z)).$ This can be seen, using the law of total expectation, as follows:

[] \begin{align*} G_{S_N}(z) = \operatorname{E}(z^{S_N})&= \operatorname{E}(z^{\sum_{i=1}^N X_i}) \\ &= \operatorname{E}\big(\operatorname{E}(z^{\sum_{i=1}^N X_i}| N) \big) \\ &= \operatorname{E}\big( (G_X(z))^N\big) =G_N(G_X(z)). \end{align*} []

This last fact is useful in the study of Galton–Watson processes.

• Suppose again that $N$ is also an independent, discrete random variable taking values on the non-negative integers, with probability generating function $G_N$ and probability density $f_i = \operatorname{P}(N = i)$. If the $X_1, \ldots, X_N$ are independent, but not identically distributed random variables, where $G_{X_i}$ denotes the probability generating function of $X_i$, then

[$]G_{S_N}(z) = \sum_{i \ge 1} f_i \prod_{k=1}^i G_{X_i}(z).[$]

For identically distributed $X_i$ this simplifies to the identity stated before. The general case is sometimes useful to obtain a decomposition of $S_N$ by means of generating functions.

### Examples

The table below gives the probability generating function for some well known discrete distributions.

Distribution PGF
Degenerate $\delta_a$ $G(z) = \left(z^a\right)$
Bernoulli $\, \operatorname{P}(X=1)=p$ $G(z) = 1/2 + z/2$
Binomial $\operatorname{B}(n, p)$ $G(z) = \left[(1-p) + pz\right]^n$
Negative Binomial $\operatorname{NB}(r,p)$ $G(z) = \left(\frac{pz}{1 - (1-p)z}\right)^r$
Poisson $\textrm{Pois}(\lambda)$ $G(z) = \textrm{e}^{\lambda(z - 1)}$