Sampling distributions — step-by-step proofs with the campus wifi, the mgf and the degrees of freedom you lose (and the μ that sneaked into my mock exam)

In a class mock exam I was asked to prove that (n−1)S2/σ2 (n-1)S^2/\sigma^2 is a chi-square and I did it in three lines. I wrote: “each (Xi−Xˉ)/σ (X_i – \bar X)/\sigma is a standard normal, there are n of them, so the sum of their squares is a χ2(n) \chi^2(n) “. The lecturer circled the Xˉ \bar X and wrote in the margin: “is this μ?”. It is not. Deviations from the sample mean are not independent standard normals: they always add up to 0, and that is why one degree of freedom is lost. Since then, before adding squares of normals, I check what they are centred on.

Here, step by step, are the proofs of the sampling distributions topic: the sample mean and variance, the chi-square family, the one-sample t, the F and the two-sample t. In the theory you saw what they say and how they are used with the campus wifi; here, why they are true. Each one ends with the result as it goes on the cheat sheet (in the exam you can only bring results, not proofs) and with a check in R.

Table of Contents

Before you start: the rules we will use

All of them come from earlier topics. We number them to cite them at each step (“by rule 4”).

RuleWhat it saysWhere it is used
1. Linearity of expectationE(∑aiXi+b)=∑aiE(Xi)+b E\left(\sum a_i X_i + b\right) = \sum a_i E(X_i) + b , no independence neededProofs 1, 2 and 9
2. Variance of a sum of independent variablesVar⁡(∑aiXi)=∑ai2Var⁡(Xi) \operatorname{Var}\left(\sum a_i X_i\right) = \sum a_i^2 \operatorname{Var}(X_i) Proofs 1 and 9
3. Shortcut varianceE(X2)=Var⁡(X)+E(X)2 E(X^2) = \operatorname{Var}(X) + E(X)^2 Proof 2
4. mgf of a sum of independent variablesMX+Y(t)=MX(t) MY(t) M_{X+Y}(t) = M_X(t)\, M_Y(t) Proofs 3, 4, 5 and 6
5. mgf of aX+b aX + b MaX+b(t)=ebtMX(at) M_{aX+b}(t) = e^{bt} M_X(at) Proof 3
6. Uniquenesstwo variables with the same mgf (near 0) have the same distributionProofs 3 to 6
7. Known mgfsnormal: eμt+σ2t2/2 e^{\mu t + \sigma^2 t^2/2} ; gamma(a, b): (bb−t)a \left(\frac{b}{b-t}\right)^a Proofs 3, 4 and 5
8. Gaussian integral∫−∞∞e−x2/(2s2) dx=s2π \int_{-\infty}^{\infty} e^{-x^2/(2s^2)}\,dx = s\sqrt{2\pi} Proof 5
9. Functions of independent variablesif X and Y are independent, so are g(X) g(X) and h(Y) h(Y) Proofs 6, 7 and 9
10. Independence of Xˉ \bar X and S2 S^2 in an SRS from a normal, Xˉ \bar X and S2 S^2 are independentProofs 6, 7 and 9

Rule 10 is proved with the joint mgf, but the calculation is long and the course notes take it as given: so do we.

Proof 1: the sample mean points at μ and concentrates with n

What we want to prove

If X1,…,Xn X_1, \dots, X_n is an SRS from a population with mean μ and variance σ² (of any shape, it need not be normal):

E(Xˉ)=μ,Var⁡(Xˉ)=σ2n E(\bar X) = \mu, \qquad \operatorname{Var}(\bar X) = \frac{\sigma^2}{n}

Why it matters. Xˉ \bar X hits μ on average and moves less the larger n is. With σ = 6, its standard deviation is 1.55 ms with 15 pings and 0.77 with 60: four times the sample, half the error.

What we start from

Xˉ=1n∑Xi \bar X = \frac1n \sum X_i with E(Xi)=μ E(X_i) = \mu and Var⁡(Xi)=σ2 \operatorname{Var}(X_i) = \sigma^2 for each i, and the Xi X_i independent.

Step 1: the expectation

By rule 1, with ai=1/n a_i = 1/n :

E(Xˉ)=1n∑i=1nE(Xi)=1n⋅nμ=μ E(\bar X) = \frac1n \sum_{i=1}^n E(X_i) = \frac1n \cdot n\mu = \mu

Step 2: the variance

By rule 2, which does need independence, with ai=1/n a_i = 1/n :

Var⁡(Xˉ)=∑i=1n1n2Var⁡(Xi)=1n2⋅nσ2=σ2n \operatorname{Var}(\bar X) = \sum_{i=1}^n \frac{1}{n^2} \operatorname{Var}(X_i) = \frac{1}{n^2} \cdot n\sigma^2 = \frac{\sigma^2}{n}

The constant 1/n 1/n comes out squared, but the sum of n equal variances gives back an n: you are left with σ2/n \sigma^2/n , and the standard deviation, σ/n \sigma/\sqrt n .

Writing Var⁡(Xˉ)=σ2/n2 \operatorname{Var}(\bar X) = \sigma^2/n^2 (forgetting that n variances are added) or σ2 \sigma^2 (forgetting the square of 1/n 1/n ). Check with n = 1: you must get σ².

Result for the cheat sheet. E(Xˉ)=μ E(\bar X) = \mu , Var⁡(Xˉ)=σ2/n \operatorname{Var}(\bar X) = \sigma^2/n , sd⁡(Xˉ)=σ/n \operatorname{sd}(\bar X) = \sigma/\sqrt n .

Check it with R

With the wifi, 10,000 means of n pings for three sizes. If the proof is right, n⋅Var⁡(Xˉ) n \cdot \operatorname{Var}(\bar X) must always come out close to 36:

set.seed(2026)
for (n in c(5, 15, 60)) {
  means <- replicate(10000, mean(rnorm(n, 40, 6)))
  cat("n =", n, " mean:", round(mean(means), 2), " n * var:", round(n * var(means), 2), "\n")
}

Output:

n = 5  mean: 40.02  n * var: 36.99 
n = 15  mean: 40.01  n * var: 35.74 
n = 60  mean: 40  n * var: 36.01 

The mean of the means is always at 40 and n⋅Var⁡(Xˉ) n \cdot \operatorname{Var}(\bar X) around 36, for all three sizes. If the variance were σ2/n2 \sigma^2/n^2 , the second column would drop as n grows.

Check you’ve got it: if the pings were measured back to back and were not independent, which part of the proof would still hold?

The expectation does: rule 1 does not ask for independence, so E(Xˉ)=μ E(\bar X) = \mu still stands. The variance does not: rule 2 only holds for independent variables. With dependent pings, covariances appear and Var⁡(Xˉ) \operatorname{Var}(\bar X) is no longer σ2/n \sigma^2/n .

Proof 2: why S² divides by n − 1

What we want to prove

With the same assumptions (any population with mean μ and variance σ²):

E(S2)=σ2,S2=1n−1∑i=1n(Xi−Xˉ)2 E(S^2) = \sigma^2, \qquad S^2 = \frac{1}{n-1}\sum_{i=1}^n (X_i – \bar X)^2

Why it matters. It explains why R’s var() divides by n − 1. And S2 S^2 is the variance of proofs 6 to 9: if it fell short on average, every t and F in the topic would come out skewed.

What we start from

From proof 1 and rule 3 applied to each Xi X_i and to Xˉ \bar X :

E(Xi2)=σ2+μ2,E(Xˉ2)=σ2n+μ2 E(X_i^2) = \sigma^2 + \mu^2, \qquad E(\bar X^2) = \frac{\sigma^2}{n} + \mu^2

Step 1: expand the sum of squares

Open the square and use ∑Xi=nXˉ \sum X_i = n\bar X :

∑i=1n(Xi−Xˉ)2=∑Xi2−2Xˉ∑Xi+nXˉ2=∑Xi2−2nXˉ2+nXˉ2=∑Xi2−nXˉ2 \sum_{i=1}^n (X_i – \bar X)^2 = \sum X_i^2 – 2\bar X \sum X_i + n\bar X^2 = \sum X_i^2 – 2n\bar X^2 + n\bar X^2 = \sum X_i^2 – n\bar X^2

What gets skipped: ∑Xi=nXˉ \sum X_i = n\bar X is the definition of the mean, and the last term is nXˉ2 n\bar X^2 because Xˉ2 \bar X^2 does not depend on i and is added n times.

Step 2: take expectations

By rule 1 (no independence needed) and the two expectations we started from:

E(∑(Xi−Xˉ)2)=n(σ2+μ2)−n(σ2n+μ2)=nσ2−σ2=(n−1)σ2 E\left(\sum (X_i – \bar X)^2\right) = n(\sigma^2 + \mu^2) – n\left(\frac{\sigma^2}{n} + \mu^2\right) = n\sigma^2 – \sigma^2 = (n-1)\sigma^2

The μ2 \mu^2 terms go. What is left is (n−1)σ2 (n-1)\sigma^2 , not nσ2 n\sigma^2 : there is the lost degree of freedom.

Why each piece: E(∑Xi2) E\left(\sum X_i^2\right) is n equal expectations, and the n in nXˉ2 n\bar X^2 comes out of the expectation because it is a constant. The two pieces only differ in the variance: σ² versus σ2/n \sigma^2/n .

Step 3: divide

E(S2)=1n−1(n−1)σ2=σ2 E(S^2) = \frac{1}{n-1} (n-1)\sigma^2 = \sigma^2

If you had divided by n, the expectation would be n−1nσ2 \frac{n-1}{n}\sigma^2 : always below.

Measuring from the sample mean always falls shortParabola of the sum of squared deviations of the 15 Computer Science pings from a point c, between 34 and 50. The minimum, 536.01, is at the sample mean, 41.67, marked in coral. In green, the value from the population mean, 40, which is 577.68, higher.4008001,2001,600343638404244464850c, the point the deviations are measured from (ms)Σ (xᵢ − c)²x̄ = 41.67 → 536.01μ = 40 → 577.68the minimum is alwaysat the sample mean
That is why the sum with x̄ is "too small" and you divide by n − 1.

The picture explains step 2 without any algebra: with the 15 Computer Science pings, the sum of squares about xˉ=41.67 \bar x = 41.67 is smaller than about any other number, including μ = 40. Measuring from the center of the sample itself always falls short, and dividing by n−1 n – 1 compensates exactly.

Thinking the n−1 n – 1 is for “small samples”. It holds for any n: with n = 1000 the difference is small, but dividing by n is still biased.

Result for the cheat sheet. E(S2)=σ2 E(S^2) = \sigma^2 for any population; ∑(Xi−Xˉ)2=∑Xi2−nXˉ2 \sum (X_i – \bar X)^2 = \sum X_i^2 – n\bar X^2 .

Check it with R

The proof does not use normality, so we check it with exponential pings (a very skewed population) with mean 40, whose variance is 402=1600 40^2 = 1600 :

set.seed(2026)
s2 <- replicate(20000, var(rexp(5, 1 / 40)))       # var() divides by n - 1
round(c(sigma2 = 1600, with_n1 = mean(s2), with_n = mean(s2 * 4 / 5)), 1)
x <- c(35.2, 41.2, 46.0, 47.7, 45.4, 43.0, 43.6, 30.5, 46.0, 53.1, 32.7, 36.5, 46.3, 38.1, 39.7)
c(sum((x - mean(x))^2), sum(x^2) - length(x) * mean(x)^2)   # step 1, with numbers

Output:

 sigma2 with_n1  with_n 
 1600.0  1591.7  1273.4 
[1] 536.0133 536.0133

With n−1 n – 1 , the mean of 20,000 variances comes out close to 1600; with n, close to 1600⋅4/5=1280 1600 \cdot 4/5 = 1280 . And the two forms of the sum of squares in step 1 agree with the 15 Computer Science pings.

Check you’ve got it: with the 15 Computer Science pings, the sum of squares about the mean is 536.01. What is the variance dividing by 14 and by 15, and which one is unbiased?

By 14: S2=536.01/14=38.29 S^2 = 536.01/14 = 38.29 ; by 15: 35.73 35.73 . The unbiased one is S2 S^2 , but that shows on average over many afternoons, not in one: with σ² = 36, the n − 1 version averages 36 and the n version, 36⋅14/15=33.6 36 \cdot 14/15 = 33.6 .

Proof 3: the mean of normals is normal

What we want to prove

If X1,…,Xn X_1, \dots, X_n are independent with Xi∼N(μi,σi) X_i \sim N(\mu_i, \sigma_i) and a1,…,an a_1, \dots, a_n are constants:

Y=∑i=1naiXi∼N(∑aiμi, ∑ai2σi2) Y = \sum_{i=1}^n a_i X_i \sim N\left(\sum a_i \mu_i,\ \sqrt{\sum a_i^2 \sigma_i^2}\right)

and, in particular, for an SRS from an N(μ,σ) N(\mu, \sigma) : ∑Xi∼N(nμ,σn) \sum X_i \sim N(n\mu, \sigma\sqrt n) and Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) .

Why it matters. Proof 1 gives the mean and variance of Xˉ \bar X , not its shape. To compute probabilities you need to know it is normal: with 15 pings, P(Xˉ>43)=0.03 P(\bar X > 43) = 0.03 .

What we start from

The mgf of each Xi X_i (rule 7): MXi(t)=eμit+σi2t2/2 M_{X_i}(t) = e^{\mu_i t + \sigma_i^2 t^2/2} .

Step 1: the mgf of Y as a product

By rule 4 (independence) and rule 5 (each term is aiXi a_i X_i ):

MY(t)=∏i=1nMaiXi(t)=∏i=1nMXi(ait)=∏i=1neμiait+σi2ai2t2/2 M_Y(t) = \prod_{i=1}^n M_{a_i X_i}(t) = \prod_{i=1}^n M_{X_i}(a_i t) = \prod_{i=1}^n e^{\mu_i a_i t + \sigma_i^2 a_i^2 t^2/2}

What gets skipped in the last equality: in the normal’s mgf, t is replaced by ait a_i t . Since t is squared in the second term, you get ai2 a_i^2 : that square ends up in the variance.

Step 2: combine the exponents

A product of exponentials is the exponential of the sum:

MY(t)=exp⁡(t∑aiμi+t22∑ai2σi2) M_Y(t) = \exp\left( t\sum a_i \mu_i + \frac{t^2}{2}\sum a_i^2 \sigma_i^2 \right)

Step 3: recognise the mgf

It is the mgf of a normal with mean ∑aiμi \sum a_i\mu_i and variance ∑ai2σi2 \sum a_i^2\sigma_i^2 . By rule 6, Y is that normal.

Step 4: the two special cases

With ai=1 a_i = 1 , μi=μ \mu_i = \mu , σi=σ \sigma_i = \sigma : mean nμ n\mu , variance nσ2 n\sigma^2 . With ai=1/n a_i = 1/n : mean μ, variance n⋅σ2/n2=σ2/n n \cdot \sigma^2/n^2 = \sigma^2/n .

Subtracting variances when subtracting variables. With a2=−1 a_2 = -1 , a22=1 a_2^2 = 1 : Var⁡(X1−X2)=σ12+σ22 \operatorname{Var}(X_1 – X_2) = \sigma_1^2 + \sigma_2^2 . The difference of two sample means has more variance than either.

Result for the cheat sheet. ∑aiXi∼N(∑aiμi,∑ai2σi2) \sum a_i X_i \sim N\left(\sum a_i\mu_i, \sqrt{\sum a_i^2\sigma_i^2}\right) with independent normals; Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) ; Xˉ−Yˉ∼N(μ1−μ2,σ12/m+σ22/n) \bar X – \bar Y \sim N\left(\mu_1 – \mu_2, \sqrt{\sigma_1^2/m + \sigma_2^2/n}\right) .

Check it with R

The difference between the mean of 12 library pings, N(46,6) N(46, 6) , and that of 15 Computer Science pings, N(40,6) N(40, 6) , should be N(6,36/12+36/15)=N(6, 2.324) N\left(6, \sqrt{36/12 + 36/15}\right) = N(6,\ 2.324) :

set.seed(2026)
dif <- replicate(10000, mean(rnorm(12, 46, 6)) - mean(rnorm(15, 40, 6)))
round(c(mean = mean(dif), sd = sd(dif), sd_theoretical = sqrt(36 / 12 + 36 / 15)), 3)
c(simulated = mean(dif > 10), normal = 1 - pnorm(10, 6, sqrt(36 / 12 + 36 / 15)))

Output:

          mean             sd sd_theoretical 
         5.991          2.327          2.324 
 simulated     normal 
0.04190000 0.04259585 

The mean of the differences is 6, the standard deviation matches the theoretical one, and the probability that the library is more than 10 ms behind Computer Science, simulated and with the normal, is practically the same.

Check you’ve got it: if the library wifi had σ = 8 instead of 6, what distribution would the difference between its mean and the Computer Science one have?

The mean does not change: 46 − 40 = 6. The variances add up (a22=1 a_2^2 = 1 ): 64/12+36/15=7.73 64/12 + 36/15 = 7.73 . So it is an N(6; 2.78) N(6;\ 2.78) , wider than the N(6; 2.324) N(6;\ 2.324) above.

Proof 4: the chi-square is a gamma

What we want to prove

That χ2(n)=gamma(n/2,1/2) \chi^2(n) = \text{gamma}(n/2, 1/2) and, from there, its mgf, its mean and its variance:

MX(t)=(1−2t)−n/2  (t<1/2),E(X)=n,Var⁡(X)=2n M_X(t) = (1 – 2t)^{-n/2}\ \ (t < 1/2), \qquad E(X) = n, \qquad \operatorname{Var}(X) = 2n

Why it matters. It links the chi-square with the gamma from topic 4 and inherits its mgf without integrating anything. That mgf, (1−2t)−n/2 (1-2t)^{-n/2} , is the tool of proofs 5 and 6.

What we start from

The density of the χ2(n) \chi^2(n) and that of a gamma(a, b) from topic 4:

fχ2(x)=(1/2)n/2Γ(n/2)xn/2−1e−x/2,fgamma(x)=baΓ(a)xa−1e−bx,x>0 f_{\chi^2}(x) = \frac{(1/2)^{n/2}}{\Gamma(n/2)} x^{n/2-1} e^{-x/2}, \qquad f_{\text{gamma}}(x) = \frac{b^a}{\Gamma(a)} x^{a-1} e^{-bx}, \qquad x > 0

Step 1: compare the densities

With a=n/2 a = n/2 and b=1/2 b = 1/2 , the gamma density is, letter for letter, the χ2(n) \chi^2(n) one. They are the same distribution.

Step 2: the mgf

By rule 7, the mgf of the gamma(a, b) is (bb−t)a \left(\frac{b}{b-t}\right)^a . With a=n/2 a = n/2 , b=1/2 b = 1/2 :

MX(t)=(1/21/2−t)n/2=(11−2t)n/2=(1−2t)−n/2,t<12 M_X(t) = \left(\frac{1/2}{1/2 – t}\right)^{n/2} = \left(\frac{1}{1 – 2t}\right)^{n/2} = (1 – 2t)^{-n/2}, \qquad t < \frac12

Step 3: the mean, by differentiating

MX′(t)=−n2(1−2t)−n/2−1(−2)=n(1−2t)−(n+2)/2⇒E(X)=MX′(0)=n M_X'(t) = -\frac n2 (1 – 2t)^{-n/2 – 1}(-2) = n(1 – 2t)^{-(n+2)/2} \quad\Rightarrow\quad E(X) = M_X'(0) = n

Why differentiate: the derivative of the mgf at 0 is E(X) E(X) . At t=0 t = 0 , any power of 1−2t 1 – 2t is 1 and only the number in front is left. The (−2) (-2) is the chain rule.

Step 4: the variance, differentiating again

MX′′(t)=n⋅(−n+22)(1−2t)−(n+4)/2(−2)=n(n+2)(1−2t)−(n+4)/2 M_X''(t) = n \cdot \left(-\frac{n+2}{2}\right)(1 – 2t)^{-(n+4)/2}(-2) = n(n+2)(1 – 2t)^{-(n+4)/2}
E(X2)=MX′′(0)=n(n+2)=n2+2n,Var⁡(X)=n2+2n−n2=2n E(X^2) = M_X''(0) = n(n+2) = n^2 + 2n, \qquad \operatorname{Var}(X) = n^2 + 2n – n^2 = 2n

It also comes out with the gamma formulas: a/b=(n/2)/(1/2)=n a/b = (n/2)/(1/2) = n and a/b2=(n/2)/(1/4)=2n a/b^2 = (n/2)/(1/4) = 2n .

Forgetting the chain rule when differentiating (1−2t)−n/2 (1-2t)^{-n/2} : the inner −2 -2 goes missing and you get E(X)=−n/2 E(X) = -n/2 . A chi-square is positive: its mean cannot be negative.

Result for the cheat sheet. χ2(n)=gamma(n/2,1/2) \chi^2(n) = \text{gamma}(n/2, 1/2) ; M(t)=(1−2t)−n/2 M(t) = (1-2t)^{-n/2} ; E=n E = n ; Var⁡=2n \operatorname{Var} = 2n .

Check it with R

k <- 7
f <- function(x) dchisq(x, k)
g <- function(x) dgamma(x, shape = k / 2, rate = 1 / 2)
c(same = all.equal(f(1:20), g(1:20)))           # the two densities coincide
m1 <- integrate(function(x) x * f(x), 0, Inf)$value
m2 <- integrate(function(x) x^2 * f(x), 0, Inf)$value
round(c(mean = m1, var = m2 - m1^2), 4)         # n = 7 and 2n = 14

Output:

same 
TRUE 
mean  var 
   7   14 

all.equal says the densities of χ2(7) \chi^2(7) and gamma(3.5, 0.5) are equal at the 20 points, and the integrals give mean 7 and variance 14.

Check you’ve got it: the chi-square with 14 degrees from the 15 Computer Science pings: what mean, variance and mgf does it have, and which gamma is it?

Mean 14, variance 2⋅14=28 2 \cdot 14 = 28 (standard deviation 5.29) and mgf (1−2t)−7 (1-2t)^{-7} for t<1/2 t < 1/2 . It is a gamma(7, 0.5): a/b=14 a/b = 14 and a/b2=28 a/b^2 = 28 , the same.

Proof 5: Z² is a χ²(1) and chi-squares add up

What we want to prove

Two results that, together, give the definition “sum of squared normals”:

Z∼N(0,1)⇒Z2∼χ2(1);Xi∼χ2(ni) independent⇒∑i=1kXi∼χ2(∑ni) Z \sim N(0, 1) \Rightarrow Z^2 \sim \chi^2(1); \qquad X_i \sim \chi^2(n_i) \text{ independent} \Rightarrow \sum_{i=1}^k X_i \sim \chi^2\left(\sum n_i\right)

and, as a consequence, ∑i=1n(Xi−μσ)2∼χ2(n) \sum_{i=1}^n \left(\frac{X_i – \mu}{\sigma}\right)^2 \sim \chi^2(n) for an SRS from an N(μ,σ) N(\mu, \sigma) .

Why it matters. It says where the chi-square comes from: adding squared standard normals. Proof 6 needs it, and the fact that chi-squares add up is what joins the two samples in proof 9.

Step 1: the mgf of Z²

By the definition of the mgf, integrating against the density of Z:

MZ2(t)=E(etZ2)=12π∫−∞∞etz2e−z2/2 dz=12π∫−∞∞e−(1−2t)z22 dz M_{Z^2}(t) = E\left(e^{tZ^2}\right) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{\infty} e^{tz^2} e^{-z^2/2}\,dz = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{\infty} e^{-\frac{(1-2t)z^2}{2}}\,dz

The last equality just joins exponents: tz2−z2/2=−(1−2t)z2/2 tz^2 – z^2/2 = -(1-2t)z^2/2 , taking −z2/2 -z^2/2 as a common factor.

Step 2: recognise a Gaussian integral

For t<1/2 t < 1/2 , write (1−2t)z2/2=z2/(2s2) (1-2t)z^2/2 = z^2/(2s^2) with s2=1/(1−2t) s^2 = 1/(1-2t) . By rule 8, the integral is s2π s\sqrt{2\pi} :

MZ2(t)=12π⋅2π1−2t=(1−2t)−1/2 M_{Z^2}(t) = \frac{1}{\sqrt{2\pi}} \cdot \frac{\sqrt{2\pi}}{\sqrt{1-2t}} = (1 – 2t)^{-1/2}

It is the mgf of proof 4 with n = 1. By rule 6, Z2∼χ2(1) Z^2 \sim \chi^2(1) .

Why t<1/2 t < 1/2 : if 1−2t≤0 1 – 2t \le 0 , the exponential does not go down to 0 and the integral does not converge. It does no harm: the mgf is only needed near 0. And the root at the bottom is s=1/1−2t s = 1/\sqrt{1-2t} .

Step 3: the sum of independent chi-squares

By rule 4, the mgf of the sum is the product:

M∑Xi(t)=∏i=1k(1−2t)−ni/2=(1−2t)−(∑ni)/2 M_{\sum X_i}(t) = \prod_{i=1}^k (1-2t)^{-n_i/2} = (1-2t)^{-\left(\sum n_i\right)/2}

which is the mgf of a χ2(∑ni) \chi^2\left(\sum n_i\right) .

Step 4: the sum of squares with μ and σ

Each Zi=(Xi−μ)/σ Z_i = (X_i – \mu)/\sigma is an N(0, 1); they are independent because each is a function of a single Xi X_i (rule 9). By step 2, each Zi2∼χ2(1) Z_i^2 \sim \chi^2(1) , and by step 3 the sum of the n of them is a χ2(n) \chi^2(n) .

Applying step 4 with Xˉ \bar X instead of μ. The (Xi−Xˉ)/σ (X_i – \bar X)/\sigma are not independent (they add up to 0): that case is proof 6, and it gives n−1 n – 1 degrees.

Result for the cheat sheet. Z2∼χ2(1) Z^2 \sim \chi^2(1) ; ∑χ2(ni)∼χ2(∑ni) \sum \chi^2(n_i) \sim \chi^2(\sum n_i) if independent; ∑((Xi−μ)/σ)2∼χ2(n) \sum ((X_i – \mu)/\sigma)^2 \sim \chi^2(n) .

Check it with R

With μ = 40 and σ = 6 known, the sum of the 15 standardised squares of an afternoon of pings must be a χ2(15) \chi^2(15) : the simulated 95 % quantile must come out close to qchisq(0.95, 15).

set.seed(2026)
total <- replicate(10000, sum(((rnorm(15, 40, 6) - 40) / 6)^2))
round(c(mean = mean(total), var = var(total), q95 = unname(quantile(total, 0.95)),
        q95_theoretical = qchisq(0.95, 15)), 2)

Output:

           mean             var             q95 q95_theoretical 
          15.05           30.42           24.96           25.00 

Mean close to 15 and variance close to 30 (n n and 2n 2n ), and the simulated 95 % quantile next to the theoretical one, 25.00.

Check you’ve got it: if the 15 pings were standardised with 38 instead of the true μ = 40, would the sum of the squares still be a chi-square with 15 degrees?

No. Each (Xi−38)/6 (X_i – 38)/6 has mean 2/6=1/3 2/6 = 1/3 , not 0: it is no longer an N(0, 1). By rule 3, each square has expectation 1+1/9 1 + 1/9 , and the sum, 15⋅10/9=16.67 15 \cdot 10/9 = 16.67 instead of 15. That is why the true μ is needed.

Proof 6: (n − 1)S²/σ² is a χ²(n − 1)

What we want to prove

If X1,…,Xn X_1, \dots, X_n is an SRS from an N(μ,σ) N(\mu, \sigma) :

(n−1)S2σ2=∑(Xi−Xˉ)2σ2∼χ2(n−1) \frac{(n-1)S^2}{\sigma^2} = \frac{\sum (X_i – \bar X)^2}{\sigma^2} \sim \chi^2(n-1)

Why it matters. It is the hook’s proof. With real data μ is unknown and you center on Xˉ \bar X : this says what happens then. It is the basis of intervals for σ² and the bottom piece of the t and the F.

What we start from

From proof 5 (with known μ, n degrees) and rule 10 (Xˉ \bar X and S2 S^2 independent).

Step 1: add and subtract Xˉ \bar X

Inside each square of the sum with μ, add and subtract Xˉ \bar X :

∑i=1n(Xi−μ)2=∑i=1n[(Xi−Xˉ)+(Xˉ−μ)]2 \sum_{i=1}^n (X_i – \mu)^2 = \sum_{i=1}^n \big[(X_i – \bar X) + (\bar X – \mu)\big]^2

Step 2: expand and drop the cross term

Expanding gives three sums. The middle one is 2(Xˉ−μ)∑(Xi−Xˉ) 2(\bar X – \mu)\sum (X_i – \bar X) , and deviations from the mean always add up to 0: ∑(Xi−Xˉ)=nXˉ−nXˉ=0 \sum (X_i – \bar X) = n\bar X – n\bar X = 0 . What is left:

∑i=1n(Xi−μ)2=∑i=1n(Xi−Xˉ)2+n(Xˉ−μ)2 \sum_{i=1}^n (X_i – \mu)^2 = \sum_{i=1}^n (X_i – \bar X)^2 + n(\bar X – \mu)^2

In the other two sums: the first stays as it is, and in the third (Xˉ−μ)2 (\bar X – \mu)^2 does not depend on i, so it is added n times.

Step 3: divide by σ² and name each piece

We call each piece:

W=∑(Xi−μ)2σ2,Y=(n−1)S2σ2,V=(Xˉ−μσ/n)2,W=Y+V W = \frac{\sum (X_i – \mu)^2}{\sigma^2}, \qquad Y = \frac{(n-1)S^2}{\sigma^2}, \qquad V = \left(\frac{\bar X – \mu}{\sigma/\sqrt n}\right)^2, \qquad W = Y + V

What we know: W∼χ2(n) W \sim \chi^2(n) by proof 5; Xˉ−μσ/n∼N(0,1) \frac{\bar X – \mu}{\sigma/\sqrt n} \sim N(0, 1) by proof 3, so V∼χ2(1) V \sim \chi^2(1) ; and Y and V are independent because Y depends only on S2 S^2 and V only on Xˉ \bar X (rules 9 and 10).

Step 4: solve for the mgf of Y

By rule 4, MW(t)=MY(t) MV(t) M_W(t) = M_Y(t)\, M_V(t) :

(1−2t)−n/2=MY(t) (1−2t)−1/2⇒MY(t)=(1−2t)−(n−1)/2 (1-2t)^{-n/2} = M_Y(t)\,(1-2t)^{-1/2} \quad\Rightarrow\quad M_Y(t) = (1-2t)^{-(n-1)/2}

It is the mgf of a χ2(n−1) \chi^2(n-1) . By rule 6, Y∼χ2(n−1) Y \sim \chi^2(n-1) .

Why you can solve for it: (1−2t)−1/2 (1-2t)^{-1/2} is never 0, and subtracting exponents gives −n/2+1/2=−(n−1)/2 -n/2 + 1/2 = -(n-1)/2 . Without the independence of Y and V (rule 10), the mgf of W would not be the product.

The sum of squares split in twoA violet bar with the sum of squares of the 15 pings about 40, 577.68, which over sigma squared is a chi-square with 15 degrees. Below, the same length split in two: in coral the sum about the sample mean, 536.01, which is n minus 1 times S squared and gives a chi-square with 14; in green the mean's piece, 41.67, which gives a chi-square with 1.Sum of squares about μ = 40577.68/σ² → χ²(15)equalsΣ (xᵢ − x̄)² = 536.0141.67(n − 1)S², which over σ² is χ²(14)n (x̄ − μ)²: over σ²,it is χ²(1), the mean's degreeThe cross term 2(x̄ − μ) Σ (xᵢ − x̄) is 0: the deviations from x̄ add up to 0.
W = Y + V with the Computer Science numbers: 577.68 = 536.01 + 41.67.

In the picture, the decomposition of step 2 with the 15 Computer Science pings: the sum of squares about μ (577.68) splits into the one about xˉ \bar x (536.01) plus n(xˉ−μ)2 n(\bar x – \mu)^2 (41.67). The second piece is the degree of freedom the mean takes.

Saying “they are n squares of normals, so it is a χ2(n) \chi^2(n) “. That is the hook’s mistake. What has n degrees is W, with μ; with Xˉ \bar X one is lost, the one V keeps.

Result for the cheat sheet. (n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1) , independent of Xˉ \bar X . Hence E(S2)=σ2 E(S^2) = \sigma^2 and Var⁡(S2)=2σ4/(n−1) \operatorname{Var}(S^2) = 2\sigma^4/(n-1) .

Check it with R

First the decomposition with the data (it is an identity: it must come out exact) and then the distribution by simulation:

x <- c(35.2, 41.2, 46.0, 47.7, 45.4, 43.0, 43.6, 30.5, 46.0, 53.1, 32.7, 36.5, 46.3, 38.1, 39.7)
n <- length(x); mu <- 40
round(c(with_mu = sum((x - mu)^2), with_mean = sum((x - mean(x))^2),
        mean_piece = n * (mean(x) - mu)^2), 2)
set.seed(2026)
y <- replicate(10000, 14 * var(rnorm(15, 40, 6)) / 36)
round(c(q05 = unname(quantile(y, 0.05)), theoretical_14 = qchisq(0.05, 14), with_15 = qchisq(0.05, 15)), 2)

Output:

   with_mu  with_mean mean_piece 
    577.68     536.01      41.67 
           q05 theoretical_14        with_15 
          6.56           6.57           7.26 

536.01+41.67=577.68 536.01 + 41.67 = 577.68 , exactly the sum with μ. And the simulated 5 % quantile of 14S2/36 14S^2/36 sits next to the χ2(14) \chi^2(14) one, not the χ2(15) \chi^2(15) one.

Check you’ve got it: with the 15 Computer Science pings and σ = 6, what is (n − 1)S²/σ², and is it an unusual value for its distribution?

536.01/36=14.89 536.01/36 = 14.89 . It is a χ2(14) \chi^2(14) , with mean 14 and standard deviation 5.29: 14.89 falls almost in the center, P(χ2(14)>14.89)=0.39 P(\chi^2(14) > 14.89) = 0.39 . Unusual would be below 6.57 or above 23.68, its 5 % and 95 % quantiles.

Proof 7: the one-sample t

What we want to prove

If X1,…,Xn X_1, \dots, X_n is an SRS from an N(μ,σ) N(\mu, \sigma) :

T=n Xˉ−μS∼t(n−1) T = \sqrt n\, \frac{\bar X – \mu}{S} \sim t(n-1)

Why it matters. You almost never know σ. The standardised normal needs it; the t swaps it for S. This says what the swap costs: n−1 n – 1 degrees and wider tails (2.57 instead of 1.96 with six pings).

What we start from

The definition of the t: Z/Y/k∼t(k) Z/\sqrt{Y/k} \sim t(k) if Z∼N(0,1) Z \sim N(0,1) , Y∼χ2(k) Y \sim \chi^2(k) and they are independent. And two pieces already proved:

Z=n Xˉ−μσ∼N(0,1),Y=(n−1)S2σ2∼χ2(n−1) Z = \sqrt n\, \frac{\bar X – \mu}{\sigma} \sim N(0, 1), \qquad Y = \frac{(n-1)S^2}{\sigma^2} \sim \chi^2(n-1)

Z depends only on Xˉ \bar X and Y only on S2 S^2 : by rules 9 and 10, they are independent.

Step 1: build the ratio from the definition

With k=n−1 k = n – 1 :

ZY/(n−1)=n (Xˉ−μ)/σ(n−1)S2σ2(n−1) \frac{Z}{\sqrt{Y/(n-1)}} = \frac{\sqrt n\, (\bar X – \mu)/\sigma}{\sqrt{\frac{(n-1)S^2}{\sigma^2 (n-1)}}}

Why Y is divided by its degrees: the definition asks for it, and that way what is inside the root is 1 on average, E(Y)/(n−1)=1 E(Y)/(n-1) = 1 (proof 4). That is why, with large n, the t looks like the normal.

Step 2: simplify

The n−1 n – 1 inside the root go and you are left with S2/σ2=S/σ \sqrt{S^2/\sigma^2} = S/\sigma (both are positive):

n (Xˉ−μ)/σS/σ=n Xˉ−μS \frac{\sqrt n\, (\bar X – \mu)/\sigma}{S/\sigma} = \sqrt n\, \frac{\bar X – \mu}{S}

σ cancels. That is why the t is useful: it is computed without knowing σ.

How the one-sample t is builtDiagram of a ratio. On top, root n times X bar minus mu over sigma, a standard normal. Below, the root of n minus 1 times S squared over sigma squared, over n minus 1, the root of a chi-square over its degrees. The ratio equals root n times X bar minus mu over S, a t with n minus 1 degrees that no longer carries sigma.√n (X̄ − μ) / σN(0, 1)√( (n − 1)S² / σ² / (n − 1) )√(χ²(n − 1) / (n − 1))=√n (X̄ − μ) / St(n − 1), no σboth carry σ: dividing cancels itindependent: one depends on X̄,the other on S²
Normal over the root of a chi-square: the σ on top and the one below go away together.

In the picture, the two pieces: on top the normal, which needs σ; below the root of the chi-square over its degrees, which carries it too. When you divide, σ disappears and you are left with the statistic you compute from your data.

Dividing the chi-square by n instead of n−1 n – 1 inside the root. Then σ does not cancel cleanly and an extra (n−1)/n \sqrt{(n-1)/n} appears.

Result for the cheat sheet. n(Xˉ−μ)/S∼t(n−1) \sqrt n (\bar X – \mu)/S \sim t(n-1) ; t(k) symmetric, E=0 E = 0 (k > 1), Var⁡=k/(k−2) \operatorname{Var} = k/(k-2) (k > 2).

Check it with R

With the six pings from the hook and with a simulation of afternoons of six pings:

six <- c(57.4, 52.9, 41.4, 37.3, 39.4, 47.8)
z_with_sigma <- sqrt(6) * (mean(six) - 40) / 6            # needs sigma = 6
t_with_s <- sqrt(6) * (mean(six) - 40) / sd(six)          # does not need it
round(c(z = z_with_sigma, t = t_with_s), 3)
set.seed(2026)
tt <- replicate(10000, { x <- rnorm(6, 40, 6); sqrt(6) * (mean(x) - 40) / sd(x) })
round(c(q975 = unname(quantile(tt, 0.975)), t5 = qt(0.975, 5), normal = qnorm(0.975)), 2)

Output:

    z     t 
2.463 1.844 
  q975     t5 normal 
  2.55   2.57   1.96 

With σ = 6 known, the statistic of the six pings is 2.46; with S, 1.84 (in this sample S = 8.02 came out larger than σ). And the 97.5 % quantile of 10,000 statistics with S falls next to the t(5) t(5) one, 2.57, far from the normal’s 1.96.

Check you’ve got it: with the six pings from the hook, why does the statistic come out as 2.46 with σ and 1.84 with S, if the data are the same?

The numerator is the same: 6 (46.03−40)=14.78 \sqrt 6\,(46.03 – 40) = 14.78 . The denominator changes: 14.78/6=2.46 14.78/6 = 2.46 with σ and 14.78/8.02=1.84 14.78/8.02 = 1.84 with S. Each one goes with its own distribution: 2.46 with the normal (1.96) and 1.84 with the t(5) (2.57).

Proof 8: the F for two variances, the reciprocal and the squared t

What we want to prove

For two independent SRSs from N(μ1,σ1) N(\mu_1, \sigma_1) (size m) and N(μ2,σ2) N(\mu_2, \sigma_2) (size n):

S12/σ12S22/σ22∼F(m−1,n−1);F∼F(m,n)⇒1F∼F(n,m);T∼t(n)⇒T2∼F(1,n) \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F(m-1, n-1); \qquad F \sim F(m,n) \Rightarrow \frac1F \sim F(n,m); \qquad T \sim t(n) \Rightarrow T^2 \sim F(1, n)

Why it matters. The F compares two variances: is the library wifi more irregular? Also, the inverse gives left-tail quantiles from tables that only have the right one, and T2∼F(1,n) T^2 \sim F(1, n) links the two-sided t with the F.

Step 1: the two chi-squares

By proof 6, applied to each sample:

U=(m−1)S12σ12∼χ2(m−1),V=(n−1)S22σ22∼χ2(n−1) U = \frac{(m-1)S_1^2}{\sigma_1^2} \sim \chi^2(m-1), \qquad V = \frac{(n-1)S_2^2}{\sigma_2^2} \sim \chi^2(n-1)

independent because each depends only on its own sample (rule 9).

Step 2: the ratio from the definition

U/(m−1)V/(n−1)=S12/σ12S22/σ22∼F(m−1,n−1) \frac{U/(m-1)}{V/(n-1)} = \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F(m-1, n-1)

If σ1=σ2 \sigma_1 = \sigma_2 , they cancel and you are left with S12/S22 S_1^2/S_2^2 .

Step 3: the reciprocal

If F=U/mV/n F = \frac{U/m}{V/n} , then 1F=V/nU/m \frac1F = \frac{V/n}{U/m} : a ratio of two independent chi-squares with the roles swapped, so 1/F∼F(n,m) 1/F \sim F(n, m) . Consequence for quantiles: P(F≤q)=P(1/F≥1/q) P(F \le q) = P(1/F \ge 1/q) , hence

qα(m,n)=1q1−α(n,m) q_{\alpha}(m, n) = \frac{1}{q_{1-\alpha}(n, m)}

The skipped step: if q=qα(m,n) q = q_\alpha(m, n) , then α=P(F≤q)=P(1/F≥1/q) \alpha = P(F \le q) = P(1/F \ge 1/q) , because inverting positive numbers flips the inequality. So 1/q 1/q leaves 1−α 1 – \alpha to its left in an F(n, m): it is q1−α(n,m) q_{1-\alpha}(n, m) .

Step 4: the squared t

If T=Z/Y/n T = Z/\sqrt{Y/n} , then T2=Z2/1Y/n T^2 = \frac{Z^2/1}{Y/n} . By proof 5, Z2∼χ2(1) Z^2 \sim \chi^2(1) , and it is independent of Y (rule 9). It is a ratio of chi-squares with 1 and n degrees: T2∼F(1,n) T^2 \sim F(1, n) .

In step 3, swapping the degrees of freedom without swapping the tail: q0.05(m,n)≠1/q0.05(n,m) q_{0.05}(m, n) \ne 1/q_{0.05}(n, m) . Taking the reciprocal flips the inequality: the left tail of one is the right tail of the other.

Result for the cheat sheet. S12/σ12S22/σ22∼F(m−1,n−1) \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F(m-1, n-1) ; 1/F(m,n)∼F(n,m) 1/F(m,n) \sim F(n,m) ; qα(m,n)=1/q1−α(n,m) q_\alpha(m,n) = 1/q_{1-\alpha}(n,m) ; t(n)2∼F(1,n) t(n)^2 \sim F(1,n) ; E(F)=n/(n−2) E(F) = n/(n-2) .

Check it with R

round(c(qf(0.05, 14, 11), 1 / qf(0.95, 11, 14)), 4)    # the reciprocal
round(c(qt(0.975, 14)^2, qf(0.95, 1, 14)), 4)          # t^2 is F(1, n): both tails of the t
set.seed(2026)
ff <- replicate(10000, var(rnorm(15, 40, 6)) / var(rnorm(12, 46, 6)))
round(c(mean = mean(ff), mean_theoretical = 11 / 9, tail = mean(ff > qf(0.95, 14, 11))), 3)

Output:

[1] 0.3898 0.3898
[1] 4.6001 4.6001
            mean mean_theoretical             tail 
           1.221            1.222            0.053 

The two numbers in each row agree. In the second, notice the t’s 0.975 against the F’s 0.95: T2>c2 T^2 > c^2 is ∣T∣>c |T| > c , which puts both tails of the t together. And the simulated ratio of variances has mean close to 11/9=1.22 11/9 = 1.22 and exceeds the 95 % quantile 5 % of the time.

Check you’ve got it: if the tables only tell you that the 95 % quantile of an F(11, 14) is 2.57, what is the 5 % quantile of an F(14, 11)?

With step 3: q0.05(14,11)=1/q0.95(11,14)=1/2.57=0.39 q_{0.05}(14, 11) = 1/q_{0.95}(11, 14) = 1/2.57 = 0.39 , the 0.3898 in the R output. Careful: the degrees swap and the tail goes from 0.05 to 0.95.

Proof 9: the two-sample t and the paired t

What we want to prove

For two independent SRSs from N(μ1,σ) N(\mu_1, \sigma) and N(μ2,σ) N(\mu_2, \sigma) (the same σ, unknown), of sizes m and n:

T=(Xˉ−Yˉ)−(μ1−μ2)Sp1m+1n∼t(m+n−2),Sp2=(m−1)S12+(n−1)S22m+n−2 T = \frac{(\bar X – \bar Y) – (\mu_1 – \mu_2)}{S_p\sqrt{\frac1m + \frac1n}} \sim t(m+n-2), \qquad S_p^2 = \frac{(m-1)S_1^2 + (n-1)S_2^2}{m+n-2}

And for paired data (Xi,Yi) (X_i, Y_i) , with differences Di=Xi−Yi D_i = X_i – Y_i normal and independent between pairs: n(Dˉ−μD)/SD∼t(n−1) \sqrt n (\bar D – \mu_D)/S_D \sim t(n-1) .

Why it matters. It compares two means without knowing σ: is the library wifi slower? And it brings everything together: the normal on top is proof 3; the chi-square at the bottom, proofs 5 and 6; and the ratio is built as in proof 7. If you understand this one, you have understood the topic.

Step 1: the normal in the numerator

By proof 3, Xˉ−Yˉ∼N(μ1−μ2,σ1/m+1/n) \bar X – \bar Y \sim N\left(\mu_1 – \mu_2, \sigma\sqrt{1/m + 1/n}\right) . Standardising:

Z=(Xˉ−Yˉ)−(μ1−μ2)σ1m+1n∼N(0,1) Z = \frac{(\bar X – \bar Y) – (\mu_1 – \mu_2)}{\sigma\sqrt{\frac1m + \frac1n}} \sim N(0, 1)

Step 2: the chi-square in the denominator

By proof 6, each sample gives a chi-square; they are independent, so by proof 5 they add up:

Y=(m−1)S12σ2+(n−1)S22σ2=(m+n−2)Sp2σ2∼χ2(m+n−2) Y = \frac{(m-1)S_1^2}{\sigma^2} + \frac{(n-1)S_2^2}{\sigma^2} = \frac{(m+n-2)S_p^2}{\sigma^2} \sim \chi^2(m+n-2)

Z depends only on the means and Y only on the variances; by rules 9 and 10, they are independent.

What gets skipped: the degrees add up, (m−1)+(n−1)=m+n−2 (m-1) + (n-1) = m+n-2 (proof 5), and the last equality is the definition of Sp2 S_p^2 . In step 3, since Y/(m+n−2)=Sp2/σ2 Y/(m+n-2) = S_p^2/\sigma^2 , its root is Sp/σ S_p/\sigma and σ goes.

Step 3: the ratio

ZY/(m+n−2)=[(Xˉ−Yˉ)−(μ1−μ2)]/(σ1/m+1/n)Sp/σ=(Xˉ−Yˉ)−(μ1−μ2)Sp1m+1n \frac{Z}{\sqrt{Y/(m+n-2)}} = \frac{\big[(\bar X – \bar Y) – (\mu_1 – \mu_2)\big] / \left(\sigma\sqrt{1/m + 1/n}\right)}{S_p/\sigma} = \frac{(\bar X – \bar Y) – (\mu_1 – \mu_2)}{S_p\sqrt{\frac1m + \frac1n}}

Once again, σ cancels because it is the same in both samples. If they were different, they would not cancel and you would not get an exact t.

Step 4: paired data

If the two measurements are on the same unit (the same spot on campus in the morning and in the afternoon), X and Y are not independent and steps 1-3 do not apply. But the differences D1,…,Dn D_1, \dots, D_n are an SRS from a normal N(μD,σD) N(\mu_D, \sigma_D) , with μD=μ1−μ2 \mu_D = \mu_1 – \mu_2 . It is enough to apply proof 7 to them: n(Dˉ−μD)/SD∼t(n−1) \sqrt n (\bar D – \mu_D)/S_D \sim t(n-1) , with SD S_D the standard deviation of the differences.

Using the two-sample t with paired data. The formula gives a different number (usually a smaller t, because it does not use the fact that each pair shares a common part) and the degrees of freedom are 2n−2 2n – 2 instead of n−1 n – 1 .

Result for the cheat sheet. Two samples with common σ: (Xˉ−Yˉ)−(μ1−μ2)Sp1/m+1/n∼t(m+n−2) \frac{(\bar X – \bar Y) – (\mu_1 – \mu_2)}{S_p\sqrt{1/m + 1/n}} \sim t(m+n-2) , Sp2=(m−1)S12+(n−1)S22m+n−2 S_p^2 = \frac{(m-1)S_1^2 + (n-1)S_2^2}{m+n-2} . Paired: n(Dˉ−μD)/SD∼t(n−1) \sqrt n(\bar D – \mu_D)/S_D \sim t(n-1) .

Check it with R

The course notes’ form, mn(m+n−2)m+n(Xˉ−Yˉ)−(μ1−μ2)(m−1)S12+(n−1)S22 \sqrt{\frac{mn(m+n-2)}{m+n}}\frac{(\bar X – \bar Y) – (\mu_1 – \mu_2)}{\sqrt{(m-1)S_1^2 + (n-1)S_2^2}} , must give the same number as step 3’s:

cs  <- c(35.2, 41.2, 46.0, 47.7, 45.4, 43.0, 43.6, 30.5, 46.0, 53.1, 32.7, 36.5, 46.3, 38.1, 39.7)
lib <- c(57.4, 52.9, 41.4, 37.3, 39.4, 47.8, 46.0, 52.9, 58.8, 47.4, 38.3, 46.2)
m <- length(cs); n <- length(lib)
sp <- sqrt(((m - 1) * var(cs) + (n - 1) * var(lib)) / (m + n - 2))
t_step3 <- (mean(cs) - mean(lib)) / (sp * sqrt(1 / m + 1 / n))
t_notes <- sqrt(m * n * (m + n - 2) / (m + n)) * (mean(cs) - mean(lib)) /
           sqrt((m - 1) * var(cs) + (n - 1) * var(lib))
round(c(t_step3, t_notes), 4)
set.seed(2026)
tt <- replicate(10000, { a <- rnorm(15, 40, 6); b <- rnorm(12, 40, 6)
  s <- sqrt((14 * var(a) + 11 * var(b)) / 25); (mean(a) - mean(b)) / (s * sqrt(1/15 + 1/12)) })
round(c(q975 = unname(quantile(tt, 0.975)), t25 = qt(0.975, 25)), 3)

Output:

[1] -2.1208 -2.1208
 q975   t25 
2.052 2.060 

Both forms give −2.1208, the two-building t from the theory. And with two buildings with the same mean, the 97.5 % quantile of 10,000 statistics falls next to the t(25) t(25) one.

Check you’ve got it: with the 15 Computer Science pings (S = 6.19) and the 12 library ones (S = 7.25), what is the pooled standard deviation and why is it not the average of the two?

Sp2=(14⋅38.29+11⋅52.55)/25=44.56 S_p^2 = (14 \cdot 38.29 + 11 \cdot 52.55)/25 = 44.56 and Sp=6.68 S_p = 6.68 , not (6.19+7.25)/2=6.72 (6.19 + 7.25)/2 = 6.72 : variances are averaged, not standard deviations, and each one is weighted by its degrees of freedom (14 versus 11).

Prove it yourself

Try each on paper before opening the solution.

  1. Exponentials and chi-square. If X1,…,Xn X_1, \dots, X_n is an SRS from an exp⁡(λ) \exp(\lambda) , prove that 2λ∑Xi∼χ2(2n) 2\lambda\sum X_i \sim \chi^2(2n) .
  2. A ratio of exponentials. If X and Y are independent and exp⁡(1) \exp(1) , prove that X/Y∼F(2,2) X/Y \sim F(2, 2) .
  3. The variance of S². For an SRS from an N(μ,σ) N(\mu, \sigma) , prove that Var⁡(S2)=2σ4n−1 \operatorname{Var}(S^2) = \dfrac{2\sigma^4}{n-1} .
Solution 1: exponentials and chi-square

The mgf of each Xi∼exp⁡(λ) X_i \sim \exp(\lambda) is λλ−t \frac{\lambda}{\lambda – t} . By rule 5 with a=2λ a = 2\lambda , that of 2λXi 2\lambda X_i is

M2λXi(t)=λλ−2λt=11−2t=(1−2t)−2/2 M_{2\lambda X_i}(t) = \frac{\lambda}{\lambda – 2\lambda t} = \frac{1}{1 – 2t} = (1-2t)^{-2/2}

which is the mgf of a χ2(2) \chi^2(2) . The 2λXi 2\lambda X_i are independent (rule 9), so by proof 5 their sum is a χ2(2+⋯+2)=χ2(2n) \chi^2(2 + \dots + 2) = \chi^2(2n) . This is the result that allows exact intervals for λ with qchisq in the confidence intervals topic.

Solution 2: a ratio of exponentials

By solution 1 with λ=1 \lambda = 1 and n = 1, 2X∼χ2(2) 2X \sim \chi^2(2) and 2Y∼χ2(2) 2Y \sim \chi^2(2) , independent. Then

XY=2X/22Y/2 \frac{X}{Y} = \frac{2X/2}{2Y/2}

is a ratio of two independent chi-squares, each over its 2 degrees of freedom: X/Y∼F(2,2) X/Y \sim F(2, 2) . In R: mean(rexp(1e5) / rexp(1e5) <= 3) comes out close to pf(3, 2, 2) = 0.75.

Solution 3: the variance of S²

By proof 6, Y=(n−1)S2/σ2∼χ2(n−1) Y = (n-1)S^2/\sigma^2 \sim \chi^2(n-1) , and by proof 4, Var⁡(Y)=2(n−1) \operatorname{Var}(Y) = 2(n-1) . Since S2=σ2n−1Y S^2 = \frac{\sigma^2}{n-1} Y , by the rule for the variance of aY aY :

Var⁡(S2)=(σ2n−1)2⋅2(n−1)=2σ4n−1 \operatorname{Var}(S^2) = \left(\frac{\sigma^2}{n-1}\right)^2 \cdot 2(n-1) = \frac{2\sigma^4}{n-1}

With 15 Computer Science pings, 2⋅362/14=185.14 2 \cdot 36^2/14 = 185.14 : the standard deviation of S2 S^2 is 13.61 ms², more than a third of σ² = 36. That is why the sample variance moves so much.

When to use each result

If you are asked for…UseWatch out for…
Mean or variance of Xˉ \bar X Proof 1holds for any population; only the variance needs independence
That S2 S^2 is unbiasedProof 2the step ∑(Xi−Xˉ)2=∑Xi2−nXˉ2 \sum (X_i – \bar X)^2 = \sum X_i^2 – n\bar X^2
The distribution of a combination of normalsProof 3 (mgf)variances add with ai2 a_i^2
That something is a chi-squaremgf (1−2t)−k/2 (1-2t)^{-k/2} (proofs 4 and 5)write the mgf and read off the degrees
The distribution of S2 S^2 Proof 6n − 1 degrees, not n
A tBuild Z/Y/k Z/\sqrt{Y/k} and check independencethat σ cancels
An FRatio of two chi-squares over their degreesthe order of the degrees
Comparing two meansProof 9common σ; if paired, differences

Common mistakes when proving

  • Adding squares of deviations from Xˉ \bar X as if they were independent standard normals. They are not: they add up to 0. With Xˉ \bar X , n−1 n – 1 degrees.
  • Not justifying independence when building a t or an F. Write what each piece depends on (Xˉ \bar X , S2 S^2 , each sample) and cite the rule.
  • Forgetting the −2 -2 from the chain rule when differentiating (1−2t)−k/2 (1-2t)^{-k/2} .
  • Writing Var⁡(Xˉ−Yˉ)=σ12/m−σ22/n \operatorname{Var}(\bar X – \bar Y) = \sigma_1^2/m – \sigma_2^2/n . With a=−1 a = -1 , a2=1 a^2 = 1 : they add.
  • Using the mgf-of-a-sum rule without independence. MX+Y=MXMY M_{X+Y} = M_X M_Y only if they are independent; in proof 6, the independence of Y and V comes from rule 10.
  • Swapping the degrees of an F without flipping the tail (proof 8, step 3).

Try it in the R playground

Open the R playground on the site (or RStudio) and paste this script. It checks three results from this article by simulation:

set.seed(2026)
# 1. E(S^2) = sigma^2 even if the population is not normal (exponential with mean 40)
s2 <- replicate(20000, var(rexp(5, 1 / 40)))
c(with_n1 = mean(s2), with_n = mean(s2 * 4 / 5), sigma2 = 1600)
# 2. 2 * lambda * sum of exponentials is a chi^2(2n)  (Prove it yourself, 1)
lambda <- 1 / 40; n <- 6
u <- replicate(10000, 2 * lambda * sum(rexp(n, lambda)))
hist(u, freq = FALSE, breaks = 40); curve(dchisq(x, 2 * n), add = TRUE, lwd = 2)
# 3. Var(S^2) = 2 sigma^4 / (n - 1) with 15 pings  (Prove it yourself, 3)
v <- replicate(10000, var(rnorm(15, 40, 6)))
c(simulated = var(v), theoretical = 2 * 36^2 / 14)

Things to look at:

  1. That with n−1 n – 1 the mean of the variances comes out close to 1600 even though the population is exponential, and with n it falls short.
  2. That the histogram of u fits the χ2(12) \chi^2(12) .
  3. That the simulated variance of S2 S^2 comes out close to 185.
  4. Replace rnorm(15, 40, 6) with rexp(15, 1/40) in point 3: the formula 2σ4/(n−1) 2\sigma^4/(n-1) stops holding, because proof 6 needs normality.

Summary

ProofKey ideaResult
1. Sample meanLinearity; independence for the varianceE(Xˉ)=μ E(\bar X) = \mu , Var⁡(Xˉ)=σ2/n \operatorname{Var}(\bar X) = \sigma^2/n
2. S2 S^2 unbiased∑(Xi−Xˉ)2=∑Xi2−nXˉ2 \sum (X_i – \bar X)^2 = \sum X_i^2 – n\bar X^2 E(S2)=σ2 E(S^2) = \sigma^2
3. NormalsProduct of mgfs∑aiXi∼N(∑aiμi,∑ai2σi2) \sum a_iX_i \sim N(\sum a_i\mu_i, \sqrt{\sum a_i^2\sigma_i^2})
4. Chi-squareIt is a gamma(n/2, 1/2)(1−2t)−n/2 (1-2t)^{-n/2} , mean n, variance 2n
5. Z2 Z^2 and sumsGaussian integral; product of mgfsZ2∼χ2(1) Z^2 \sim \chi^2(1) , ∑χ2(ni)∼χ2(∑ni) \sum \chi^2(n_i) \sim \chi^2(\sum n_i)
6. Sample varianceW=Y+V W = Y + V and solve for the mgf(n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1)
7. One-sample tNormal over root of chi-square; σ cancelsn(Xˉ−μ)/S∼t(n−1) \sqrt n(\bar X – \mu)/S \sim t(n-1)
8. FRatio of chi-squaresF(m−1,n−1) F(m-1, n-1) ; 1/F 1/F ; t2∼F(1,n) t^2 \sim F(1, n)
9. Two samplesNormal of the difference and added chi-squarest(m+n−2) t(m+n-2) ; paired, t(n−1) t(n-1)

Three ideas to take away:

  1. Almost everything is proved with the mgf: write the sum’s as a product, simplify and recognise a known distribution’s.
  2. Every estimated parameter eats a degree of freedom. The decomposition W=Y+V W = Y + V shows it: the degree S2 S^2 loses is the one Xˉ \bar X keeps.
  3. The t and the F exist so that σ cancels. If σ does not disappear when you build the ratio, something is wrong (or the σs are not equal).

Now, on to the computer: the sampling distributions practice in R draws the three families and checks these results with thousands of ping samples. If a proof gets stuck, go back to the theory, where each result first appears with the campus wifi.

Next step: practiceSampling distributions — practice in R with the campus wifi, replicate, histograms, qchisq, qt and qf (and the curve that was off by one degree of freedom)

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