Discrete random variables — step-by-step proofs with the WhatsApp group, series that add themselves up and the mgf differentiated at zero (and the mean I left half done)

In a class mock exam I had to prove that a function was a mass function and I got stuck on a sum with an xx multiplying a power: I could sum the geometric series, but not that one. I wrote “it converges” and moved on to the next part. I lost five points out of fifteen for not knowing a two-line trick: differentiating the geometric series. This article exists so that it does not happen to you. Here, step by step, is why everything you saw in the discrete random variables theory is true, with the same class WhatsApp group.

Each proof follows the same order: what we want to prove, where we start from, each step with the rule that justifies it, where people get stuck, the result for the cheat sheet and how to check it with R. The first one is exactly the kind of 15-point exercise that comes up in the first continuous assessment: you are given a function with a parameter and asked to check it is a mass function, find its mgf and its mean.

Before you start: the rules we will use

Almost every proof in the topic is summing a series. These six rules are the tools; each step of the proofs cites one by its number (“by rule 2”).

  1. Geometric series. If ∣a∣<1\lvert a \rvert < 1, ∑k=0∞ak=11−a\sum_{k=0}^{\infty} a^k = \frac{1}{1-a}. And the finite sum, for any a≠1a \neq 1: ∑k=0nak=1−an+11−a\sum_{k=0}^{n} a^k = \frac{1 – a^{n+1}}{1 – a}.
  2. Differentiated geometric series. If ∣a∣<1\lvert a \rvert < 1, ∑k=1∞k ak=a(1−a)2\sum_{k=1}^{\infty} k\,a^k = \frac{a}{(1-a)^2}.
  3. Exponential series. For any number zz, ∑k=0∞zkk!=ez\sum_{k=0}^{\infty} \frac{z^k}{k!} = e^z.
  4. Newton’s binomial theorem. (a+b)n=∑k=0n(nk)akbn−k(a + b)^n = \sum_{k=0}^{n} \binom{n}{k} a^k b^{n-k}.
  5. Linearity. Constants come out of sums and expectations, and the sum of a sum is the sum of the sums: ∑(c uk+vk)=c∑uk+∑vk\sum (c\,u_k + v_k) = c\sum u_k + \sum v_k. The same with EE: E(aX+b)=aE(X)+bE(aX + b) = aE(X) + b.
  6. Term-by-term differentiation. Inside the interval where a power series converges, its derivative is the series of the derivatives. And whenever needed: e0=1e^{0} = 1.

Rule 2 is the one I was missing in the mock, so let’s prove it right now. Start from rule 1 as a function of aa:

∑k=0∞ak=11−a \sum_{k=0}^{\infty} a^k = \frac{1}{1-a}

Differentiate both sides with respect to aa (rule 6). On the left, the derivative of aka^k is k ak−1k\,a^{k-1} (the k=0k = 0 term is the constant 1, whose derivative is 0, so the sum starts at 1). On the right, the derivative of (1−a)−1(1-a)^{-1} is (1−a)−2(1-a)^{-2}:

∑k=1∞k ak−1=1(1−a)2 \sum_{k=1}^{\infty} k\,a^{k-1} = \frac{1}{(1-a)^2}

And multiply both sides by aa (rule 5) so that the power becomes aka^k:

∑k=1∞k ak=a(1−a)2 \sum_{k=1}^{\infty} k\,a^{k} = \frac{a}{(1-a)^2}

That is rule 2. Whenever you see a kk multiplying a power, think of it.

Which rule each proof usesDot table: rows with the six rules and columns with the six proofs. The geometric series is used in proofs 4 and 6; the differentiated geometric series, in 1; the exponential, in 2 and 5; Newton, in 3; linearity and term-by-term differentiation, in almost all.D1D2D3D4D5D61 Geometric2 Differentiated geometric3 Exponential4 Newton5 Linearity6 Term-by-term derivative
A big dot is a rule used in that proof. The two geometric series, in coral, are the ones that come up most in the exam.

The diagram is a map: which rule appears in each proof. The geometric series (rule 1) and its derivative (rule 2) are the most used in the topic; the exponential (3) is the Poisson’s and Newton (4), the binomial’s.

Proof 1: a new mass function, its mgf and its mean

This is the exam format. Marta proposes a model for the number of messages in a row that Pablo sends every time he writes in the group (Pablo never sends just one):

P(X=x)=x2x+1,x=1,2,3,… P(X = x) = \frac{x}{2^{x+1}}, \quad x = 1, 2, 3, \ldots

We are asked to: (a) prove it is a mass function; (b) find its moment generating function; (c) calculate E(X)E(X).

Where we are going. To do the whole 15-point exercise. The three parts look like three problems, but they are the same sum: in (a), x x times powers of 1/2 1/2 ; in (b), the same with et/2 e^t/2 instead of 1/2 1/2 ; in (c), differentiating what came out of (b). If you recognise the series once (rule 2), the rest is algebra.

(a) It is a mass function

What has to be proved. The two conditions: that P(X=x)≥0P(X = x) \geq 0 for every x=1,2,…x = 1, 2, \ldots and that ∑x=1∞P(X=x)=1\sum_{x=1}^{\infty} P(X = x) = 1.

The first. For x≥1x \geq 1, the numerator xx is positive and so is the denominator 2x+12^{x+1}. A quotient of positives is positive: P(X=x)>0P(X = x) > 0.

The second. Step 1: split off the extra 2 in the denominator, 2x+1=2⋅2x2^{x+1} = 2 \cdot 2^x, and take it out of the sum (rule 5):

∑x=1∞x2x+1=12∑x=1∞x2x=12∑x=1∞x(12)x \sum_{x=1}^{\infty} \frac{x}{2^{x+1}} = \frac{1}{2} \sum_{x=1}^{\infty} \frac{x}{2^{x}} = \frac{1}{2} \sum_{x=1}^{\infty} x \left(\frac{1}{2}\right)^{x}

Step 2: what is inside is rule 2 with a=1/2a = 1/2, which satisfies ∣a∣<1\lvert a \rvert < 1:

∑x=1∞x(12)x=1/2(1−1/2)2=1/21/4=2 \sum_{x=1}^{\infty} x \left(\frac{1}{2}\right)^{x} = \frac{1/2}{(1 – 1/2)^2} = \frac{1/2}{1/4} = 2

Step 3: put it together.

∑x=1∞P(X=x)=12⋅2=1 \sum_{x=1}^{\infty} P(X = x) = \frac{1}{2} \cdot 2 = 1

Both conditions hold: it is a mass function.

Writing rule 1 where rule 2 belongs. ∑(1/2)x\sum (1/2)^x from x=1x = 1 is 1, and from x=0x = 0 it is 2; but here there is an xx multiplying and neither of them works. If you mix up the rules, the sum can come out as 1 “by luck” with the wrong working, and the marker sees it.

(b) The moment generating function

What has to be proved. We need to calculate φX(t)=E(etX)=∑x=1∞etxP(X=x)\varphi_X(t) = E(e^{tX}) = \sum_{x=1}^{\infty} e^{tx} P(X = x) and say for which tt it exists.

Step 1: write the definition and combine the two powers with exponent xx, because etx=(et)xe^{tx} = (e^t)^x:

φX(t)=∑x=1∞etxx2x+1=12∑x=1∞x(et2)x \varphi_X(t) = \sum_{x=1}^{\infty} e^{tx} \frac{x}{2^{x+1}} = \frac{1}{2} \sum_{x=1}^{\infty} x \left(\frac{e^t}{2}\right)^{x}

Step 2: it is rule 2 again, now with a=et/2a = e^t/2. It only holds if ∣a∣<1\lvert a \rvert < 1: et/2<1e^t / 2 < 1, that is, et<2e^t < 2, that is, t<ln⁡2t < \ln 2. Since ln⁡2≈0.69>0\ln 2 \approx 0.69 > 0, there is an interval around 0 where it exists, which is what the definition requires.

φX(t)=12⋅et/2(1−et/2)2 \varphi_X(t) = \frac{1}{2} \cdot \frac{e^t/2}{(1 – e^t/2)^2}

Step 3: simplify. On top, 12⋅et2=et4\frac{1}{2} \cdot \frac{e^t}{2} = \frac{e^t}{4}. Underneath, 1−et2=2−et21 – \frac{e^t}{2} = \frac{2 – e^t}{2}, and squared, (2−et)24\frac{(2 – e^t)^2}{4}. The two quarters cancel:

φX(t)=et(2−et)2,t<ln⁡2 \boxed{\varphi_X(t) = \frac{e^t}{(2 – e^t)^2}, \quad t < \ln 2}

A quick check worth doing every time: φX(0)=E(e0)=E(1)=1\varphi_X(0) = E(e^{0}) = E(1) = 1. Here, 1(2−1)2=1\frac{1}{(2-1)^2} = 1. It works.

Forgetting to say for which tt the mgf exists. In the exam it is part of the answer: without the condition t<ln⁡2t < \ln 2, the series does not converge and the formula makes no sense.

(c) The expectation

Step 1: E(X)=φX′(0)E(X) = \varphi_X'(0) (we prove it in proof 2). Differentiate with the quotient rule, (uv)′=u′v−uv′v2\left(\frac{u}{v}\right)' = \frac{u'v – uv'}{v^2}, with u=etu = e^t and v=(2−et)2v = (2 – e^t)^2:

  • u′=etu' = e^t.
  • v′=2(2−et)⋅(−et)=−2et(2−et)v' = 2(2 – e^t) \cdot (-e^t) = -2e^t(2 – e^t) (chain rule: the derivative of 2−et2 – e^t is −et-e^t).

Step 2: substitute.

φX′(t)=et(2−et)2+et⋅2et(2−et)(2−et)4 \varphi_X'(t) = \frac{e^t (2 – e^t)^2 + e^t \cdot 2e^t (2 – e^t)}{(2 – e^t)^4}

Why there is a + + in the middle, which is where people go wrong the most. The quotient rule subtracts uv′ u v' , but v′=−2et(2−et) v' = -2e^t(2 – e^t) is negative: minus times minus is plus, and we get + et⋅2et(2−et) + \, e^t \cdot 2e^t(2 – e^t) . Below, v2=((2−et)2)2=(2−et)4 v^2 = \big((2 – e^t)^2\big)^2 = (2 – e^t)^4 .

Step 3: take out the common factor et(2−et)e^t (2 – e^t) on top and cancel one (2−et)(2 – e^t):

φX′(t)=et(2−et)[(2−et)+2et](2−et)4=et(2+et)(2−et)3 \varphi_X'(t) = \frac{e^t (2 – e^t)\big[(2 – e^t) + 2e^t\big]}{(2 – e^t)^4} = \frac{e^t (2 + e^t)}{(2 – e^t)^3}

Step 4: evaluate at t=0t = 0 (rule 6, e0=1e^0 = 1):

E(X)=φX′(0)=1⋅(2+1)(2−1)3=3 E(X) = \varphi_X'(0) = \frac{1 \cdot (2 + 1)}{(2 – 1)^3} = 3

On average, Pablo sends three messages in a row.

Result for the cheat sheet. To sum series with an xx in front: ∑x≥1x ax=a(1−a)2\sum_{x \geq 1} x\,a^x = \frac{a}{(1-a)^2}. And the mgf always satisfies φX(0)=1\varphi_X(0) = 1: use it as a check.

The mass function x / 2^(x + 1)Bars of the mass function x over 2 to the power x plus 1 for x from 1 to 12: 0.25, 0.25, 0.1875, 0.125 and falling. Coral dashed line at the mean, 3. The sum up to x equal to 12 is 0.9983 and tends to 1.0.000.100.200.30123456789101112Pablo's messages in a rowP(X = x)0.250.25E(X) = 3sum up to x = 12:0.9983 → 1
The two tallest bars are at 1 and 2, but the tail pulls the mean up to 3.

The diagram shows the bars of Pablo’s mass function: 0.25 for 1 and for 2 messages, 0.1875 for 3, and a tail that falls slowly. The mean, 3, falls to the right of the tallest bars, as always happens when there is a tail to the right. And the box shows the cumulative sum approaching 1 without going over.

Check it with R

x <- 1:200                                  # 200 terms are enough: the rest is negligible
p <- x / 2^(x + 1)
sum(p)                                      # (a) must be 1
sum(x * p)                                  # E(X) by summing the series
mgf <- function(t) exp(t) / (2 - exp(t))^2
h <- 1e-5
(mgf(h) - mgf(-h)) / (2 * h)                # (c) numerical derivative at 0
sum(exp(0.3 * x) * p); mgf(0.3)             # (b) the mgf at t = 0.3, both ways

Output:

[1] 1
[1] 3
[1] 3
[1] 3.193545
[1] 3.193545

The first line confirms (a), the second and third give the 3 of (c) in two different ways (summing ∑x P(X=x)\sum x\,P(X = x) and differentiating the mgf numerically: the slope between t=−ht = -h and t=ht = h), and the last two check that the formula from (b) gives the same as the original sum at t=0.3t = 0.3. A curious detail: X−1X – 1 is a negative binomial with r=2r = 2 and p=1/2p = 1/2 (check it: dnbinom(0:4, 2, 0.5) gives the same as (1:5) / 2^(2:6)). Its mean is 2⋅0.5/0.5=22 \cdot 0.5 / 0.5 = 2, and adding the 1, 3. One more check.

Check you’ve got it: if Marta had proposed P(X=x)=c x3x+1 P(X = x) = c \, \frac{x}{3^{x+1}} for x=1,2,… x = 1, 2, \ldots , what value of c c turns it into a mass function?

c=4 c = 4 . It is done just like (a): we take out the extra 3, ∑x≥1x3x+1=13∑x≥1x(13)x \sum_{x \geq 1} \frac{x}{3^{x+1}} = \frac{1}{3} \sum_{x \geq 1} x \left(\frac{1}{3}\right)^x , and the inside is rule 2 with a=1/3 a = 1/3 : 1/3(2/3)2=1/34/9=34 \frac{1/3}{(2/3)^2} = \frac{1/3}{4/9} = \frac{3}{4} . All together, 13⋅34=14 \frac{1}{3} \cdot \frac{3}{4} = \frac{1}{4} . For the sum to be 1 you have to multiply by 4. The first condition holds by itself: with c=4>0 c = 4 > 0 , every probability is positive.

Proof 2: the mgf generates the moments, and the variance shortcut

Where we are going. In proof 1 we used E(X)=φX′(0) E(X) = \varphi_X'(0) without proving it. Here we prove it, and it is what makes the mgf useful: differentiating and setting t=0 t = 0 , it keeps handing out E(X) E(X) , E(X2) E(X^2) … The idea: write etX e^{tX} as a series and look at what is left after differentiating. Then the variance shortcut, which is how every variance in the topic is computed.

What has to be proved. Two things:

φX(k)(0)=E(Xk)andVar(X)=E(X2)−[E(X)]2 \varphi_X^{(k)}(0) = E(X^k) \qquad \text{and} \qquad \text{Var}(X) = E(X^2) – [E(X)]^2

The mgf generates the moments

Where we start from. The Taylor (or Maclaurin, around 0) expansion of the exponential, which is rule 3 with z=txz = tx:

etx=∑j=0∞(tx)jj!=1+tx+t2x22!+t3x33!+⋯ e^{tx} = \sum_{j=0}^{\infty} \frac{(tx)^j}{j!} = 1 + tx + \frac{t^2 x^2}{2!} + \frac{t^3 x^3}{3!} + \cdots

Step 1: what holds for every number xx holds for the variable XX. Take expectations on both sides:

φX(t)=E(etX)=E(1+tX+t2X22!+t3X33!+⋯ ) \varphi_X(t) = E\big(e^{tX}\big) = E\left(1 + tX + \frac{t^2 X^2}{2!} + \frac{t^3 X^3}{3!} + \cdots\right)

Step 2: by linearity (rule 5), the expectation of the sum is the sum of the expectations, and the tj/j!t^j/j! are constants (they do not depend on XX), so they come out:

φX(t)=1+t E(X)+t22!E(X2)+t33!E(X3)+⋯ \varphi_X(t) = 1 + t\,E(X) + \frac{t^2}{2!}E(X^2) + \frac{t^3}{3!}E(X^3) + \cdots

Look at what we have: the mgf is a power series in tt whose coefficients carry the moments inside. Now we have to get them out.

Step 3: differentiate once with respect to tt (rule 6). The 1 disappears, t E(X)t\,E(X) leaves E(X)E(X), t22!E(X2)\frac{t^2}{2!}E(X^2) leaves t E(X2)t\,E(X^2), and so on:

φX′(t)=E(X)+t E(X2)+t22!E(X3)+⋯ \varphi_X'(t) = E(X) + t\,E(X^2) + \frac{t^2}{2!}E(X^3) + \cdots

Why the series keeps its shape: the derivative of tjj! \frac{t^j}{j!} is j tj−1j! \frac{j\,t^{j-1}}{j!} , and since j!=j⋅(j−1)! j! = j \cdot (j-1)! , the j j cancels and we are left with tj−1(j−1)! \frac{t^{j-1}}{(j-1)!} . With j=2 j = 2 : t22! \frac{t^2}{2!} becomes 2t2=t \frac{2t}{2} = t . Each term moves down one step and its factorial moves down with it.

Step 4: evaluate at t=0t = 0. Every term with a tt vanishes and only the first survives:

φX′(0)=E(X) \varphi_X'(0) = E(X)

Step 5: if we differentiate again before evaluating, the first surviving term is the one with E(X2)E(X^2): φX′′(t)=E(X2)+t E(X3)+⋯\varphi_X''(t) = E(X^2) + t\,E(X^3) + \cdots, and φX′′(0)=E(X2)\varphi_X''(0) = E(X^2). In general, after differentiating kk times, the terms with powers of tt lower than kk disappear, the tkt^k term leaves exactly E(Xk)E(X^k) (because the kk-th derivative of tkk!\frac{t^k}{k!} is 1) and those with higher powers keep some tt that vanishes at 0:

φX(k)(0)=E(Xk) \boxed{\varphi_X^{(k)}(0) = E(X^k)}
The mgf as a conveyor belt of momentsThree rows: the mgf expanded as 1 plus t times E of X plus t squared over 2 factorial times E of X squared, and its first two derivatives. Each derivative shifts the terms one box to the left; at t equal to 0 only the first box is left: 1, E of X and E of X squared.at t = 0 only the 1st box is leftφ(t) =1+t·E(X)+t²/2!·E(X²)+t³/3!·E(X³)differentiatet = 0 → 1φ'(t) =E(X)+t·E(X²)+t²/2!·E(X³)+…differentiatet = 0 → E(X)φ''(t) =E(X²)+t·E(X³)+…t = 0 → E(X²)
Each derivative pushes the series one box; setting t = 0 wipes out everything with a t.

The diagram shows the mechanism: each derivative “pushes” the series one term to the left, and when you set t=0t = 0 only the one in the first box is left. It is like a conveyor belt that drops one moment each time.

Evaluating at t=1t = 1. At t=1t = 1 nothing vanishes and no clean moment comes out. Always t=0t = 0.

The variance shortcut

Where we start from. From the definition Var(X)=E[(X−μ)2]\text{Var}(X) = E[(X – \mu)^2], with μ=E(X)\mu = E(X), which is a fixed number.

Step 1: expand the square: (X−μ)2=X2−2μX+μ2(X – \mu)^2 = X^2 – 2\mu X + \mu^2.

Step 2: take expectations and apply linearity (rule 5). 2μ2\mu is a constant that multiplies and μ2\mu^2 is a constant that adds:

Var(X)=E(X2)−2μ E(X)+μ2 \text{Var}(X) = E(X^2) – 2\mu\,E(X) + \mu^2

Step 3: since E(X)=μE(X) = \mu, the middle term is 2μ⋅μ=2μ22\mu \cdot \mu = 2\mu^2:

Var(X)=E(X2)−2μ2+μ2=E(X2)−μ2 \text{Var}(X) = E(X^2) – 2\mu^2 + \mu^2 = E(X^2) – \mu^2
Var(X)=E(X2)−[E(X)]2=φX′′(0)−[φX′(0)]2 \boxed{\text{Var}(X) = E(X^2) – [E(X)]^2 = \varphi_X''(0) – [\varphi_X'(0)]^2}

And the variance of aX+baX + b

Same idea: E(aX+b)=aμ+bE(aX + b) = a\mu + b (rule 5), so (aX+b)−(aμ+b)=a(X−μ)(aX + b) – (a\mu + b) = a(X – \mu). The bb has gone. Squared, a2(X−μ)2a^2 (X – \mu)^2, and taking expectations:

Var(aX+b)=a2 Var(X) \boxed{\text{Var}(aX + b) = a^2\,\text{Var}(X)}

Result for the cheat sheet. φX(k)(0)=E(Xk)\varphi_X^{(k)}(0) = E(X^k); Var(X)=E(X2)−[E(X)]2\text{Var}(X) = E(X^2) – [E(X)]^2; Var(aX+b)=a2 Var(X)\text{Var}(aX + b) = a^2\,\text{Var}(X).

Check it with R

With the variable from the theory, how many times a day the group asks “is there class tomorrow?” (0, 1, 2 or 3 times with probabilities 0.4, 0.3, 0.2 and 0.1):

x <- 0:3; p <- c(0.4, 0.3, 0.2, 0.1)
mgf <- function(t) sum(exp(t * x) * p)
h <- 1e-4
d1 <- (mgf(h) - mgf(-h)) / (2 * h)              # first derivative at 0
d2 <- (mgf(h) - 2 * mgf(0) + mgf(-h)) / h^2      # second derivative at 0
c(d1 = d1, EX = sum(x * p), d2 = d2, EX2 = sum(x^2 * p))
c(var_def = sum((x - 1)^2 * p), var_short = d2 - d1^2)
c(var_4X_plus_2 = sum((4 * x + 2 - 6)^2 * p), sixteen_times_var = 16 * 1)

Output:

 d1  EX  d2 EX2 
  1   1   2   2 
  var_def var_short 
        1         1 
    var_4X_plus_2 sixteen_times_var 
               16                16 

The numerical derivatives match E(X)=1E(X) = 1 and E(X2)=2E(X^2) = 2 (the rounding error of the numerical derivative is below what R shows), the variance by the definition and by the shortcut is 1 both times, and the variance of 4X+24X + 2 (mean 6) is 16, which is 424^2 times the variance of XX. The 2 has left no trace.

Check you’ve got it: if all you know about a variable is that its mgf starts φX(t)=1+2t+3t2+⋯ \varphi_X(t) = 1 + 2t + 3t^2 + \cdots , what are E(X) E(X) , E(X2) E(X^2) and Var(X) \text{Var}(X) ?

Compare coefficients with step 2, φX(t)=1+t E(X)+t22!E(X2)+⋯ \varphi_X(t) = 1 + t\,E(X) + \frac{t^2}{2!}E(X^2) + \cdots . The coefficient of t t gives E(X)=2 E(X) = 2 . The one of t2 t^2 is E(X2)/2! E(X^2)/2! , so E(X2)/2=3 E(X^2)/2 = 3 and E(X2)=6 E(X^2) = 6 , not 3: the typical mistake is forgetting the 2! 2! . The variance shortcut gives 6−22=2 6 – 2^2 = 2 . It is the mgf of a Poisson with λ=2 \lambda = 2 (proof 5): mean 2 and variance 2.

Proof 3: the binomial (adds up to 1, mgf, mean and variance)

Where we are going. To justify the two binomial formulas you use without thinking: with ten messages and 30% memes, np=3 np = 3 on average and a variance of np(1−p)=2.1 np(1-p) = 2.1 . A single tool, Newton’s binomial, works twice: with p p (adds up to 1) and with p et p\,e^t (the mgf). Then two derivatives; the second one is where marks are lost.

What has to be proved. If P(X=k)=(nk)pk(1−p)n−kP(X = k) = \binom{n}{k} p^k (1-p)^{n-k} for k=0,…,nk = 0, \ldots, n, with 0<p<10 < p < 1:

∑k=0nP(X=k)=1φX(t)=(1−p+p et)nE(X)=npVar(X)=np(1−p) \sum_{k=0}^{n} P(X = k) = 1 \qquad \varphi_X(t) = (1 – p + p\,e^t)^n \qquad E(X) = np \qquad \text{Var}(X) = np(1-p)

It adds up to 1

The probabilities are non-negative (products of a binomial coefficient and powers of positive numbers). For the sum, Newton’s binomial theorem (rule 4) with a=pa = p and b=1−pb = 1 – p:

∑k=0n(nk)pk(1−p)n−k=(p+(1−p))n=1n=1 \sum_{k=0}^{n} \binom{n}{k} p^k (1-p)^{n-k} = \big(p + (1 – p)\big)^n = 1^n = 1

That is where the name comes from: the binomial probabilities are the terms of the expansion of a binomial.

The mgf

Step 1: definition. Put etke^{tk} inside and combine it with pkp^k, because both have exponent kk:

φX(t)=∑k=0netk(nk)pk(1−p)n−k=∑k=0n(nk)(p et)k(1−p)n−k \varphi_X(t) = \sum_{k=0}^{n} e^{tk} \binom{n}{k} p^k (1-p)^{n-k} = \sum_{k=0}^{n} \binom{n}{k} (p\,e^t)^k (1-p)^{n-k}

Step 2: it is Newton’s theorem again, now with a=p eta = p\,e^t and b=1−pb = 1 – p:

φX(t)=(1−p+p et)nfor every t \boxed{\varphi_X(t) = (1 – p + p\,e^t)^n} \quad \text{for every } t

Since it is a finite sum, it exists for any tt: there is no condition.

Newton's binomial twiceTop, p plus 1 minus p to the power n is the sum of the binomial probabilities and equals 1. Bottom, replacing p with p times e to the t, the same sum gives the mgf.adds up to 1(p + (1 − p))ⁿ=Σ C(n,k) · (p)ᵏ · (1 − p)ⁿ⁻ᵏ=1ⁿ = 1the mgf(p·eᵗ + (1 − p))ⁿ=Σ C(n,k) · (p·eᵗ)ᵏ · (1 − p)ⁿ⁻ᵏ=φ(t)put eᵗᵏ inside pᵏ: eᵗᵏ · pᵏ = (p·eᵗ)ᵏ
The same calculation with p and with p·eᵗ: the first proves it adds up to 1 and the second gives the mgf.

In the diagram, the same Newton expansion appears twice: on top with pp and 1−p1 – p (adds up to 1) and underneath with p etp\,e^t instead of pp (the mgf). The trick of putting etke^{tk} inside the power of pp is the same as in proof 1, and you will see it again in the Poisson.

Mean and variance

Step 1: first derivative, with the chain rule (the derivative of the inside, 1−p+p et1 – p + p\,e^t, is p etp\,e^t):

φX′(t)=n(1−p+p et)n−1⋅p et \varphi_X'(t) = n (1 – p + p\,e^t)^{n-1} \cdot p\,e^t

At t=0t = 0, the inside is 1−p+p=11 – p + p = 1 and e0=1e^0 = 1:

E(X)=φX′(0)=n⋅1n−1⋅p=np E(X) = \varphi_X'(0) = n \cdot 1^{n-1} \cdot p = np

Step 2: second derivative. φX′(t)\varphi_X'(t) is a product of npn p, (1−p+p et)n−1(1 – p + p\,e^t)^{n-1} and ete^t; differentiate with the product rule:

φX′′(t)=n(n−1)(1−p+p et)n−2(p et)2+n(1−p+p et)n−1p et \varphi_X''(t) = n(n-1)(1 – p + p\,e^t)^{n-2} (p\,e^t)^2 + n (1 – p + p\,e^t)^{n-1} p\,e^t

The second derivative, piece by piece. φX′(t) \varphi_X'(t) is n n times two factors with t t in them: (1−p+p et)n−1 (1 – p + p\,e^t)^{n-1} and p et p\,e^t . Differentiating the first gives (n−1)(1−p+p et)n−2⋅p et (n-1)(1 – p + p\,e^t)^{n-2} \cdot p\,e^t (chain rule), and with the p et p\,e^t that was already there we get (p et)2 (p\,e^t)^2 : the first term. Differentiating p et p\,e^t gives p et p\,e^t : the second term, which is φX′(t) \varphi_X'(t) again. At t=0 t = 0 , every bracket and every et e^t equals 1.

At t=0t = 0: E(X2)=φX′′(0)=n(n−1)p2+npE(X^2) = \varphi_X''(0) = n(n-1)p^2 + np.

Step 3: variance shortcut (proof 2):

Var(X)=n(n−1)p2+np−(np)2=n2p2−np2+np−n2p2=np−np2=np(1−p) \text{Var}(X) = n(n-1)p^2 + np – (np)^2 = n^2p^2 – np^2 + np – n^2p^2 = np – np^2 = np(1-p)

In the second derivative, forgetting that ete^t also depends on tt and differentiating only the power. You get E(X2)=n(n−1)p2E(X^2) = n(n-1)p^2 and a negative variance. If your variance comes out negative, check the product rule.

Result for the cheat sheet. X∼Binom(n,p)X \sim \text{Binom}(n, p): φX(t)=(1−p+p et)n\varphi_X(t) = (1 – p + p\,e^t)^n, E(X)=npE(X) = np, Var(X)=np(1−p)\text{Var}(X) = np(1-p).

Check it with R

n <- 10; p <- 0.3; k <- 0:n
pk <- dbinom(k, n, p)
c(sum = sum(pk), mean = sum(k * pk), np = n * p)
c(EX2 = sum(k^2 * pk), formula = n * (n - 1) * p^2 + n * p)
c(var = sum(k^2 * pk) - sum(k * pk)^2, npq = n * p * (1 - p))
t <- 0.4
c(mgf_sum = sum(exp(t * k) * pk), mgf_formula = (1 - p + p * exp(t))^n)

Output:

 sum mean   np 
   1    3    3 
    EX2 formula 
   11.1    11.1 
var npq 
2.1 2.1 
    mgf_sum mgf_formula 
   3.960102    3.960102 

With the ten messages and 30% memes: the sum is 1, the mean 3, E(X2)=11.1E(X^2) = 11.1 both ways (90⋅0.09+3=8.1+390 \cdot 0.09 + 3 = 8.1 + 3), the variance 2.1, and the mgf at t=0.4t = 0.4 matches when summed term by term and with the formula.

Check you’ve got it: if X X counts the memes among the ten messages, what is the variance of Y=10−X Y = 10 – X , the messages that are not memes? Do it in two ways.

By proof 2: Y=−1⋅X+10 Y = -1 \cdot X + 10 , so Var(Y)=(−1)2 Var(X)=2.1 \text{Var}(Y) = (-1)^2 \, \text{Var}(X) = 2.1 . The minus sign disappears when squared and the 10 leaves no trace. By the binomial: Y Y counts the messages that are not memes, each with probability 0.7, so Y∼Binom(10,0.7) Y \sim \text{Binom}(10, 0.7) and Var(Y)=10⋅0.7⋅0.3=2.1 \text{Var}(Y) = 10 \cdot 0.7 \cdot 0.3 = 2.1 . It checks out: np(1−p) np(1-p) does not change if you swap p p and 1−p 1 – p .

Proof 4: the geometric (adds up to 1, its closed-form F and memorylessness)

Where we are going. X X counts the useless messages before the first useful one (each one is useful with probability p p ). We want it to add up to 1, a closed-form F(n) F(n) so we don’t have to add term by term, and memorylessness, which the exam asks you to prove and interpret. The piece that ties it all together is the tail, P(X≥n)=(1−p)n P(X \geq n) = (1-p)^n .

What has to be proved. If P(X=k)=(1−p)kpP(X = k) = (1-p)^k p for k=0,1,2,…k = 0, 1, 2, \ldots, with 0<p<10 < p < 1:

∑k=0∞P(X=k)=1F(n)=1−(1−p)n+1P(X≥m+k∣X≥m)=P(X≥k) \sum_{k=0}^{\infty} P(X = k) = 1 \qquad F(n) = 1 – (1-p)^{n+1} \qquad P(X \geq m + k \mid X \geq m) = P(X \geq k)

And, while we are at it, its mean.

It adds up to 1

Step 1: take out pp, which does not depend on kk (rule 5):

∑k=0∞(1−p)kp=p∑k=0∞(1−p)k \sum_{k=0}^{\infty} (1-p)^k p = p \sum_{k=0}^{\infty} (1-p)^k

Step 2: rule 1 with a=1−pa = 1 – p. Since 0<p<10 < p < 1, also 0<1−p<10 < 1 – p < 1, and the series converges:

p⋅11−(1−p)=p⋅1p=1 p \cdot \frac{1}{1 – (1-p)} = p \cdot \frac{1}{p} = 1

The closed-form distribution function

What has to be proved. F(n)=P(X≤n)=1−(1−p)n+1F(n) = P(X \leq n) = 1 – (1-p)^{n+1} for n=0,1,2,…n = 0, 1, 2, \ldots.

Step 1: F(n)F(n) is a finite sum:

F(n)=∑k=0n(1−p)kp=p∑k=0n(1−p)k F(n) = \sum_{k=0}^{n} (1-p)^k p = p \sum_{k=0}^{n} (1-p)^k

Step 2: the finite sum from rule 1 with a=1−pa = 1 – p:

F(n)=p⋅1−(1−p)n+11−(1−p)=p⋅1−(1−p)n+1p=1−(1−p)n+1 F(n) = p \cdot \frac{1 – (1-p)^{n+1}}{1 – (1-p)} = p \cdot \frac{1 – (1-p)^{n+1}}{p} = 1 – (1-p)^{n+1}

In the problem sheets you may be asked to prove the finite sum by induction. For n=0n = 0: ∑k=00ak=1\sum_{k=0}^{0} a^k = 1 and 1−a1−a=1\frac{1 – a}{1 – a} = 1. If it holds for nn, for n+1n + 1 one more term is added:

1−an+11−a+an+1=1−an+1+an+1−an+21−a=1−an+21−a \frac{1 – a^{n+1}}{1 – a} + a^{n+1} = \frac{1 – a^{n+1} + a^{n+1} – a^{n+2}}{1 – a} = \frac{1 – a^{n+2}}{1 – a}

which is the formula for n+1n + 1. It is proved for every nn.

A consequence we are about to use: the tail is a power.

P(X≥n)=1−P(X≤n−1)=1−(1−(1−p)n)=(1−p)n P(X \geq n) = 1 – P(X \leq n – 1) = 1 – \big(1 – (1-p)^n\big) = (1-p)^n

It makes sense: “at least nn useless ones before the useful one” is the same as “the first nn messages are useless”, and that has probability (1−p)n(1-p)^n.

Why n−1 n – 1 : X X only takes integer values, so the opposite of “X≥n X \geq n ” is “X≤n−1 X \leq n – 1 “, not “X≤n X \leq n ” (the value n n is inside the tail). And in F(n−1) F(n-1) the exponent becomes (n−1)+1=n (n-1) + 1 = n . With p=0.2 p = 0.2 and n=3 n = 3 : 1−F(2)=0.83=0.512 1 – F(2) = 0.8^3 = 0.512 , the number in the memorylessness diagram.

Memorylessness

What has to be proved. For m,k≥0m, k \geq 0: P(X≥m+k∣X≥m)=P(X≥k)P(X \geq m + k \mid X \geq m) = P(X \geq k).

Step 1: definition of conditional probability (topic 2):

P(X≥m+k∣X≥m)=P(X≥m+k ∩ X≥m)P(X≥m) P(X \geq m + k \mid X \geq m) = \frac{P(X \geq m + k \,\cap\, X \geq m)}{P(X \geq m)}

Step 2: if X≥m+kX \geq m + k, then certainly X≥mX \geq m (because k≥0k \geq 0). The intersection is just the smaller event:

=P(X≥m+k)P(X≥m) = \frac{P(X \geq m + k)}{P(X \geq m)}

Step 3: use the tail we just calculated:

=(1−p)m+k(1−p)m=(1−p)k=P(X≥k) = \frac{(1-p)^{m+k}}{(1-p)^m} = (1-p)^k = P(X \geq k)
The geometric has no memoryTop, three useless messages from the start: probability 0.8 cubed, 0.512. Bottom, five already read in light grey and three more highlighted: the conditional probability is also 0.512.From the startP(X ≥ 3) = 0.8³ = 0.512If you have already read 5 useless onesalready read3 moreP(X ≥ 8 | X ≥ 5) = 0.8³ = 0.512
What you have already read does not count: the probability of three more useless ones is the same as at the start.

In the diagram, the same read of the group seen two ways: from the start, the probability of at least 3 useless ones is 0.83=0.5120.8^3 = 0.512; if you have already read 5 useless ones and start counting again, the probability of at least 3 more is 0.512 again. What you have already read does not change what is left.

Thinking that “after so many useless messages, the useful one must be about to arrive”. It is the gambler’s fallacy: if the messages are independent, the geometric has no memory and the remaining wait is the same as at the start.

The mean

With the mgf. Step 1: φX(t)=∑k≥0etk(1−p)kp=p∑k≥0((1−p)et)k\varphi_X(t) = \sum_{k \geq 0} e^{tk} (1-p)^k p = p \sum_{k \geq 0} \big((1-p)e^t\big)^k and, by rule 1 with a=(1−p)eta = (1-p)e^t (which needs (1−p)et<1(1-p)e^t < 1, that is, t<−ln⁡(1−p)t < -\ln(1-p)):

φX(t)=p1−(1−p)et \varphi_X(t) = \frac{p}{1 – (1-p)e^t}

Step 2: the derivative of p (1−(1−p)et)−1p\,\big(1 – (1-p)e^t\big)^{-1} is p (1−p)et (1−(1−p)et)−2p\,(1-p)e^t\,\big(1 – (1-p)e^t\big)^{-2}. At t=0t = 0, 1−(1−p)=p1 – (1-p) = p:

E(X)=p(1−p)p2=1−pp E(X) = \frac{p(1-p)}{p^2} = \frac{1-p}{p}

Why that derivative: it is the chain rule with two minus signs. The exponent −1 -1 comes down and leaves −(1−(1−p)et)−2 -\big(1 – (1-p)e^t\big)^{-2} , and the inside differentiates to −(1−p)et -(1-p)e^t : minus times minus, plus. At t=0 t = 0 the bracket equals p p , and squared, p2 p^2 . With p=0.2 p = 0.2 : 0.8/0.2=4 0.8/0.2 = 4 , the simulated mean.

Result for the cheat sheet. X∼geom(p)X \sim \text{geom}(p) (failures before the first success): F(n)=1−(1−p)n+1F(n) = 1 – (1-p)^{n+1}, P(X≥n)=(1−p)nP(X \geq n) = (1-p)^n, φX(t)=p1−(1−p)et\varphi_X(t) = \frac{p}{1 – (1-p)e^t}, E(X)=1−ppE(X) = \frac{1-p}{p}, Var(X)=1−pp2\text{Var}(X) = \frac{1-p}{p^2}, memoryless.

Check it with R

p <- 0.2
c(sum = sum(dgeom(0:500, p)), F7 = pgeom(7, p), formula = 1 - (1 - p)^8)
set.seed(3)
x <- rgeom(100000, p)                 # 100,000 simulated reads of the group
c(P_at_least_3 = mean(x >= 3),
  P_3_more_given_5 = mean(x[x >= 5] >= 8),
  theoretical = (1 - p)^3)
c(simulated_mean = mean(x), theoretical = (1 - p) / p)

Output:

      sum        F7   formula 
1.0000000 0.8322278 0.8322278 
    P_at_least_3 P_3_more_given_5      theoretical 
       0.5107900        0.5135715        0.5120000 
simulated_mean    theoretical 
         3.996          4.000 

The sum is 1 and F(7)F(7) matches the closed formula. In the simulation, the proportion of reads with at least 3 useless ones and the proportion of those that, having reached 5, reach 8, both come out close to 0.512 (the small differences are the randomness of the simulation). The simulated mean stays close to 4.

Check you’ve got it: with p=0.2 p = 0.2 , you have already read 5 useless messages. What is the probability that the useful one arrives in the next two?

0.36. “In the next two” is X≤6 X \leq 6 given X≥5 X \geq 5 , which is the opposite of X≥7 X \geq 7 given X≥5 X \geq 5 . By memorylessness with m=5 m = 5 and k=2 k = 2 , P(X≥7∣X≥5)=P(X≥2)=0.82=0.64 P(X \geq 7 \mid X \geq 5) = P(X \geq 2) = 0.8^2 = 0.64 , so the answer is 1−0.64=0.36 1 – 0.64 = 0.36 . It is the same as if you started reading now: the five useless ones do not bring the useful one any closer.

Proof 5: the Poisson (adds up to 1, mgf, mean equal to variance)

Where we are going. With 4 messages on average every ten minutes, to the Poisson property that gets asked the most: the mean and the variance are equal, λ \lambda . One series is enough, the exponential (rule 3), which plays here the role Newton played in the binomial, and the mgf is almost free to differentiate because the derivative of eg(t) e^{g(t)} contains eg(t) e^{g(t)} again. At the end, the mean without the mgf, by reindexing the sum.

What has to be proved. If P(X=k)=e−λλkk!P(X = k) = e^{-\lambda} \frac{\lambda^k}{k!} for k=0,1,2,…k = 0, 1, 2, \ldots, with λ>0\lambda > 0:

∑k=0∞P(X=k)=1φX(t)=eλ(et−1)E(X)=Var(X)=λ \sum_{k=0}^{\infty} P(X = k) = 1 \qquad \varphi_X(t) = e^{\lambda(e^t – 1)} \qquad E(X) = \text{Var}(X) = \lambda

It adds up to 1

The probabilities are positive (exponential, power of λ>0\lambda > 0 and factorial). Step 1: e−λe^{-\lambda} does not depend on kk and comes out (rule 5). Step 2: what is left is the exponential series (rule 3) with z=λz = \lambda:

∑k=0∞e−λλkk!=e−λ∑k=0∞λkk!=e−λeλ=1 \sum_{k=0}^{\infty} e^{-\lambda} \frac{\lambda^k}{k!} = e^{-\lambda} \sum_{k=0}^{\infty} \frac{\lambda^k}{k!} = e^{-\lambda} e^{\lambda} = 1

The mgf

Step 1: put etke^{tk} inside the power, as in the binomial: etkλk=(λet)ke^{tk}\lambda^k = (\lambda e^t)^k.

φX(t)=∑k=0∞etke−λλkk!=e−λ∑k=0∞(λet)kk! \varphi_X(t) = \sum_{k=0}^{\infty} e^{tk} e^{-\lambda} \frac{\lambda^k}{k!} = e^{-\lambda} \sum_{k=0}^{\infty} \frac{(\lambda e^t)^k}{k!}

Step 2: rule 3 with z=λetz = \lambda e^t, which holds for any tt:

φX(t)=e−λeλet=eλet−λ⇒φX(t)=eλ(et−1) \varphi_X(t) = e^{-\lambda} e^{\lambda e^t} = e^{\lambda e^t – \lambda} \quad \Rightarrow \quad \boxed{\varphi_X(t) = e^{\lambda(e^t – 1)}}

Mean and variance

Step 1: the derivative of eg(t)e^{g(t)} is eg(t)g′(t)e^{g(t)} g'(t). Here g(t)=λ(et−1)g(t) = \lambda(e^t – 1) and g′(t)=λetg'(t) = \lambda e^t:

φX′(t)=λet φX(t)⇒E(X)=φX′(0)=λ⋅1⋅1=λ \varphi_X'(t) = \lambda e^t \, \varphi_X(t) \qquad \Rightarrow \qquad E(X) = \varphi_X'(0) = \lambda \cdot 1 \cdot 1 = \lambda

(at t=0t = 0, φX(0)=e0=1\varphi_X(0) = e^{0} = 1).

Step 2: the second derivative is that of a product, λet\lambda e^t times φX(t)\varphi_X(t):

φX′′(t)=λetφX(t)+λetφX′(t)=λetφX(t)+(λet)2φX(t) \varphi_X''(t) = \lambda e^t \varphi_X(t) + \lambda e^t \varphi_X'(t) = \lambda e^t \varphi_X(t) + (\lambda e^t)^2 \varphi_X(t)

At t=0t = 0: E(X2)=λ+λ2E(X^2) = \lambda + \lambda^2.

Step 3: Var(X)=λ+λ2−λ2=λ\text{Var}(X) = \lambda + \lambda^2 – \lambda^2 = \lambda.

Result for the cheat sheet. X∼Pois(λ)X \sim \text{Pois}(\lambda): φX(t)=eλ(et−1)\varphi_X(t) = e^{\lambda(e^t – 1)}, E(X)=Var(X)=λE(X) = \text{Var}(X) = \lambda.

If an exercise gives you a mass function with θxx!\frac{\theta^x}{x!} and a constant, the sum is almost certainly done with rule 3. And if it starts at x=1x = 1 instead of 0, the x=0x = 0 term of the series is missing: ∑x≥1θxx!=eθ−1\sum_{x \geq 1} \frac{\theta^x}{x!} = e^\theta – 1.

The mean without the mgf: reindexing the sum

Sometimes the question asks for E(X) E(X) “directly”, without the mgf. Then you add up ∑k P(X=k) \sum k\,P(X = k) , and the trick is to make the exponential series appear again. Three steps:

  • The k=0 k = 0 term is 0⋅P(X=0)=0 0 \cdot P(X = 0) = 0 , so the sum can start at k=1 k = 1 .
  • For k≥1 k \geq 1 , kk!=1(k−1)! \frac{k}{k!} = \frac{1}{(k-1)!} , because k!=k⋅(k−1)! k! = k \cdot (k-1)! . And we take out one λ \lambda : λk=λ⋅λk−1 \lambda^k = \lambda \cdot \lambda^{k-1} .
  • We call j=k−1 j = k – 1 . When k k goes from 1 to infinity, j j goes from 0 to infinity: it is rule 3, starting where it has to start.
E(X)=∑k=1∞k e−λλkk!=λe−λ∑k=1∞λk−1(k−1)!=λe−λ∑j=0∞λjj!=λe−λeλ=λ E(X) = \sum_{k=1}^{\infty} k\,e^{-\lambda} \frac{\lambda^k}{k!} = \lambda e^{-\lambda} \sum_{k=1}^{\infty} \frac{\lambda^{k-1}}{(k-1)!} = \lambda e^{-\lambda} \sum_{j=0}^{\infty} \frac{\lambda^{j}}{j!} = \lambda e^{-\lambda} e^{\lambda} = \lambda

Reindexing does not change any term: it only renames them.

Reindexing halfway. If you replace k k with j+1 j + 1 inside and leave the sum starting at 1, you are missing the j=0 j = 0 term, which is 1, and you get λ(1−e−λ) \lambda(1 – e^{-\lambda}) instead of λ \lambda .

Check it with R

lambda <- 4; k <- 0:100
pk <- dpois(k, lambda)
c(sum = sum(pk), mean = sum(k * pk), variance = sum(k^2 * pk) - sum(k * pk)^2)
t <- 0.5
c(mgf_sum = sum(exp(t * k) * pk), mgf_formula = exp(lambda * (exp(t) - 1)))

Output:

     sum     mean variance 
       1        4        4 
    mgf_sum mgf_formula 
   13.39505    13.39505 

With 4 messages on average every ten minutes: sum 1, mean 4 and variance 4; and the mgf at t=0.5t = 0.5 gives the same by summing as with the formula.

Check you’ve got it: with the same reindexing trick, what is E[X(X−1)] E[X(X-1)] for the Poisson? How do you get the variance from it?

λ2 \lambda^2 . Now the k=0 k = 0 and k=1 k = 1 terms vanish (both have a factor 0), and for k≥2 k \geq 2 , k(k−1)k!=1(k−2)! \frac{k(k-1)}{k!} = \frac{1}{(k-2)!} . Taking out λ2 \lambda^2 and calling j=k−2 j = k – 2 , we are left with λ2e−λ∑j≥0λjj!=λ2 \lambda^2 e^{-\lambda} \sum_{j \geq 0} \frac{\lambda^j}{j!} = \lambda^2 . Since X(X−1)=X2−X X(X-1) = X^2 – X , by linearity E(X2)=λ2+λ E(X^2) = \lambda^2 + \lambda , the same as with the mgf, and the variance is λ2+λ−λ2=λ \lambda^2 + \lambda – \lambda^2 = \lambda . With λ=4 \lambda = 4 , E[X(X−1)]=16 E[X(X-1)] = 16 .

Proof 6: the mean as a sum of tails

Where we are going. To another way of computing the mean: instead of multiplying each value by its probability, adding up the tails P(X≥n) P(X \geq n) . It matters because sometimes the tails are simpler than the mass (in the geometric, (1−p)n (1-p)^n ) and the mean comes out without differentiating. No new series is needed: just counting the same thing by rows and by columns.

What has to be proved. If XX only takes non-negative integer values (0,1,2,…0, 1, 2, \ldots) and has a finite mean:

E(X)=∑n=1∞P(X≥n) E(X) = \sum_{n=1}^{\infty} P(X \geq n)

It is exercise 5 from the problem sheets with a different face, and it gives a very quick way to get the mean of the geometric.

Where we start from. Write pn=P(X=n)p_n = P(X = n). Then E(X)=∑n=0∞n pn=0⋅p0+1⋅p1+2⋅p2+3⋅p3+⋯E(X) = \sum_{n=0}^{\infty} n\,p_n = 0 \cdot p_0 + 1 \cdot p_1 + 2 \cdot p_2 + 3 \cdot p_3 + \cdots

Step 1: write each n pnn\,p_n as nn copies of pnp_n and put each copy in a different row:

E(X)=  p1+p2+p3+p4+⋯+  p1+  p2+p3+p4+⋯+  p1+p2+  p3+p4+⋯+  ⋯ \begin{aligned} E(X) = \; & p_1 + p_2 + p_3 + p_4 + \cdots \\ + \; & \phantom{p_1 +\;} p_2 + p_3 + p_4 + \cdots \\ + \; & \phantom{p_1 + p_2 +\;} p_3 + p_4 + \cdots \\ + \; & \cdots \end{aligned}

In the first column, p1p_1 appears once; in the second, p2p_2 appears twice (rows 1 and 2); in the third, p3p_3 appears three times. Adding by columns gives 1⋅p1+2⋅p2+3⋅p3+⋯1 \cdot p_1 + 2 \cdot p_2 + 3 \cdot p_3 + \cdots, which is the mean.

Step 2: now add by rows. The first row is p1+p2+⋯=P(X≥1)p_1 + p_2 + \cdots = P(X \geq 1); the second, p2+p3+⋯=P(X≥2)p_2 + p_3 + \cdots = P(X \geq 2); the nn-th, P(X≥n)P(X \geq n). Since all the terms are positive, we can rearrange them without changing the sum:

E(X)=P(X≥1)+P(X≥2)+P(X≥3)+⋯=∑n=1∞P(X≥n) \boxed{E(X) = P(X \geq 1) + P(X \geq 2) + P(X \geq 3) + \cdots = \sum_{n=1}^{\infty} P(X \geq n)}
The mean as a sum of tailsThree rows of blocks for the variable with P of 1 equal to 0.3, P of 2 equal to 0.2 and P of 3 equal to 0.1. Row 1 has p1, p2 and p3 and adds up to 0.6; row 2, p2 and p3, 0.3; row 3, p3, 0.1. By columns, p1 appears once, p2 twice and p3 three times; the rows add up to 1, the mean.P(X ≥ 1)p1p2p3= 0.6P(X ≥ 2)p2p3= 0.3P(X ≥ 3)p3= 0.1By columns: p1 once, p2 twice, p3 three times → Σ n·pn = E(X)By rows: 0.6 + 0.3 + 0.1 = 1 = E(X)
The same staircase added by rows (tails) or by columns (n·pn) gives the same area: the mean.

The diagram is the same idea with blocks: the mean is the area of a staircase. Counted by columns (each value nn with its height n pnn\,p_n) or by rows (each tail P(X≥n)P(X \geq n)), the area is the same.

With numbers, to see that rows and columns give the same result. The “is there class tomorrow?” variable has p1=0.3 p_1 = 0.3 , p2=0.2 p_2 = 0.2 and p3=0.1 p_3 = 0.1 (and p0=0.4 p_0 = 0.4 , which does not appear because it is multiplied by 0):

n n Column n pn n\,p_n Row P(X≥n) P(X \geq n) Why
11⋅0.3=0.3 1 \cdot 0.3 = 0.3 0.3+0.2+0.1=0.6 0.3 + 0.2 + 0.1 = 0.6 Row 1 has one copy of every pn p_n with n≥1 n \geq 1
22⋅0.2=0.4 2 \cdot 0.2 = 0.4 0.2+0.1=0.3 0.2 + 0.1 = 0.3 Row 2 starts at p2 p_2 : p1 p_1 has already used its only copy
33⋅0.1=0.3 3 \cdot 0.1 = 0.3 0.1 0.1 Only p3 p_3 has a third copy
Total11The same six copies, grouped differently

Applying it to the geometric. Since P(X≥n)=(1−p)nP(X \geq n) = (1-p)^n (proof 4):

E(X)=∑n=1∞(1−p)n=11−(1−p)−1=1p−1=1−pp E(X) = \sum_{n=1}^{\infty} (1-p)^n = \frac{1}{1 – (1-p)} – 1 = \frac{1}{p} – 1 = \frac{1-p}{p}

(rule 1 starts at 0; the sum from 1 is that minus the first term, which is 1). The same mean as with the mgf, without differentiating.

Starting the sum at n=0n = 0. P(X≥0)=1P(X \geq 0) = 1 always, and if you add it you get the mean plus one. The sum starts at 1.

Result for the cheat sheet. If X∈{0,1,2,…}X \in \{0, 1, 2, \ldots\}: E(X)=∑n≥1P(X≥n)E(X) = \sum_{n \geq 1} P(X \geq n).

Check it with R

p <- 0.2; n <- 1:500
tails <- 1 - pgeom(n - 1, p)          # P(X >= n) = 1 - P(X <= n - 1)
c(tail_sum = sum(tails), mean = (1 - p) / p)
x <- 0:3; px <- c(0.4, 0.3, 0.2, 0.1)    # and with "is there class tomorrow?"
c(tail_sum = sum(rev(cumsum(rev(px)))[-1]), mean = sum(x * px))

Output:

tail_sum     mean 
       4        4 
tail_sum     mean 
       1        1 

With the geometric the sum of tails is 4, which is the mean. With the “is there class tomorrow?” variable, the tails are P(X≥1)=0.6P(X \geq 1) = 0.6, P(X≥2)=0.3P(X \geq 2) = 0.3 and P(X≥3)=0.1P(X \geq 3) = 0.1; they add up to 1, which is its mean. (rev(cumsum(rev(px))) accumulates from the right: it gives P(X≥0),P(X≥1),…P(X \geq 0), P(X \geq 1), \ldots, and [-1] removes the n=0n = 0 one.)

Check you’ve got it: the tail of Pablo’s variable (proof 1) is P(X≥n)=n+12n P(X \geq n) = \frac{n+1}{2^n} . Do you get its mean, 3, by adding up tails?

Yes. First, a check of the tail: P(X≥1)=2/2=1 P(X \geq 1) = 2/2 = 1 , because Pablo always sends at least one message, and P(X≥2)=3/4=1−0.25 P(X \geq 2) = 3/4 = 1 – 0.25 . We split the sum in two: ∑n≥1n+12n=∑n≥1n(12)n+∑n≥1(12)n \sum_{n \geq 1} \frac{n+1}{2^n} = \sum_{n \geq 1} n \left(\frac{1}{2}\right)^n + \sum_{n \geq 1} \left(\frac{1}{2}\right)^n . The first is rule 2 with a=1/2 a = 1/2 , which equals 2 (step 2 of proof 1). The second is rule 1 minus its n=0 n = 0 term: 2−1=1 2 – 1 = 1 . Total, 2+1=3 2 + 1 = 3 : the same mean as differentiating the mgf, without the quotient rule.

Prove it yourself

Three more proofs to practice. Try them on paper before opening the solution.

1. The negative binomial. Let P(X=k)=(k+r−1k)pr(1−p)kP(X = k) = \binom{k + r – 1}{k} p^r (1-p)^k, k=0,1,2,…k = 0, 1, 2, \ldots Using that, for ∣a∣<1\lvert a \rvert < 1, ∑k=0∞(k+r−1k)ak=(1−a)−r\sum_{k=0}^{\infty} \binom{k + r – 1}{k} a^k = (1 – a)^{-r}, prove that it adds up to 1, that its mgf is (p1−(1−p)et)r\left(\frac{p}{1 – (1-p)e^t}\right)^r and that E(X)=r(1−p)pE(X) = \frac{r(1-p)}{p}.

Solution for the negative binomial

It adds up to 1. Take out prp^r (rule 5) and apply the identity with a=1−pa = 1 – p: ∑k(k+r−1k)pr(1−p)k=pr(1−(1−p))−r=prp−r=1\sum_k \binom{k + r – 1}{k} p^r (1-p)^k = p^r (1 – (1 – p))^{-r} = p^r p^{-r} = 1.

mgf. φX(t)=pr∑k(k+r−1k)((1−p)et)k=pr(1−(1−p)et)−r=(p1−(1−p)et)r\varphi_X(t) = p^r \sum_k \binom{k + r – 1}{k} \big((1-p)e^t\big)^k = p^r \big(1 – (1-p)e^t\big)^{-r} = \left(\frac{p}{1 – (1-p)e^t}\right)^r, if (1−p)et<1(1-p)e^t < 1.

Mean. By the chain rule, φX′(t)=r(p1−(1−p)et)r−1⋅p(1−p)et(1−(1−p)et)2\varphi_X'(t) = r \left(\frac{p}{1 – (1-p)e^t}\right)^{r-1} \cdot \frac{p(1-p)e^t}{\big(1 – (1-p)e^t\big)^2}. At t=0t = 0 the first factor is r⋅1r−1=rr \cdot 1^{r-1} = r and the second p(1−p)p2=1−pp\frac{p(1-p)}{p^2} = \frac{1-p}{p}. So E(X)=r(1−p)pE(X) = \frac{r(1-p)}{p}. With r=3r = 3 and p=0.2p = 0.2, 12 useless ones on average before the third useful one.

2. The Poisson recurrence. If X∼Pois(λ)X \sim \text{Pois}(\lambda), prove that P(X=k)=λkP(X=k−1)P(X = k) = \frac{\lambda}{k} P(X = k – 1) for k≥1k \geq 1 and use it to calculate P(X≤2)P(X \leq 2) with λ=4\lambda = 4 without factorials.

Solution for the Poisson recurrence

Divide two consecutive probabilities: P(X=k)P(X=k−1)=e−λλk/k!e−λλk−1/(k−1)!=λk(k−1)!λk−1k!=λk\frac{P(X = k)}{P(X = k-1)} = \frac{e^{-\lambda}\lambda^k / k!}{e^{-\lambda}\lambda^{k-1} / (k-1)!} = \frac{\lambda^k (k-1)!}{\lambda^{k-1} k!} = \frac{\lambda}{k}, because λk/λk−1=λ\lambda^k / \lambda^{k-1} = \lambda and k!=k⋅(k−1)!k! = k \cdot (k-1)!. Rearranging, P(X=k)=λkP(X=k−1)P(X = k) = \frac{\lambda}{k}P(X = k – 1).

With λ=4\lambda = 4: P(X=0)=e−4P(X = 0) = e^{-4}; P(X=1)=4⋅e−4P(X = 1) = 4 \cdot e^{-4}; P(X=2)=42⋅4e−4=8e−4P(X = 2) = \frac{4}{2} \cdot 4e^{-4} = 8e^{-4}. Adding up, P(X≤2)=(1+4+8)e−4=13e−4≈0.2381P(X \leq 2) = (1 + 4 + 8)e^{-4} = 13e^{-4} \approx 0.2381, the same as ppois(2, 4). That is how a computer calculates it: each probability from the previous one.

3. The discrete uniform. If P(X=i)=1/nP(X = i) = 1/n for i=1,…,ni = 1, \ldots, n, prove that E(X)=n+12E(X) = \frac{n+1}{2} and Var(X)=n2−112\text{Var}(X) = \frac{n^2 – 1}{12}. You can use ∑i=1ni=n(n+1)2\sum_{i=1}^n i = \frac{n(n+1)}{2} and ∑i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^n i^2 = \frac{n(n+1)(2n+1)}{6}.

Solution for the discrete uniform

Mean. E(X)=∑i=1ni⋅1n=1n⋅n(n+1)2=n+12E(X) = \sum_{i=1}^n i \cdot \frac{1}{n} = \frac{1}{n} \cdot \frac{n(n+1)}{2} = \frac{n+1}{2}.

E(X2)E(X^2). ∑i=1ni2⋅1n=1n⋅n(n+1)(2n+1)6=(n+1)(2n+1)6\sum_{i=1}^n i^2 \cdot \frac{1}{n} = \frac{1}{n} \cdot \frac{n(n+1)(2n+1)}{6} = \frac{(n+1)(2n+1)}{6}.

Variance. (n+1)(2n+1)6−(n+1)24\frac{(n+1)(2n+1)}{6} – \frac{(n+1)^2}{4}. Common denominator 12 and common factor n+1n + 1: (n+1)[2(2n+1)−3(n+1)]12=(n+1)(n−1)12=n2−112\frac{(n+1)\big[2(2n+1) – 3(n+1)\big]}{12} = \frac{(n+1)(n-1)}{12} = \frac{n^2 – 1}{12}. With the six-sided die, 35/12≈2.9235/12 \approx 2.92.

When to use each result

If you are asked for…UseWatch out for…
Proving something is a mass functionNon-negative + adds up to 1 with the right series (rules 1, 2, 3 or 4)Which value the sum starts at
The mgf of a new mass functionPut etxe^{tx} inside the power and sum the same seriesSaying for which tt it exists
E(X)E(X), E(X2)E(X^2) from the mgfDifferentiate and evaluate at t=0t = 0The product rule in the second derivative
The varianceE(X2)−[E(X)]2E(X^2) – [E(X)]^2That it does not come out negative
P(X≥n)P(X \geq n) in the geometric(1−p)n(1-p)^nThat XX counts failures
The mean without differentiating∑n≥1P(X≥n)\sum_{n \geq 1} P(X \geq n)Starting at n=1n = 1
Recognising a distributionCompare the mgf with the known onesThe mgf identifies the distribution

Common mistakes when proving

  • Skipping the first condition. Proving it adds up to 1 and forgetting to say that each probability is non-negative. It is an easy point that gets lost.
  • Using the wrong series. With an xx in front of the power, rule 2; with a factorial underneath, rule 3; with a binomial coefficient and two powers adding up to nn, Newton.
  • Not stating the convergence condition. Every time you use rule 1 or 2, you have to say that ∣a∣<1\lvert a \rvert < 1, and in the mgf that becomes a condition on tt.
  • Differentiating wrongly. The quotient rule and the chain rule are 80% of the mistakes in the mean part. Always check that φX(0)=1\varphi_X(0) = 1 before differentiating.
  • Evaluating at t=1t = 1 instead of t=0t = 0.
  • Writing “it is obvious”. In the exam, every step with its rule. What is obvious to you is not obvious to the marker.

Try it in the R playground

Open the site’s R playground (or RStudio) and check proof 1 with another parameter. The same idea, P(X=x)=(1−a)2 x ax−1P(X = x) = (1 – a)^2 \, x \, a^{x-1} for x≥1x \geq 1, adds up to 1 for any 0<a<10 < a < 1 and has mean 1+a1−a\frac{1 + a}{1 – a}:

a <- 0.6
x <- 1:400
p <- (1 - a)^2 * x * a^(x - 1)
sum(p)                       # 1
sum(x * p)                   # mean
(1 + a) / (1 - a)            # the formula
plot(x[1:20], p[1:20], type = "h", lwd = 4,
     xlab = "x", ylab = "P(X = x)")

What to look at:

  1. In Environment, the vector p has 400 values: the last ones are so small they do not change the sum.
  2. Change a to 0.5: it is the mass function from proof 1 (check it: (1 - 0.5)^2 * x * 0.5^(x - 1) is x/2x+1x / 2^{x+1}) and the mean is 3 again.
  3. Try a <- 0.95: the mean goes up to 39. If you also change 1:400 to 1:100, the sum stays at 0.96: the tail is so long that a hundred terms are no longer enough.
  4. In the plot, the tallest bar is at x=2x = 2 when a=0.6a = 0.6. Find which value of a moves it to x=1x = 1.

Summary

ResultFormula
Moments from the mgfφX(k)(0)=E(Xk)\varphi_X^{(k)}(0) = E(X^k)
Variance shortcutVar(X)=E(X2)−[E(X)]2\text{Var}(X) = E(X^2) – [E(X)]^2; Var(aX+b)=a2 Var(X)\text{Var}(aX + b) = a^2\,\text{Var}(X)
Binomialφ=(1−p+p et)n\varphi = (1 – p + p\,e^t)^n; npnp; np(1−p)np(1-p)
GeometricF(n)=1−(1−p)n+1F(n) = 1 – (1-p)^{n+1}; P(X≥n)=(1−p)nP(X \geq n) = (1-p)^n; memoryless; mean (1−p)/p(1-p)/p
Poissonφ=eλ(et−1)\varphi = e^{\lambda(e^t – 1)}; mean = variance = λ\lambda
Mean from tailsE(X)=∑n≥1P(X≥n)E(X) = \sum_{n \geq 1} P(X \geq n)
Differentiated series∑k≥1k ak=a/(1−a)2\sum_{k \geq 1} k\,a^k = a/(1-a)^2

Three ideas to take away:

  1. Almost every proof in the topic is summing a series: geometric, differentiated geometric, exponential or Newton. Recognising which one is half the work.
  2. The mgf is found by putting etxe^{tx} inside the power and summing the same series you used to check the mass function adds up to 1; the moments come from differentiating and evaluating at 0.
  3. Every result can be checked with R in two lines: the sum of the mass function, the mean by summing, the numerical derivative of the mgf. If it does not match, the mistake is in the proof.

Now that you know why the formulas work, in the R practice we put them to the test by simulating thousands of batches of the WhatsApp group. And in the discrete random variables exercises you have a proof like this one in exam format, with its marks.

Next step: practiceDiscrete random variables — R practice with a simulated WhatsApp group, waits for the useful message and a Poisson that fits the data (and the rgeom I thought was broken)

Did this article help you? Here is how you can support SergioLearns →