Tutorials › Statistical Theory I - Probability and Distribution Theory › Generating Functions for a Bernoulli Variable

Bernoulli and Binomial Families · Tutorial 103 of 994

Generating Functions for a Bernoulli Variable

Learn how the Bernoulli generating functions encode its distribution and how their derivatives yield the mean and variance.

Beginner 9 min read

What You'll Learn

  • Define the probability-generating function and moment-generating function for a Bernoulli variable.
  • Derive each function directly from the two possible outcomes.
  • Use derivatives at one to recover ordinary and factorial moments from the probability-generating function.
  • Use derivatives at zero to recover the mean and variance from the moment-generating function.
  • Recognize why the second derivative of the probability-generating function is not, by itself, the second moment.

Why Generate Functions for a Two-Point Distribution?

A Bernoulli variable has only two possible outcomes, so its distribution can be written down directly. Generating functions give another way to record those probabilities: the probability-generating function uses powers of an argument to encode integer outcomes, while the moment-generating function uses exponentials. For a Bernoulli variable, both functions are simple, but their derivatives make a useful distinction between ordinary moments and factorial moments.

The main calculation is compact: the probability-generating function has one derivative that yields the mean and a second derivative that yields a factorial moment; the moment-generating function yields ordinary moments from derivatives at zero. Keeping track of which function is differentiated and where is essential.

Definitions and the Bernoulli Generating Functions

Definition: Let \(X\sim\operatorname{Bernoulli}(p)\), where \(0\leq p\leq 1\), so that \(P(X=1)=p\) and \(P(X=0)=1-p\). Its probability-generating function is \(G_X(s)=E[s^X]\) for \(s\) in a neighborhood of \(1\) where the expectation is defined. Its moment-generating function is \(M_X(t)=E[e^{tX}]\) for \(t\) in a neighborhood of \(0\) where the expectation is finite.

For this two-point distribution the expectations are finite sums, so both functions exist for every real \(s\) and \(t\). In particular, the convention \(s^0=1\) applies, including when \(s=0\). Evaluating each expectation by summing over the two outcomes gives the following formulas.

$$ G_X(s)=(1-p)s^0+ps^1=1-p+ps, \qquad M_X(t)=(1-p)e^{t\cdot 0}+pe^{t\cdot 1}=1-p+pe^t. $$

The functions have different input variables and different useful evaluation points. For the probability-generating function, evaluate derivatives at \(s=1\). For the moment-generating function, evaluate derivatives at \(t=0\). The values at those points are both \(1\), as expected: \(G_X(1)=E[1^X]=1\) and \(M_X(0)=E[e^0]=1\).

Worked Example: Constructing Both Functions

Suppose \(X\sim\operatorname{Bernoulli}(0.3)\). Then \(P(X=0)=0.7\) and \(P(X=1)=0.3\). Summing the two terms gives

$$ G_X(s)=0.7s^0+0.3s^1=0.7+0.3s, \qquad M_X(t)=0.7e^{0t}+0.3e^{t}=0.7+0.3e^t. $$

As a check, \(G_X(1)=0.7+0.3=1\), and \(M_X(0)=0.7+0.3e^0=1\). At \(s=2\), the probability-generating function is \(G_X(2)=0.7+0.3(2)=1.3\). At \(t=\log 2\), the moment-generating function is \(M_X(\log 2)=0.7+0.3(2)=1.3\). The matching numerical values here do not make the functions interchangeable: one is evaluated at \(s=2\), the other at \(t=\log 2\), and their derivatives encode moments through different rules.

Derivatives of the Probability-Generating Function

For a nonnegative integer-valued variable, differentiating a probability-generating function brings down powers of the outcome. At \(s=1\), the first derivative gives the mean. The second derivative gives the expectation of \(X(X-1)\), not \(X^2\), because two differentiations of \(s^x\) produce \(x(x-1)s^{x-2}\).

Result: For \(X\sim\operatorname{Bernoulli}(p)\), \(G_X'(1)=E[X]=p\) and \(G_X''(1)=E[X(X-1)]=0\). Consequently, \(E[X^2]=G_X''(1)+G_X'(1)=p\), and \(\operatorname{Var}(X)=p(1-p)\).

Here the derivatives can be computed directly from the polynomial \(G_X(s)=1-p+ps\): \(G_X'(s)=p\) and \(G_X''(s)=0\). To see why these values correspond to the stated expectations, differentiate the defining finite sum \(G_X(s)=\sum_{x=0}^1P(X=x)s^x\). Because it is a finite sum, differentiation term by term is valid. The first derivative is \(\sum_{x=0}^1P(X=x)x s^{x-1}\); at \(s=1\), this is \(E[X]\). The second derivative at \(1\) is \(\sum_{x=0}^1P(X=x)x(x-1)=E[X(X-1)]\). For this Bernoulli distribution the \(x=0\) term and the \(x=1\) term in the second derivative are both zero.

Finally, \(X^2=X(X-1)+X\), so the ordinary second moment is \(E[X^2]=G_X''(1)+G_X'(1)=p\). Subtracting the square of the mean gives the variance:

$$ \operatorname{Var}(X)=E[X^2]-\{E[X]\}^2=p-p^2=p(1-p). $$

This calculation is also a direct verification of the moment formulas for the Bernoulli distribution. The probability-generating function returns the mean from its first derivative at one, and its second derivative contributes the factorial moment needed to construct the ordinary second moment.

Worked Example: Recovering the Mean and Variance from the PGF

Let \(X\sim\operatorname{Bernoulli}(1/4)\). Its probability-generating function and its first two derivatives are

$$ G_X(s)=\frac{3}{4}+\frac{1}{4}s, \qquad G_X'(s)=\frac{1}{4}, \qquad G_X''(s)=0. $$

Evaluating at \(s=1\) gives \(E[X]=G_X'(1)=1/4\) and \(E[X(X-1)]=G_X''(1)=0\). Thus

$$ E[X^2]=E[X(X-1)]+E[X]=0+\frac{1}{4}=\frac{1}{4}. $$

The variance is therefore

$$ \operatorname{Var}(X)=E[X^2]-\{E[X]\}^2 =\frac{1}{4}-\left(\frac{1}{4}\right)^2 =\frac{1}{4}-\frac{1}{16} =\frac{3}{16}. $$

As a check from the two possible outcomes, \(X^2=X\) for \(X=0\) and \(X=1\), so its mean must also be \(1/4\). The result agrees with the derivative calculation.

Derivatives of the Moment-Generating Function

The moment-generating function encodes ordinary moments directly. For the Bernoulli variable, differentiating \(M_X(t)=1-p+pe^t\) gives \(M_X'(t)=pe^t\) and \(M_X''(t)=pe^t\). At \(t=0\), these derivatives are both \(p\). The second derivative therefore gives \(E[X^2]\), not \(E[X(X-1)]\).

Result: For \(X\sim\operatorname{Bernoulli}(p)\), \(M_X'(0)=E[X]=p\) and \(M_X''(0)=E[X^2]=p\). Hence \(\operatorname{Var}(X)=M_X''(0)-\{M_X'(0)\}^2=p(1-p)\).

The identification follows from the defining expectation. Since \(X\) takes only the values \(0\) and \(1\), \(M_X(t)=\sum_{x=0}^1P(X=x)e^{tx}\). Differentiating this finite sum once gives \(\sum_xP(X=x)xe^{tx}\), and twice gives \(\sum_xP(X=x)x^2e^{tx}\). Setting \(t=0\) makes each exponential factor \(1\), leaving the first and second ordinary moments, respectively. The finite sum requires no interchange of a limit with an infinite series or integral.

Worked Example: Using the MGF to Find Variance

Suppose \(X\sim\operatorname{Bernoulli}(0.2)\). Its moment-generating function is

$$ M_X(t)=0.8+0.2e^t. $$

Differentiate and evaluate at zero:

$$ M_X'(t)=0.2e^t, \qquad M_X'(0)=0.2e^0=0.2=E[X], $$
$$ M_X''(t)=0.2e^t, \qquad M_X''(0)=0.2e^0=0.2=E[X^2]. $$

It follows that

$$ \operatorname{Var}(X)=M_X''(0)-\{M_X'(0)\}^2 =0.2-(0.2)^2 =0.2-0.04 =0.16. $$

The result also equals \(p(1-p)=0.2(0.8)=0.16\). In this example the first and second raw moments are equal because \(X^2=X\) at both possible outcomes.

Why the Two Derivative Rules Differ

The probability-generating function differentiates powers \(s^x\), while the moment-generating function differentiates exponentials \(e^{tx}\). Their derivative rules explain why the PGF’s second derivative produces \(x(x-1)\), whereas the MGF’s second derivative produces \(x^2\). For a Bernoulli variable, both \(E[X]\) and \(E[X^2]\) equal \(p\), but that equality comes from the support \(\{0,1\}\); it does not mean the two derivative rules are the same.

For the PGF, the conversion from a factorial moment to an ordinary moment uses the identity \(X^2=X(X-1)+X\). The direct finite-sum calculation for this particular variable is:

$$ G_X'(1)=\sum_{x=0}^1P(X=x)x=0(1-p)+1p=p, $$
$$ G_X''(1)=\sum_{x=0}^1P(X=x)x(x-1) =0(1-p)+1\cdot 0\cdot p=0. $$

For the MGF, the corresponding calculation uses \(x^2\):

$$ M_X''(0)=\sum_{x=0}^1P(X=x)x^2 =0^2(1-p)+1^2p=p. $$

Worked Example: Diagnosing a Derivative Mistake

A student writes: “For \(X\sim\operatorname{Bernoulli}(0.6)\), \(G_X''(1)=E[X^2]\). Since \(G_X(s)=0.4+0.6s\), \(G_X''(1)=0\), so \(E[X^2]=0\).” The conclusion cannot be right: \(X=1\) with probability \(0.6\), and \(X^2=1\) on that event.

The error is the derivative rule. The second derivative of \(s^x\) is \(x(x-1)s^{x-2}\), so \(G_X''(1)\) is \(E[X(X-1)]\), not \(E[X^2]\). For this distribution, the correct calculations are

$$ G_X'(1)=0.6, \qquad G_X''(1)=0, \qquad E[X^2]=G_X''(1)+G_X'(1)=0+0.6=0.6. $$

Then \(\operatorname{Var}(X)=0.6-(0.6)^2=0.6-0.36=0.24\), matching \(p(1-p)=0.6(0.4)=0.24\).

Boundary Cases and Practical Use

The formulas remain valid at the boundary values of the parameter. If \(p=0\), then \(X=0\) with probability one, \(G_X(s)=1\), \(M_X(t)=1\), and both the mean and variance are zero. If \(p=1\), then \(X=1\) with probability one, \(G_X(s)=s\), \(M_X(t)=e^t\), the mean is one, and the variance is zero. The variance formula \(p(1-p)\) gives zero in both cases.

In practice, these calculations provide a concise way to check a Bernoulli distribution’s moments and to learn how generating functions encode distributions. The distinction to retain is simple: \(G_X'(1)\) gives the mean and \(G_X''(1)\) gives a factorial moment; \(M_X'(0)\) gives the mean and \(M_X''(0)\) gives the second ordinary moment. For this variable both routes lead to the same variance once the appropriate moment identity is used.

Check Your Understanding

Use the definitions and derivative rules above to answer these questions.

  1. For \(X\sim\operatorname{Bernoulli}(p)\), write \(G_X(s)\) and \(M_X(t)\) and state the point at which each function’s derivatives are evaluated to obtain moments.
  2. Why does \(G_X''(1)\) equal \(E[X(X-1)]\) rather than \(E[X^2]\)?
  3. If \(G_X'(1)=0.35\) and \(G_X''(1)=0\) for a Bernoulli variable, find \(E[X^2]\) and \(\operatorname{Var}(X)\).
  4. For a Bernoulli variable with \(p=0.8\), calculate \(M_X'(0)\), \(M_X''(0)\), and the variance.
  5. Verify the PGF, MGF, mean, and variance when \(p=0\), and explain why the derivative rules still apply.