# Probability-generating function

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

## Definition

If N is a discrete random variable taking values on some subset of the non-negative integers, {0,1, ...}, then the probability-generating function of N is defined as:

${\displaystyle G(x)={\textrm {E}}(x^{N})=\sum _{n=0}^{\infty }f(n)x^{n},}$

where f is the probability mass function of N. Note that the equivalent notation GN is sometimes used to distinguish between the probability-generating functions of several random variables.

## Properties

### Power series

Probability-generating functions obey all the rules of power series with non-negative coefficients. In particular, G(1-) = 1, since the probabilities must sum to one, and where G(1-) = limz→1G(z) from below. 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

${\displaystyle \quad f(k)={\textrm {Pr}}(X=k)={\frac {G^{(k)}(0)}{k!}}.}$

2. It follows from Property 1 that if we have two random variables X and Y, and GX = GY, then fX = fY. That is, if X and Y have identical probability-generating functions, then they are identically distributed.

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

${\displaystyle E(1)=G(1^{-})=\sum _{i=0}^{\infty }f(i)=1.}$

The expectation of X is given by

${\displaystyle {\textrm {E}}\left(X\right)=G'(1^{-}).}$

More generally, the kth factorial moment, E(X(X − 1) ... (X − k + 1)), of X is given by

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

So the variance of X is given by

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

4.GX(${\displaystyle e^{t}}$) = MX(t) where X is a random variable, G(t) is the probability generating function and M(t) is the moment generating function.

### Functions of independent random variables

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

• If X1, X2, ..., Xn is a sequence of independent (and not necessarily identically distributed) random variables, and
${\displaystyle S_{n}=\sum _{i=1}^{n}a_{i}X_{i},}$
where the ai are constants, then the probability-generating function is given by
${\displaystyle E(z^{S_{n}})=E(z^{\sum _{i=1}^{n}a_{i}X_{i},})=G_{S_{n}}(z)=G_{X_{1}}(z^{a_{1}})G_{X_{2}}(z^{a_{2}})\ldots G_{X_{n}}(z^{a_{n}}).}$
For example, if
${\displaystyle S_{n}=\sum _{i=1}^{n}X_{i},}$
then the probability-generating function, GSn(z), is given by
${\displaystyle G_{S_{n}}(z)=G_{X_{1}}(z)G_{X_{2}}(z)\ldots G_{X_{n}}(z).}$
It also follows that the probability-generating function of the difference of two random variables S = X1X2 is
${\displaystyle 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 GN. If the X1, X2, ..., XN are independent and identically distributed with common probability-generating function GX, then
${\displaystyle G_{S_{N}}(z)=G_{N}(G_{X}(z)).}$
This can be seen as follows:
${\displaystyle G_{S_{N}}(z)=E(z^{S_{N}})=E(z^{\sum _{i=1}^{N}X_{i}})=E{\big (}E(z^{\sum _{i=1}^{N}X_{i}}|N){\big )}=E{\big (}(G_{X}(z))^{N}{\big )}=G_{N}(G_{X}(z)).}$
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 GN. If the X1, X2, ..., XN are independent, but not identically distributed random variables, where ${\displaystyle G_{X_{i}}}$ denotes the probability generating function of ${\displaystyle X_{i}}$, then it holds
${\displaystyle G_{S_{N}}(z)=\sum _{i\geq 1}f_{i}\prod _{k=1}^{i}G_{X_{i}}(z).}$
For identically distributed Xi this simplifies to the identity stated before. The general case is sometimes useful to obtain a decomposition of SN by means of generating functions.

## Examples

${\displaystyle G(z)=\left(z^{c}\right).}$
• The probability-generating function of a binomial random variable, the number of successes in n trials, with probability p of success in each trial, is
${\displaystyle G(z)=\left[(1-p)+pz\right]^{n}.}$
Note that this is the n-fold product of the probability-generating function of a Bernoulli random variable with parameter p.
• The probability-generating function of a negative binomial random variable, the number of trials required to obtain the rth success with probability of success in each trial p, is
${\displaystyle G(z)=\left({\frac {p}{1-(1-p)z}}\right)^{r}.}$
Note that this is the r-fold product of the probability generating function of a geometric random variable.
${\displaystyle G(z)=\left({\textrm {e}}^{\lambda (z-1)}\right).}$

## Example calculation: use of bivariate generating functions

The following example illustrates a very common technique the manipulation of PGFs: the use of bivariate super generating functions to compute the OGF of the PGFs of a sequence of random variables.

Suppose you sample a system that can assume two states, X and Y, X with probability p and Y with probability 1-p, e.g. a coin being flipped, obtaining the sequence of samples

${\displaystyle S_{1},\,S_{2},\,S_{3},\,\ldots \,S_{n},}$

where the system was sampled n times and has no memory.

Define the random variable ${\displaystyle M_{n}}$ to be the number of changes from one sample to the next in a sequence of n samples, i.e. how often ${\displaystyle S_{m}}$ was different from ${\displaystyle S_{m-1}}$. For example, the sequence

${\displaystyle X\,X\,X\,Y\,X\,X}$

has two changes, as does

${\displaystyle Y\,X\,X\,X\,X\,X\,Y\,Y\,Y\,Y.}$

We want to calculate the PGF of ${\displaystyle M_{n}}$, which we will do by using bivariate generating functions.

We introduce the bivariate GF ${\displaystyle G(z,u)}$ given by

${\displaystyle G(z,u)=\sum _{n\geq 1}E\left[u^{M_{n}}\right]z^{n},}$

i.e. ${\displaystyle G(z,u)}$ is the ordinary generating function of the PGFs of the ${\displaystyle M_{n}.}$ This step is completely general and indeed the core of the method.

Now let ${\displaystyle x_{n,k}}$ be the probability of having k changes in a sequence of n samples, where the last sample was an X. Similarly, let ${\displaystyle y_{n,k}}$ be the probability of having k changes in a sequence of n samples, where the last sample was a Y, and put

${\displaystyle X(z,u)=\sum _{n\geq 1,k\geq 0}x_{n,k}\,u^{k}z^{n}\quad {\mbox{and}}\quad Y(z,u)=\sum _{n\geq 1,k\geq 0}y_{n,k}\,u^{k}z^{n}}$

so that

${\displaystyle G(z,u)=X(z,u)+Y(z,u).\,}$

Now we clearly have

${\displaystyle x_{n,0}=p^{n}\quad {\mbox{and}}\quad y_{n,0}=(1-p)^{n},}$

because having zero changes means getting a sequence of all Xs or Ys.

For ${\displaystyle k\geq 1}$ we find

${\displaystyle x_{n,k}=p\,y_{n-1,k-1}+p\,x_{n-1,k}\quad {\mbox{and}}\quad y_{n,k}=(1-p)\,x_{n-1,k-1}+(1-p)\,y_{n-1,k},}$

because e.g. to have k changes in a sequence of length n that ends in X, we either append an X to a sequence having k-1 changes and ending in Y, or append an X to a sequence having k changes and ending in X.

Summing these equations over n and k and writing X for X(z, u) and Y for Y(z, u), we obtain

${\displaystyle X-{\frac {pz}{1-pz}}=puzY+pz\left(X-{\frac {pz}{1-pz}}\right)}$

and

${\displaystyle Y-{\frac {(1-p)z}{1-(1-p)z}}=(1-p)uzX+(1-p)z\left(Y-{\frac {(1-p)z}{1-(1-p)z}}\right).}$

The solution of this system is

${\displaystyle X=-{\frac {\left(-pz+puz+z-uz-1\right)pz}{-z+1+p{z}^{2}-{p}^{2}{z}^{2}-{u}^{2}{z}^{2}p+{p}^{2}{u}^{2}{z}^{2}}}}$

and

${\displaystyle Y=-{\frac {z\left(-puz-1+p+pz-{p}^{2}z+{p}^{2}uz\right)}{-z+1+p{z}^{2}-{p}^{2}{z}^{2}-{u}^{2}{z}^{2}p+{p}^{2}{u}^{2}{z}^{2}}}.}$

We may now use the general identity

${\displaystyle \sum _{n\geq 1}E\left[M_{n}(M_{n}-1)\ldots (M_{n}-r)\right]z^{n}=\left(\left({\frac {d}{du}}\right)^{r+1}G(z,u)\right)_{u=1}}$

to calculate the factorial moments of ${\displaystyle M_{n}.}$ E.g. the OGF of the expectations is given by

${\displaystyle \sum _{n\geq 1}E[M_{n}]z^{n}=\left({\frac {d}{du}}(X+Y)\right)_{u=1}=-2\,{\frac {\left(-1+p\right){z}^{2}p}{\left(-1+z\right)^{2}}},}$

from which we find (extracting coefficients) that

${\displaystyle E[M_{n}]=2\,p(1-p)\,(n-1).}$

An extensive discussion of this problem, as well as solutions by other methods, may be found on Les-Mathematiques.net (external links).

## Example calculation: bivariate generating functions and differential equations

Consider the following balls and urns problem: suppose we have an urn containing n distinguishable balls, i.e. bearing labels from 1 to n. We pick one of the balls at random and remove it from the urn. We also remove all balls whose labels are larger than the one we picked from the urn. E.g. if we picked ball number one, the urn is emptied after one operation. We repeat until the urn is empty. E.g. for an urn containing ten balls, the sequence of picks 6-3-1 would empty the urn in three operations. We introduce the random variable ${\displaystyle X_{n}}$, which gives the number of picks needed to empty the urn. Our goal is to compute all of its moments, and we will do so using exactly the same bivariate generating function as in the previous example, namely the OGF of the PGFs:

${\displaystyle P(z,u)=\sum _{n\geq 1}E\left[u^{X_{n}}\right]z^{n}.}$

We let ${\displaystyle p_{n,k}}$ be the probability of emptying an urn containing n balls with k operations, so that

${\displaystyle P(z,u)=\sum _{n\geq 1,k\geq 1}p_{n,k}u^{k}z^{n}.}$

We find that

${\displaystyle p_{n,1}={\frac {1}{n}}\quad {\mbox{and}}\quad p_{n,k}={\frac {1}{n}}\sum _{r=1}^{n-(k-1)}p_{n-r,k-1},\quad k\geq 2}$

because to empty the urn with one operation, we must pick the ball labelled 1. The remaining probabilities are computed recursively, e.g. we pick the ball with the largest label with probability ${\displaystyle 1/n}$, leaving ${\displaystyle n-1}$ balls (this is ${\displaystyle r=1}$). We pick the ball with the next-to-largest label with probability ${\displaystyle 1/n}$, leaving ${\displaystyle n-2}$ balls (this is ${\displaystyle r=2}$), etc. The upper bound for r is ${\displaystyle n-(k-1)}$, because we must have ${\displaystyle n-r\geq k-1}$ (we cannot e.g. empty an urn containing six balls using seven operations).

Next we set ${\displaystyle p_{n,k}=0}$ for ${\displaystyle n, so that we may replace the recursion by

${\displaystyle p_{n,k}={\frac {1}{n}}\sum _{r=1}^{n-1}p_{n-r,k-1},\quad k\geq 2.}$

Using the coefficient-extraction operator for formal power series, we thus have

${\displaystyle [z^{n-1}u^{k}]{\frac {d}{dz}}P(z,u)=[z^{n-1}u^{k-1}]{\frac {1}{1-z}}P(z,u)=[z^{n-1}u^{k}]{\frac {u}{1-z}}P(z,u),\quad k\geq 2.}$

We note furthermore that

${\displaystyle [z^{n-1}u]{\frac {d}{dz}}P(z,u)=[z^{n-1}]{\frac {d}{dz}}\sum _{n\geq 1}{\frac {1}{n}}z^{n}=[z^{n-1}]{\frac {d}{dz}}\log {\frac {1}{1-z}}=[z^{n-1}]{\frac {1}{1-z}}=1}$

and that

${\displaystyle [z^{n-1}u]{\frac {u}{1-z}}P(z,u)=0,}$

where the first equation results from our "boundary condition" that the probability of emptying an urn with one operation is ${\displaystyle 1/n.}$

Summing over ${\displaystyle k\geq 1}$ (there are two contributions to both sides of the equation, one for ${\displaystyle k\geq 2}$ and another one for ${\displaystyle k=1}$), we obtain

${\displaystyle {\frac {d}{dz}}P(z,u)={\frac {u}{1-z}}+{\frac {u}{1-z}}P(z,u),}$

e.g. through

${\displaystyle \sum _{n\geq 1}z^{n-1}u[z^{n-1}u]{\frac {d}{dz}}P(z,u)=\sum _{n\geq 1}z^{n-1}u={\frac {u}{1-z}}.}$

The solution to the differential equation is

${\displaystyle P(z,u)=-1+C(u)\left({\frac {1}{1-z}}\right)^{u}}$,

with ${\displaystyle C(u)}$ a formal power series in u. We note

${\displaystyle [z^{0}]P(z,u)=0=-1+C(u)\,}$

which follows from the formal series

${\displaystyle \left({\frac {1}{1-z}}\right)^{u}=\sum _{k\geq 0}{\frac {u^{k}}{k!}}\left(\log {\frac {1}{1-z}}\right)^{k}.}$

Hence ${\displaystyle C(u)}$ is constant and equal to one, and we finally have

${\displaystyle P(z,u)=-1+\left({\frac {1}{1-z}}\right)^{u},}$

which is, incidentally, the generating function of the Stirling numbers of the first kind.

The moments now follow trivially from the formula given in the first example. E.g. for the expectation, we find

${\displaystyle \sum _{n\geq 1}E[X_{n}]z^{n}=\left.{\frac {d}{du}}P(z,u)\right|_{u=1}=\left.\left({\frac {1}{1-z}}\right)^{u}\log {\frac {1}{1-z}}\right|_{u=1}={\frac {1}{1-z}}\log {\frac {1}{1-z}}}$

which gives

${\displaystyle E[X_{n}]=[z^{n}]{\frac {1}{1-z}}\log {\frac {1}{1-z}}=H_{n},}$

the nth harmonic number, and we need about ${\displaystyle \log n\,}$ operations to empty the urn.

An extensive discussion of this problem, as well as solutions by other methods, may be found on Les-Mathematiques.net (external links).

## Related concepts

The probability-generating function is occasionally called the z-transform of the probability mass function. It is an example of a generating function of a sequence (see formal power series).

Other generating functions of random variables include the moment-generating function and the characteristic function.