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 x 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.
Table of Contents
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”).
Geometric series. If ∣a∣<1, ∑k=0∞ak=1−a1. And the finite sum, for any a=1: ∑k=0nak=1−a1−an+1.
Differentiated geometric series. If ∣a∣<1, ∑k=1∞kak=(1−a)2a.
Exponential series. For any number z, ∑k=0∞k!zk=ez.
Linearity. Constants come out of sums and expectations, and the sum of a sum is the sum of the sums: ∑(cuk+vk)=c∑uk+∑vk. The same with E: E(aX+b)=aE(X)+b.
Term-by-term differentiation. Inside the interval where a power series converges, its derivative is the series of the derivatives. And whenever needed: e0=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 a:
k=0∑∞ak=1−a1
Differentiate both sides with respect to a (rule 6). On the left, the derivative of ak is kak−1 (the k=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 is (1−a)−2:
k=1∑∞kak−1=(1−a)21
And multiply both sides by a (rule 5) so that the power becomes ak:
k=1∑∞kak=(1−a)2a
That is rule 2. Whenever you see a k multiplying a power, think of it.
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)=2x+1x,x=1,2,3,…
We are asked to: (a) prove it is a mass function; (b) find its moment generating function; (c) calculate 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 times powers of 1/2; in (b), the same with et/2 instead of 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)≥0 for every x=1,2,… and that ∑x=1∞P(X=x)=1.
The first. For x≥1, the numerator x is positive and so is the denominator 2x+1. A quotient of positives is positive: P(X=x)>0.
The second. Step 1: split off the extra 2 in the denominator, 2x+1=2⋅2x, and take it out of the sum (rule 5):
x=1∑∞2x+1x=21x=1∑∞2xx=21x=1∑∞x(21)x
Step 2: what is inside is rule 2 with a=1/2, which satisfies ∣a∣<1:
x=1∑∞x(21)x=(1−1/2)21/2=1/41/2=2
Step 3: put it together.
x=1∑∞P(X=x)=21⋅2=1
Both conditions hold: it is a mass function.
Writing rule 1 where rule 2 belongs. ∑(1/2)x from x=1 is 1, and from x=0 it is 2; but here there is an x 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) and say for which t it exists.
Step 1: write the definition and combine the two powers with exponent x, because etx=(et)x:
φX(t)=x=1∑∞etx2x+1x=21x=1∑∞x(2et)x
Step 2: it is rule 2 again, now with a=et/2. It only holds if ∣a∣<1: et/2<1, that is, et<2, that is, t<ln2. Since ln2≈0.69>0, there is an interval around 0 where it exists, which is what the definition requires.
φX(t)=21⋅(1−et/2)2et/2
Step 3: simplify. On top, 21⋅2et=4et. Underneath, 1−2et=22−et, and squared, 4(2−et)2. The two quarters cancel:
φX(t)=(2−et)2et,t<ln2
A quick check worth doing every time: φX(0)=E(e0)=E(1)=1. Here, (2−1)21=1. It works.
Forgetting to say for which t the mgf exists. In the exam it is part of the answer: without the condition t<ln2, the series does not converge and the formula makes no sense.
(c) The expectation
Step 1: E(X)=φX′(0) (we prove it in proof 2). Differentiate with the quotient rule, (vu)′=v2u′v−uv′, with u=et and v=(2−et)2:
u′=et.
v′=2(2−et)⋅(−et)=−2et(2−et) (chain rule: the derivative of 2−et is −et).
Step 2: substitute.
φX′(t)=(2−et)4et(2−et)2+et⋅2et(2−et)
Why there is a + in the middle, which is where people go wrong the most. The quotient rule subtracts uv′, but v′=−2et(2−et) is negative: minus times minus is plus, and we get +et⋅2et(2−et). Below, v2=((2−et)2)2=(2−et)4.
Step 3: take out the common factor et(2−et) on top and cancel one (2−et):
Result for the cheat sheet. To sum series with an x in front: ∑x≥1xax=(1−a)2a. And the mgf always satisfies φX(0)=1: use it as a check.
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 ∑xP(X=x) and differentiating the mgf numerically: the slope between t=−h and t=h), and the last two check that the formula from (b) gives the same as the original sum at t=0.3. A curious detail: X−1 is a negative binomial with r=2 and p=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=2, and adding the 1, 3. One more check.
Check you’ve got it: if Marta had proposed P(X=x)=c3x+1x for x=1,2,…, what value of c turns it into a mass function?
c=4. It is done just like (a): we take out the extra 3, ∑x≥13x+1x=31∑x≥1x(31)x, and the inside is rule 2 with a=1/3: (2/3)21/3=4/91/3=43. All together, 31⋅43=41. For the sum to be 1 you have to multiply by 4. The first condition holds by itself: with 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) without proving it. Here we prove it, and it is what makes the mgf useful: differentiating and setting t=0, it keeps handing out E(X), E(X2)… The idea: write etX 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
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=tx:
etx=j=0∑∞j!(tx)j=1+tx+2!t2x2+3!t3x3+⋯
Step 1: what holds for every number x holds for the variable X. Take expectations on both sides:
φX(t)=E(etX)=E(1+tX+2!t2X2+3!t3X3+⋯)
Step 2: by linearity (rule 5), the expectation of the sum is the sum of the expectations, and the tj/j! are constants (they do not depend on X), so they come out:
φX(t)=1+tE(X)+2!t2E(X2)+3!t3E(X3)+⋯
Look at what we have: the mgf is a power series in t whose coefficients carry the moments inside. Now we have to get them out.
Step 3: differentiate once with respect to t (rule 6). The 1 disappears, tE(X) leaves E(X), 2!t2E(X2) leaves tE(X2), and so on:
φX′(t)=E(X)+tE(X2)+2!t2E(X3)+⋯
Why the series keeps its shape: the derivative of j!tj is j!jtj−1, and since j!=j⋅(j−1)!, the j cancels and we are left with (j−1)!tj−1. With j=2: 2!t2 becomes 22t=t. Each term moves down one step and its factorial moves down with it.
Step 4: evaluate at t=0. Every term with a t vanishes and only the first survives:
φX′(0)=E(X)
Step 5: if we differentiate again before evaluating, the first surviving term is the one with E(X2): φX′′(t)=E(X2)+tE(X3)+⋯, and φX′′(0)=E(X2). In general, after differentiating k times, the terms with powers of t lower than k disappear, the tk term leaves exactly E(Xk) (because the k-th derivative of k!tk is 1) and those with higher powers keep some t that vanishes at 0:
φX(k)(0)=E(Xk)
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=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=1. At t=1 nothing vanishes and no clean moment comes out. Always t=0.
The variance shortcut
Where we start from. From the definition Var(X)=E[(X−μ)2], with μ=E(X), which is a fixed number.
Step 1: expand the square: (X−μ)2=X2−2μX+μ2.
Step 2: take expectations and apply linearity (rule 5). 2μ is a constant that multiplies and μ2 is a constant that adds:
Var(X)=E(X2)−2μE(X)+μ2
Step 3: since E(X)=μ, the middle term is 2μ⋅μ=2μ2:
Var(X)=E(X2)−2μ2+μ2=E(X2)−μ2
Var(X)=E(X2)−[E(X)]2=φX′′(0)−[φX′(0)]2
And the variance of aX+b
Same idea: E(aX+b)=aμ+b (rule 5), so (aX+b)−(aμ+b)=a(X−μ). The b has gone. Squared, a2(X−μ)2, and taking expectations:
Var(aX+b)=a2Var(X)
Result for the cheat sheet.φX(k)(0)=E(Xk); Var(X)=E(X2)−[E(X)]2; Var(aX+b)=a2Var(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):
The numerical derivatives match E(X)=1 and E(X2)=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+2 (mean 6) is 16, which is 42 times the variance of X. 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+⋯, what are E(X), E(X2) and Var(X)?
Compare coefficients with step 2, φX(t)=1+tE(X)+2!t2E(X2)+⋯. The coefficient of t gives E(X)=2. The one of t2 is E(X2)/2!, so E(X2)/2=3 and E(X2)=6, not 3: the typical mistake is forgetting the 2!. The variance shortcut gives 6−22=2. It is the mgf of a Poisson with λ=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 on average and a variance of np(1−p)=2.1. A single tool, Newton’s binomial, works twice: with p (adds up to 1) and with pet (the mgf). Then two derivatives; the second one is where marks are lost.
What has to be proved. If P(X=k)=(kn)pk(1−p)n−k for k=0,…,n, with 0<p<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=p and b=1−p:
k=0∑n(kn)pk(1−p)n−k=(p+(1−p))n=1n=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 etk inside and combine it with pk, because both have exponent k:
Step 2: it is Newton’s theorem again, now with a=pet and b=1−p:
φX(t)=(1−p+pet)nfor every t
Since it is a finite sum, it exists for any t: there is no condition.
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 p and 1−p (adds up to 1) and underneath with pet instead of p (the mgf). The trick of putting etk inside the power of p 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+pet, is pet):
φX′(t)=n(1−p+pet)n−1⋅pet
At t=0, the inside is 1−p+p=1 and e0=1:
E(X)=φX′(0)=n⋅1n−1⋅p=np
Step 2: second derivative. φX′(t) is a product of np, (1−p+pet)n−1 and et; differentiate with the product rule:
The second derivative, piece by piece. φX′(t) is n times two factors with t in them: (1−p+pet)n−1 and pet. Differentiating the first gives (n−1)(1−p+pet)n−2⋅pet (chain rule), and with the pet that was already there we get (pet)2: the first term. Differentiating pet gives pet: the second term, which is φX′(t) again. At t=0, every bracket and every et equals 1.
In the second derivative, forgetting that et also depends on t and differentiating only the power. You get E(X2)=n(n−1)p2 and a negative variance. If your variance comes out negative, check the product rule.
Result for the cheat sheet.X∼Binom(n,p): φX(t)=(1−p+pet)n, E(X)=np, 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.1 both ways (90⋅0.09+3=8.1+3), the variance 2.1, and the mgf at t=0.4 matches when summed term by term and with the formula.
Check you’ve got it: if X counts the memes among the ten messages, what is the variance of Y=10−X, the messages that are not memes? Do it in two ways.
By proof 2: Y=−1⋅X+10, so Var(Y)=(−1)2Var(X)=2.1. The minus sign disappears when squared and the 10 leaves no trace. By the binomial: Y counts the messages that are not memes, each with probability 0.7, so Y∼Binom(10,0.7) and Var(Y)=10⋅0.7⋅0.3=2.1. It checks out: np(1−p) does not change if you swap p and 1−p.
Proof 4: the geometric (adds up to 1, its closed-form F and memorylessness)
Where we are going.X counts the useless messages before the first useful one (each one is useful with probability p). We want it to add up to 1, a closed-form 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.
What has to be proved. If P(X=k)=(1−p)kp for k=0,1,2,…, with 0<p<1:
k=0∑∞P(X=k)=1F(n)=1−(1−p)n+1P(X≥m+k∣X≥m)=P(X≥k)
And, while we are at it, its mean.
It adds up to 1
Step 1: take out p, which does not depend on k (rule 5):
k=0∑∞(1−p)kp=pk=0∑∞(1−p)k
Step 2: rule 1 with a=1−p. Since 0<p<1, also 0<1−p<1, and the series converges:
p⋅1−(1−p)1=p⋅p1=1
The closed-form distribution function
What has to be proved.F(n)=P(X≤n)=1−(1−p)n+1 for n=0,1,2,….
In the problem sheets you may be asked to prove the finite sum by induction. For n=0: ∑k=00ak=1 and 1−a1−a=1. If it holds for n, for n+1 one more term is added:
1−a1−an+1+an+1=1−a1−an+1+an+1−an+2=1−a1−an+2
which is the formula for n+1. It is proved for every n.
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
It makes sense: “at least n useless ones before the useful one” is the same as “the first n messages are useless”, and that has probability (1−p)n.
Why n−1: X only takes integer values, so the opposite of “X≥n” is “X≤n−1“, not “X≤n” (the value n is inside the tail). And in F(n−1) the exponent becomes (n−1)+1=n. With p=0.2 and n=3: 1−F(2)=0.83=0.512, the number in the memorylessness diagram.
Memorylessness
What has to be proved. For m,k≥0: P(X≥m+k∣X≥m)=P(X≥k).
Step 1: definition of conditional probability (topic 2):
P(X≥m+k∣X≥m)=P(X≥m)P(X≥m+k∩X≥m)
Step 2: if X≥m+k, then certainly X≥m (because k≥0). The intersection is just the smaller event:
=P(X≥m)P(X≥m+k)
Step 3: use the tail we just calculated:
=(1−p)m(1−p)m+k=(1−p)k=P(X≥k)
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.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 and, by rule 1 with a=(1−p)et (which needs (1−p)et<1, that is, t<−ln(1−p)):
φX(t)=1−(1−p)etp
Step 2: the derivative of p(1−(1−p)et)−1 is p(1−p)et(1−(1−p)et)−2. At t=0, 1−(1−p)=p:
E(X)=p2p(1−p)=p1−p
Why that derivative: it is the chain rule with two minus signs. The exponent −1 comes down and leaves −(1−(1−p)et)−2, and the inside differentiates to −(1−p)et: minus times minus, plus. At t=0 the bracket equals p, and squared, p2. With p=0.2: 0.8/0.2=4, the simulated mean.
Result for the cheat sheet.X∼geom(p) (failures before the first success): F(n)=1−(1−p)n+1, P(X≥n)=(1−p)n, φX(t)=1−(1−p)etp, E(X)=p1−p, Var(X)=p21−p, 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) 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, 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 given X≥5, which is the opposite of X≥7 given X≥5. By memorylessness with m=5 and k=2, P(X≥7∣X≥5)=P(X≥2)=0.82=0.64, so the answer is 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, λ. 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) contains eg(t) again. At the end, the mean without the mgf, by reindexing the sum.
What has to be proved. If P(X=k)=e−λk!λk for k=0,1,2,…, with λ>0:
k=0∑∞P(X=k)=1φX(t)=eλ(et−1)E(X)=Var(X)=λ
It adds up to 1
The probabilities are positive (exponential, power of λ>0 and factorial). Step 1: e−λ does not depend on k and comes out (rule 5). Step 2: what is left is the exponential series (rule 3) with z=λ:
k=0∑∞e−λk!λk=e−λk=0∑∞k!λk=e−λeλ=1
The mgf
Step 1: put etk inside the power, as in the binomial: etkλk=(λet)k.
φX(t)=k=0∑∞etke−λk!λk=e−λk=0∑∞k!(λet)k
Step 2: rule 3 with z=λet, which holds for any t:
φX(t)=e−λeλet=eλet−λ⇒φX(t)=eλ(et−1)
Mean and variance
Step 1: the derivative of eg(t) is eg(t)g′(t). Here g(t)=λ(et−1) and g′(t)=λet:
φX′(t)=λetφX(t)⇒E(X)=φX′(0)=λ⋅1⋅1=λ
(at t=0, φX(0)=e0=1).
Step 2: the second derivative is that of a product, λet times φX(t):
Result for the cheat sheet.X∼Pois(λ): φX(t)=eλ(et−1), E(X)=Var(X)=λ.
If an exercise gives you a mass function with x!θx and a constant, the sum is almost certainly done with rule 3. And if it starts at x=1 instead of 0, the x=0 term of the series is missing: ∑x≥1x!θx=eθ−1.
The mean without the mgf: reindexing the sum
Sometimes the question asks for E(X) “directly”, without the mgf. Then you add up ∑kP(X=k), and the trick is to make the exponential series appear again. Three steps:
The k=0 term is 0⋅P(X=0)=0, so the sum can start at k=1.
For k≥1, k!k=(k−1)!1, because k!=k⋅(k−1)!. And we take out one λ: λk=λ⋅λk−1.
We call j=k−1. When k goes from 1 to infinity, j goes from 0 to infinity: it is rule 3, starting where it has to start.
Reindexing does not change any term: it only renames them.
Reindexing halfway. If you replace k with j+1 inside and leave the sum starting at 1, you are missing the j=0 term, which is 1, and you get λ(1−e−λ) instead of λ.
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.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)] for the Poisson? How do you get the variance from it?
λ2. Now the k=0 and k=1 terms vanish (both have a factor 0), and for k≥2, k!k(k−1)=(k−2)!1. Taking out λ2 and calling j=k−2, we are left with λ2e−λ∑j≥0j!λj=λ2. Since X(X−1)=X2−X, by linearity E(X2)=λ2+λ, the same as with the mgf, and the variance is λ2+λ−λ2=λ. With λ=4, 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). It matters because sometimes the tails are simpler than the mass (in the geometric, (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 X only takes non-negative integer values (0,1,2,…) and has a finite mean:
E(X)=n=1∑∞P(X≥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). Then E(X)=∑n=0∞npn=0⋅p0+1⋅p1+2⋅p2+3⋅p3+⋯
Step 1: write each npn as n copies of pn and put each copy in a different row:
In the first column, p1 appears once; in the second, p2 appears twice (rows 1 and 2); in the third, p3 appears three times. Adding by columns gives 1⋅p1+2⋅p2+3⋅p3+⋯, which is the mean.
Step 2: now add by rows. The first row is p1+p2+⋯=P(X≥1); the second, p2+p3+⋯=P(X≥2); the n-th, P(X≥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)
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 n with its height npn) or by rows (each tail P(X≥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, p2=0.2 and p3=0.1 (and p0=0.4, which does not appear because it is multiplied by 0):
n
Column npn
Row P(X≥n)
Why
1
1⋅0.3=0.3
0.3+0.2+0.1=0.6
Row 1 has one copy of every pn with n≥1
2
2⋅0.2=0.4
0.2+0.1=0.3
Row 2 starts at p2: p1 has already used its only copy
3
3⋅0.1=0.3
0.1
Only p3 has a third copy
Total
1
1
The same six copies, grouped differently
Applying it to the geometric. Since P(X≥n)=(1−p)n (proof 4):
E(X)=n=1∑∞(1−p)n=1−(1−p)1−1=p1−1=p1−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=0. P(X≥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,…}: E(X)=∑n≥1P(X≥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.6, P(X≥2)=0.3 and P(X≥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),…, and [-1] removes the n=0 one.)
Check you’ve got it: the tail of Pablo’s variable (proof 1) is P(X≥n)=2nn+1. Do you get its mean, 3, by adding up tails?
Yes. First, a check of the tail: P(X≥1)=2/2=1, because Pablo always sends at least one message, and P(X≥2)=3/4=1−0.25. We split the sum in two: ∑n≥12nn+1=∑n≥1n(21)n+∑n≥1(21)n. The first is rule 2 with a=1/2, which equals 2 (step 2 of proof 1). The second is rule 1 minus its n=0 term: 2−1=1. Total, 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)=(kk+r−1)pr(1−p)k, k=0,1,2,… Using that, for ∣a∣<1, ∑k=0∞(kk+r−1)ak=(1−a)−r, prove that it adds up to 1, that its mgf is (1−(1−p)etp)r and that E(X)=pr(1−p).
Solution for the negative binomial
It adds up to 1. Take out pr (rule 5) and apply the identity with a=1−p: ∑k(kk+r−1)pr(1−p)k=pr(1−(1−p))−r=prp−r=1.
mgf.φX(t)=pr∑k(kk+r−1)((1−p)et)k=pr(1−(1−p)et)−r=(1−(1−p)etp)r, if (1−p)et<1.
Mean. By the chain rule, φX′(t)=r(1−(1−p)etp)r−1⋅(1−(1−p)et)2p(1−p)et. At t=0 the first factor is r⋅1r−1=r and the second p2p(1−p)=p1−p. So E(X)=pr(1−p). With r=3 and p=0.2, 12 useless ones on average before the third useful one.
2. The Poisson recurrence. If X∼Pois(λ), prove that P(X=k)=kλP(X=k−1) for k≥1 and use it to calculate P(X≤2) with λ=4 without factorials.
Solution for the Poisson recurrence
Divide two consecutive probabilities: P(X=k−1)P(X=k)=e−λλk−1/(k−1)!e−λλk/k!=λk−1k!λk(k−1)!=kλ, because λk/λk−1=λ and k!=k⋅(k−1)!. Rearranging, P(X=k)=kλP(X=k−1).
With λ=4: P(X=0)=e−4; P(X=1)=4⋅e−4; P(X=2)=24⋅4e−4=8e−4. Adding up, P(X≤2)=(1+4+8)e−4=13e−4≈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/n for i=1,…,n, prove that E(X)=2n+1 and Var(X)=12n2−1. You can use ∑i=1ni=2n(n+1) and ∑i=1ni2=6n(n+1)(2n+1).
Variance.6(n+1)(2n+1)−4(n+1)2. Common denominator 12 and common factor n+1: 12(n+1)[2(2n+1)−3(n+1)]=12(n+1)(n−1)=12n2−1. With the six-sided die, 35/12≈2.92.
When to use each result
If you are asked for…
Use
Watch out for…
Proving something is a mass function
Non-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 function
Put etx inside the power and sum the same series
Saying for which t it exists
E(X), E(X2) from the mgf
Differentiate and evaluate at t=0
The product rule in the second derivative
The variance
E(X2)−[E(X)]2
That it does not come out negative
P(X≥n) in the geometric
(1−p)n
That X counts failures
The mean without differentiating
∑n≥1P(X≥n)
Starting at n=1
Recognising a distribution
Compare the mgf with the known ones
The 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 x in front of the power, rule 2; with a factorial underneath, rule 3; with a binomial coefficient and two powers adding up to n, Newton.
Not stating the convergence condition. Every time you use rule 1 or 2, you have to say that ∣a∣<1, and in the mgf that becomes a condition on t.
Differentiating wrongly. The quotient rule and the chain rule are 80% of the mistakes in the mean part. Always check that φX(0)=1 before differentiating.
Evaluating at t=1 instead of t=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)2xax−1 for x≥1, adds up to 1 for any 0<a<1 and has mean 1−a1+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:
In Environment, the vector p has 400 values: the last ones are so small they do not change the sum.
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+1) and the mean is 3 again.
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.
In the plot, the tallest bar is at x=2 when a=0.6. Find which value of a moves it to x=1.
Summary
Result
Formula
Moments from the mgf
φX(k)(0)=E(Xk)
Variance shortcut
Var(X)=E(X2)−[E(X)]2; Var(aX+b)=a2Var(X)
Binomial
φ=(1−p+pet)n; np; np(1−p)
Geometric
F(n)=1−(1−p)n+1; P(X≥n)=(1−p)n; memoryless; mean (1−p)/p
Poisson
φ=eλ(et−1); mean = variance = λ
Mean from tails
E(X)=∑n≥1P(X≥n)
Differentiated series
∑k≥1kak=a/(1−a)2
Three ideas to take away:
Almost every proof in the topic is summing a series: geometric, differentiated geometric, exponential or Newton. Recognising which one is half the work.
The mgf is found by putting etx 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.
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.
Data Science and Engineering student at ULPGC. I explain what I learn
at university the way I wish it had been explained to me: with its
doubts, its mistakes and the path to the solution.