Roll two fair dice, X and Y, independently, and let S=X+Y. Each of the 36 pairs has probability 61⋅61=361, by independence (lesson 5.5.1). So P(S=s) is the number of pairs that add up to s, divided by 36.
sum s
2
3
4
5
6
7
pairs
1
2
3
4
5
6
From 8 to 12 the counts fall back: 5, 4, 3, 2, 1. So P(S=7)=366=61, P(S=4)=363=121, and P(S≥10)=363+2+1=61.
Each diagonal of the grid collects the pairs with one sum. Their counts, 1 to 6 and back to 1, make the pmf of S a triangle.
The same table by convolution
To get S=s, the first die shows some x and the second must show s−x. Multiply their probabilities, by independence, and add over every x. For s=4 the splits are 1+3, 2+2 and 3+1, so P(S=4)=3⋅361.
For independent X and Y: add the probability of every way to split s into x and s−x. With densities, the sum becomes an integral. The operation is called convolution.
Try it
The loop counts the 36 pairs by their sum. np.convolve computes the convolution of the two pmfs; times 36 it gives the same counts.
Then 100,000 seeded pairs of rolls: the shares of 7 and of 4 come out near 61≈0.1667 and 121≈0.0833, in one run.
⌘/Ctrl + Enter runs the cell
The MGF of a sum is the product
Convolution gets slow for long sums and needs an integral for densities. The MGF of lesson 5.6.2 turns it into a multiplication. Since et(X+Y)=etXetY, the question is the mean of a product.
With X and Y independent, E[g(X)h(Y)]=E[g(X)]E[h(Y)] (lesson 5.5.2). The joint pmf is the product pX(x)pY(y) (lesson 5.5.1), so the double sum splits into a product of two sums.
Rule: MGF of an independent sum
MX+Y(t)=MX(t)MY(t)ψX+Y(t)=ψX(t)ψY(t)
For independent X and Y, and likewise for more terms: n independent copies of X have MGF MX(t)n. The characteristic functions multiply in the same way.
For two dice, MS(t)=(6et+⋯+e6t)2. Write u for et and multiply out:
(6u+u2+⋯+u6)2=36u2+2u3+3u4+⋯+6u7+⋯+u12
The coefficient of us=est is P(S=s). Multiplying the two polynomials collects the same splits as the convolution.
Try it
The first line checks the rule at t=0.3: the die's MGF squared against the MGF of the sum, built from the counts.
SymPy then multiplies out the polynomial, with u standing for et. Its coefficients, times 36, are the counts.
⌘/Ctrl + Enter runs the cell
Sums that stay in their family
Multiply two MGFs, recognise the product, and the uniqueness rule of lesson 5.6.2 names the distribution of the sum.
Bernoullis make a binomial. A coin that shows 1 with probability p has M(t)=1−p+pet (lesson 5.6.2). The number of 1s in n independent tosses has M(t)=(1−p+pet)n. Multiplying out gives the binomial probabilities of lesson 5.2.2: with n=3 and p=0.3, (0.7+0.3u)3=0.343+0.441u+0.189u2+0.027u3.
Poissons make a Poisson. For a Poisson count with rate λ (lesson 5.2.3), the series for ex (lesson 2.7.2) sums the MGF:
Two independent counts with rates λ1 and λ2 give eλ1(et−1)eλ2(et−1)=e(λ1+λ2)(et−1): a Poisson with rate λ1+λ2. With rates 1 and 2, P(S=3)=3!e−333≈0.224042, and convolution agrees.
Try it
The first line sums the Poisson MGF with λ=2 at t=0.5 term by term, against eλ(et−1).
Then the convolution of the Poisson pmfs with rates 1 and 2, against the rate-3 pmf, for counts 0 to 5. The binomial line compares (0.7+0.3u)3 with binom.pmf; the last line is 100,000 seeded sums of two Poisson counts.
⌘/Ctrl + Enter runs the cell
Sums of independent normals
Lesson 5.4.3 stated that a sum of independent normals is normal; the MGFs show why. Multiply eμ1t+σ12t2/2 by eμ2t+σ22t2/2 and the exponents add:
MX+Y(t)=e(μ1+μ2)t+(σ12+σ22)t2/2
That is the MGF of a normal with mean μ1+μ2 and variance σ12+σ22.
For independent X and Y. Means add and variances add; standard deviations do not. More generally aX+bY∼N(aμ1+bμ2,a2σ12+b2σ22).
An example. Take X∼N(1,4) and Y∼N(2,9), independent. Then X+Y∼N(3,13), with standard deviation 13≈3.605551, not 2+3=5. So P(X+Y>5)=1−N(135−3)≈0.28955; with the wrong 5 you would get 0.344578.
Differences.X−Y is X+(−1)Y, so its variance is 4+(−1)2⋅9=13 again: variances add for differences too (lesson 5.5.2). Its mean is 1−2=−1.
Many terms.n independent copies of N(μ,σ2) add up to N(nμ,nσ2). Their average, the sum divided by n, is N(μ,nσ2): lesson 5.7.2 meets this nσ2 again.
Try it
The first line is the exact answer, then the one with the wrong standard deviation 5.
A million seeded pairs follow. rng.normal takes the standard deviation (2 and 3), not the variance. The sum's mean, standard deviation and share above 5 come out close to 3, 3.606 and 0.290, and the difference has the same spread.
⌘/Ctrl + Enter runs the cell
A sum that leaves its family
Not every family is closed under sums. Take X and Y independent and exponential with rate λ=1, so M(t)=1−t1 (lesson 5.6.2). The sum has MS(t)=(1−t)21, which is not λ′−tλ′ for any rate λ′, so S is not exponential.
Convolution finds its density. Both densities are 0 below 0, so x runs from 0 to s:
fS(s)=∫0se−xe−(s−x)dx=∫0se−sdx=se−s
This holds for s≥0: the density starts at 0, peaks at s=1 and has mean 2. A sum near 0 needs both waits to be short, which is unlikely. It is the waiting time to the second event of a Poisson stream (lesson 5.4.2), a gamma distribution.
So P(S≤1)=1−2e−1≈0.264241; 100,000 seeded sums give 0.2638.
Try it
quad computes the convolution integral at four values of s, beside se−s.
Then 100,000 seeded sums: the share up to 1, the mean and the variance, near 0.2642, 2 and 2.
⌘/Ctrl + Enter runs the cell
Where independence matters
Every rule in this lesson needs X and Y independent. The clearest failure is X+X=2X: one variable added to itself, the opposite of independent.
A die.2X takes the values 2, 4, …, 12, each with probability 61. So P(2X=7)=0, while two independent dice give 7 with probability 61.
The MGF.M2X(t)=MX(2t), by the rule for aX+b (lesson 5.6.2), not MX(t)2.
Exponentials.2X has density 21e−s/2 (lesson 5.6.1), not se−s. Both have mean 2, but the variance of 2X is 4, against 2 for X+Y.
Normals.Z+Z=2Z is N(0,4), while two independent standard normals add to N(0,2).
Two ways to add exponentials with mean 1. Independent waits rarely sum to near 0; doubling one wait often does. Both have mean 2.
Means always add, independent or not (lesson 5.3.2). Variances add when the terms are uncorrelated (lesson 5.5.2).
The whole distribution of a sum needs more: independence, or the joint distribution. Correlated normals still add to a normal when they are jointly normal (lesson 5.5.3), with 2Cov(X,Y) in the variance.
Module 5.7 adds up many independent draws: the law of large numbers and the central limit theorem. Case study 5.6.5 adds up independent normal log returns.
Common mistakes
Add variances, not standard deviations.N(1,4)+N(2,9) has standard deviation 13≈3.61, not 5.
Variances add for differences too.Var(X−Y)=13, not 9−4.
Multiply MGFs; do not add them.MX+MY is not even 1 at t=0.
X+X is not two independent copies.2X has MX(2t), and a doubled die never shows 7.
Not every family is closed. Two exponentials add to se−s, not to an exponential.
Check independence first. Without it, the product rule and the convolution formula do not apply.
Sums of independent random variables
0 of 12 correct
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
How to type answers
Powers with ^: x^7, 2^(1/3), a^-2.
Multiply with * or by writing side by side: 3x^2, 2(x+1).
ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
Your first answer to each question is saved: it counts towards your score and brings the question back for review.
Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.
Summary card
For independent X and Y, the distribution of S=X+Y is the convolution: pS(s)=∑xpX(x)pY(s−x), or ∫fX(x)fY(s−x)dx.
Two dice: P(S=s) counts the pairs on a diagonal, from 361 at 2 up to 366 at 7 and back.
MX+Y(t)=MX(t)MY(t), and likewise ψX+Y=ψXψY: multiply, recognise, and uniqueness names the sum.
n Bernoullis make a binomial; Poissons with rates λ1,λ2 make rate λ1+λ2; N(μ1,σ12)+N(μ2,σ22)=N(μ1+μ2,σ12+σ22).
Two exponentials with rate 1 add to density se−s, not an exponential.
Independence is needed: 2X has MX(2t), not MX(t)2. Means add always; variances add without correlation.