Confidence intervals — step-by-step proofs with the pivot method (and why the quantiles swap places)

In a class mock exam I was asked for the interval for the variance and I got a lower limit of 37.6 and an upper limit of 8.1. I handed it in like that, with both numbers correctly computed and in the wrong order. The lecturer wrote a single word next to it: “Empty?”. An interval whose left end is to the right of its right end contains nothing, not even the variance I had just estimated. The mistake was not in the arithmetic but in the last step: when I flipped the fraction I did not flip the quantiles. Since then I solve every interval as I do here, one inequality at a time.

In the confidence intervals theory we saw the formula for each interval and computed it with the Gáldar and Tazacorte bananas. Here is where each one comes from, step by step, with no jumps: the pivot, why it has the distribution it has and how to solve for the parameter. These are the derivations that come up in EC2, especially the exact exponential pivot. After each one, “Check it with R” tests it by simulation: if the formula is right, the interval must hit in 95 % of samples.

Table of Contents

Before you start: the rules we will use

Every proof cites these rules by number (“by rule 3”). The ones about distributions come from sampling distributions and from the random variable topics.

  1. Quantiles. zp z_{p} , tk,p t_{k,p} , qp q_{p} (chi-squared) and fp f_{p} (F) are the values that leave probability p to their left: qnorm(p), qt(p, k), qchisq(p, k), qf(p, k1, k2). For the normal and the t, by symmetry, zα/2=−z1−α/2 z_{\alpha/2} = -z_{1-\alpha/2} and P(−z1−α/2≤Z≤z1−α/2)=1−α P(-z_{1-\alpha/2} \le Z \le z_{1-\alpha/2}) = 1-\alpha .
  2. The mean of a normal. If X1,…,Xn X_1,\dots,X_n is an s.r.s. from N(μ,σ) N(\mu,\sigma) , then Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) .
  3. The variance of a normal. In the same sample, (n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1) and it is independent of Xˉ \bar X .
  4. The t. If Z∼N(0,1) Z \sim N(0,1) and V∼χ2(k) V \sim \chi^2(k) are independent, Z/V/k∼t(k) Z/\sqrt{V/k} \sim t(k) .
  5. The F and the sum of chi-squareds. If V1∼χ2(k1) V_1 \sim \chi^2(k_1) and V2∼χ2(k2) V_2 \sim \chi^2(k_2) are independent, V1/k1V2/k2∼F(k1,k2) \frac{V_1/k_1}{V_2/k_2} \sim F(k_1, k_2) and V1+V2∼χ2(k1+k2) V_1 + V_2 \sim \chi^2(k_1+k_2) .
  6. Inequalities. Adding or subtracting the same thing to all three sides of a≤x≤b a \le x \le b changes nothing; multiplying by a positive number, neither; multiplying by a negative one reverses both inequalities. And if 0<a≤x≤b 0 < a \le x \le b , taking reciprocals reverses them: 1/b≤1/x≤1/a 1/b \le 1/x \le 1/a .
  7. Gamma and rescaling. If X1,…,Xn X_1,\dots,X_n are independent exponential(λ), ∑Xi∼gamma(n,λ) \sum X_i \sim \text{gamma}(n, \lambda) . If Y has density fY f_Y and W=cY W = cY with c>0 c > 0 , then fW(w)=1cfY(w/c) f_W(w) = \frac1c f_Y(w/c) . And χ2(k) \chi^2(k) is gamma(k/2, 1/2) (k/2,\ 1/2) .
  8. Asymptotic normality of the MLE. With large n, θ^≈N(θ,1/(n i(θ))) \hat\theta \approx N\big(\theta, \sqrt{1/(n\,i(\theta))}\big) , and θ can be replaced by θ^ \hat\theta in the standard deviation.

Proof 1: the mean of a normal with known σ

What we want to prove

That, with X1,…,Xn X_1,\dots,X_n an s.r.s. from N(μ,σ) N(\mu,\sigma) and σ known, the (1−α)100 % (1-\alpha)100\,\% interval for μ is

(Xˉ−z1−α/2σn,  Xˉ+z1−α/2σn) \left(\bar X – z_{1-\alpha/2}\frac{\sigma}{\sqrt n},\ \ \bar X + z_{1-\alpha/2}\frac{\sigma}{\sqrt n}\right)

Where we are going and why it matters. It is the simplest interval and the mould for all the others: the eight proofs follow the same path. A pivot (a quantity with the sample and the parameter whose distribution we know completely), cut its tails to keep the central 1−α 1-\alpha , and solve for the parameter. The pivot changes; the path does not.

What we start from

From rule 2: Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) . And from the fact that standardising a normal gives an N(0, 1).

Step 1: the pivot

Standardising Xˉ \bar X :

Z=Xˉ−μσ/n∼N(0,1) Z = \frac{\bar X – \mu}{\sigma/\sqrt n} \sim N(0, 1)

Z meets both conditions of a pivot: it depends on the sample (through Xˉ \bar X ) and on μ, and the only unknown is μ (σ is known); its distribution, N(0, 1), does not depend on μ.

Step 2: cut off the tails

By rule 1, leaving α/2 \alpha/2 in each tail:

P(−z1−α/2≤Xˉ−μσ/n≤z1−α/2)=1−α P\left(-z_{1-\alpha/2} \le \frac{\bar X – \mu}{\sigma/\sqrt n} \le z_{1-\alpha/2}\right) = 1-\alpha

Why α/2 \alpha/2 in each tail: the normal is symmetric with its peak in the center, so the central range is the narrowest one that keeps 1−α 1-\alpha inside. Any other split would also have confidence 1−α 1-\alpha , but it would be longer.

Step 3: solve for μ, one operation at a time

Multiplying all three sides by σ/n>0 \sigma/\sqrt n > 0 (rule 6, nothing changes):

−z1−α/2σn≤Xˉ−μ≤z1−α/2σn -z_{1-\alpha/2}\frac{\sigma}{\sqrt n} \le \bar X – \mu \le z_{1-\alpha/2}\frac{\sigma}{\sqrt n}

Subtracting Xˉ \bar X from all three:

−Xˉ−z1−α/2σn≤−μ≤−Xˉ+z1−α/2σn -\bar X – z_{1-\alpha/2}\frac{\sigma}{\sqrt n} \le -\mu \le -\bar X + z_{1-\alpha/2}\frac{\sigma}{\sqrt n}

Multiplying by −1 (rule 6: both inequalities reverse, and the left-hand side moves to the right):

Xˉ−z1−α/2σn≤μ≤Xˉ+z1−α/2σn \bar X – z_{1-\alpha/2}\frac{\sigma}{\sqrt n} \le \mu \le \bar X + z_{1-\alpha/2}\frac{\sigma}{\sqrt n}

As every step is an equivalence, the event is the same and its probability is still 1−α 1-\alpha . What is to the left of μ is L and to the right, U. ∎

Solving for μ, one inequality at a timeFour boxes in a column joined by arrows. Top, minus z at most X bar minus mu over sigma over root n, at most z. Second, after multiplying by sigma over root n. Third, after subtracting X bar. Fourth, in green, after multiplying by minus 1, which flips the inequalities: X bar minus z sigma over root n, at most mu, at most X bar plus z sigma over root n.−z ≤ (X̄ − μ)/(σ/√n) ≤ zthe starting point−zσ/√n ≤ X̄ − μ ≤ zσ/√n× σ/√n (positive: unchanged)−X̄ − zσ/√n ≤ −μ ≤ −X̄ + zσ/√n− X̄ (unchanged)X̄ − zσ/√n ≤ μ ≤ X̄ + zσ/√n× (−1): they flipZμ
At the top it is about Z; at the bottom, the same event written as "μ is in the interval".

Look at the drawing: the top box is a statement about Z, with μ fixed and Xˉ \bar X moving; the bottom one, the same event written as a statement about where μ is relative to a moving range. Solving does not change the event, only how you read it.

Jumping from step 2 to the result by writing “μ \mu between Xˉ−… \bar X – \ldots and Xˉ+… \bar X + \ldots ” without multiplying by −1. Here it comes out right by luck (the interval is symmetric), but with the variance or the exponential that jump gives the interval backwards.

Result for the cheat sheet. μ, known σ: xˉ±z1−α/2 σ/n \bar x \pm z_{1-\alpha/2}\,\sigma/\sqrt n .

Check you’ve got it: with σ = 4 and 15 bunches, how long is the 95 % interval, and how many bunches would you need for it to be half as long?

It is twice the margin: 2⋅1.96⋅4/15=4.05 2\cdot 1.96\cdot 4/\sqrt{15} = 4.05 . Doubling the bunches is not enough to halve it: n sits inside a square root, so you have to multiply it by 4. With 60, 2⋅1.96⋅4/60=2.02 2\cdot 1.96\cdot 4/\sqrt{60} = 2.02 .

Check it with R

If the formula is right, with 10,000 samples of 15 bunches from N(38,4) N(38, 4) , the 95 % interval should contain 38 in about 95 % of them:

set.seed(1)
mu <- 38; sigma <- 4; n <- 15; z <- qnorm(0.975)
hits <- replicate(10000, {
  x <- rnorm(n, mu, sigma)
  abs(mean(x) - mu) <= z * sigma / sqrt(n)    # the same as L <= mu <= U
})
mean(hits)

Output:

[1] 0.9509

Just over 95 % of samples hit. Look at the condition inside: ∣xˉ−μ∣≤zσ/n \lvert \bar x – \mu \rvert \le z\sigma/\sqrt n is exactly step 3 before solving.

Proof 2: the mean of a normal with unknown σ

What we want to prove

That, without knowing σ, the interval for μ is

(Xˉ−tn−1, 1−α/2Sn,  Xˉ+tn−1, 1−α/2Sn) \left(\bar X – t_{n-1,\,1-\alpha/2}\frac{S}{\sqrt n},\ \ \bar X + t_{n-1,\,1-\alpha/2}\frac{S}{\sqrt n}\right)

Why it matters. You almost never know σ: from Gáldar you only have the 15 weights. This is the interval you will really use, the one t.test() gives. The idea: find another quantity that also contains σ so that, when you divide, it cancels.

What we start from

From rules 2, 3 and 4. The pivot of proof 1 no longer works: it contains σ, which is now unknown, so it would stop being a pivot.

Step 1: two independent pieces

By rule 2, Z=Xˉ−μσ/n∼N(0,1) Z = \frac{\bar X – \mu}{\sigma/\sqrt n} \sim N(0,1) . By rule 3, V=(n−1)S2σ2∼χ2(n−1) V = \frac{(n-1)S^2}{\sigma^2} \sim \chi^2(n-1) , and V is independent of Xˉ \bar X , hence of Z.

Step 2: build the t

By rule 4 with k=n−1 k = n-1 :

T=ZV/(n−1)=Xˉ−μσ/n(n−1)S2σ2(n−1)=Xˉ−μσ/nS/σ T = \frac{Z}{\sqrt{V/(n-1)}} = \frac{\dfrac{\bar X – \mu}{\sigma/\sqrt n}}{\sqrt{\dfrac{(n-1)S^2}{\sigma^2(n-1)}}} = \frac{\dfrac{\bar X – \mu}{\sigma/\sqrt n}}{S/\sigma}

What gets skipped here: V is independent of Z because Z only uses Xˉ \bar X (μ, σ and n are fixed). And in the last equality the n−1 n-1 cancel, S2/σ2 S^2/\sigma^2 is left, and its square root is S/σ S/\sigma because both are positive.

Step 3: σ goes away

In the quotient, σ is in the denominator on top and in the one below, and it cancels:

T=Xˉ−μσ/n⋅σS=Xˉ−μS/n∼t(n−1) T = \frac{\bar X – \mu}{\sigma/\sqrt n}\cdot\frac{\sigma}{S} = \frac{\bar X – \mu}{S/\sqrt n} \sim t(n-1)

Now T only depends on the sample (Xˉ \bar X , S) and on μ, and its distribution depends neither on μ nor on σ: it is a pivot.

Step 4: solve

It is the same as proof 1, replacing σ with S and z1−α/2 z_{1-\alpha/2} with tn−1, 1−α/2 t_{n-1,\,1-\alpha/2} (the t is also symmetric, rule 1): multiply by S/n>0 S/\sqrt n > 0 , subtract Xˉ \bar X and multiply by −1. ∎

Giving the t n − 1 degrees of freedom “just because”. They come from the V of rule 3: the sum of squares around Xˉ \bar X loses one degree of freedom because the Xi−Xˉ X_i – \bar X add up to 0.

Result for the cheat sheet. μ, unknown σ: xˉ±tn−1, 1−α/2 s/n \bar x \pm t_{n-1,\,1-\alpha/2}\,s/\sqrt n .

Check you’ve got it: with 15 bunches and unknown σ, which quantile do you use at 95 %, and how much longer is the interval than with z?

The one from the t with 14 degrees: qt(0.975, 14) = 2.14, against 1.96. With the same S, the interval is 2.14/1.96 = 1.09 times the z one: 9 % longer. That extra margin is what lifts the coverage from 93 % to 95 % in the simulation below.

Check it with R

With 15 bunches, we compare the t interval with the same one using z (that is, putting S where σ goes without changing the quantile):

set.seed(2)
mu <- 38; n <- 15
r <- replicate(10000, {
  x <- rnorm(n, mu, 4); e <- sd(x) / sqrt(n)
  c(t = abs(mean(x) - mu) <= qt(0.975, n - 1) * e,
    z = abs(mean(x) - mu) <= qnorm(0.975) * e)
})
rowMeans(r)

Output:

     t      z 
0.9494 0.9289 

With the t it hits 95 %; with z, only about 93 %: the range is too short because it ignores that S varies too. The t corrects that.

Proof 3: the variance of a normal

What we want to prove

That the (1−α)100 % (1-\alpha)100\,\% interval for σ2 \sigma^2 is

((n−1)S2q1−α/2,  (n−1)S2qα/2) \left(\frac{(n-1)S^2}{q_{1-\alpha/2}},\ \ \frac{(n-1)S^2}{q_{\alpha/2}}\right)

with qp q_p the quantiles of χ2(n−1) \chi^2(n-1) .

Why it matters. Two farms with the same mean weight can give very regular or very uneven bunches: the spread matters as much as the mean. And this is where solving goes wrong (as in my anecdote): the pivot is no longer symmetric and the parameter is in the denominator.

What we start from

From rule 3: Q=(n−1)S2/σ2∼χ2(n−1) Q = (n-1)S^2/\sigma^2 \sim \chi^2(n-1) . Q depends on the sample (through S2 S^2 ) and on σ2 \sigma^2 , and its distribution does not depend on σ2 \sigma^2 : it is the pivot.

Step 1: cut off the tails

The chi-squared is not symmetric, so the two quantiles are different and both positive:

P(qα/2≤(n−1)S2σ2≤q1−α/2)=1−α P\left(q_{\alpha/2} \le \frac{(n-1)S^2}{\sigma^2} \le q_{1-\alpha/2}\right) = 1-\alpha

Why 1−α 1-\alpha : qα/2 q_{\alpha/2} leaves α/2 \alpha/2 to its left and q1−α/2 q_{1-\alpha/2} , α/2 \alpha/2 to its right. With 14 degrees they are 5.63 and 26.12, at different distances from 14 (the mean of the χ2(14) \chi^2(14) ), because the right tail is longer.

Step 2: take reciprocals

All three sides are positive, so by rule 6, taking reciprocals reverses the inequalities:

1q1−α/2≤σ2(n−1)S2≤1qα/2 \frac{1}{q_{1-\alpha/2}} \le \frac{\sigma^2}{(n-1)S^2} \le \frac{1}{q_{\alpha/2}}

Notice: q1−α/2 q_{1-\alpha/2} , which was on the right, is now on the left.

Step 3: multiply

Multiplying by (n−1)S2>0 (n-1)S^2 > 0 (rule 6, nothing changes):

(n−1)S2q1−α/2≤σ2≤(n−1)S2qα/2 \frac{(n-1)S^2}{q_{1-\alpha/2}} \le \sigma^2 \le \frac{(n-1)S^2}{q_{\alpha/2}}

∎ And as the square root is increasing, taking the root of all three sides gives the interval for σ.

Why the quantiles swap placesTop, an axis for the pivot Q with the interval from 5.63 to 26.12. Bottom, a variance axis with the interval from 8.10 to 37.60. Two crossing arrows: 26.12 goes down to 8.10 and 5.63 down to 37.60, because the variance is 211.67 over Q, a decreasing function.0510152025303540Pivot Q = 14 s²/σ² ~ χ²(14)5.6326.120510152025303540σ² = 211.67 / Q8.1037.60the big one goes down,the small one up
Dividing by Q reverses the order: the big quantile gives the lower limit.

In the drawing, the range of Q (top) goes from 5.63 to 26.12 with the 15 Gáldar bunches; when you move to σ2=211.67/Q \sigma^2 = 211.67/Q , the 26.12 end lands on the small side (8.10) and 5.63 on the big one (37.60). A decreasing function swaps the ends.

My anecdote. If in step 2 you do not reverse the inequalities, the “interval” is (37.60, 8.10): empty. Always check that L < U.

Result for the cheat sheet. σ2 \sigma^2 : ((n−1)s2/q1−α/2, (n−1)s2/qα/2) \big((n-1)s^2/q_{1-\alpha/2},\ (n-1)s^2/q_{\alpha/2}\big) , with q q from χ2(n−1) \chi^2(n-1) ; for σ, the root of the ends.

Check you’ve got it: with the 15 bunches from Gáldar, what is the 95 % interval for σ, not for σ²?

The one for σ2 \sigma^2 is (8.10, 37.60). The square root is increasing, so it flips nothing: take the root of each end and leave each one where it is. You get (2.85, 6.13), which is not symmetric around s = 3.89.

Check it with R

set.seed(3)
n <- 15; sigma2 <- 16
q <- qchisq(c(0.975, 0.025), n - 1)              # the big one first
hits <- replicate(10000, {
  ci <- (n - 1) * var(rnorm(n, 38, 4)) / q
  ci[1] <= sigma2 & sigma2 <= ci[2]
})
mean(hits)
galdar <- c(38.9, 36.7, 36.8, 28.8, 37.3, 38.6, 32.0, 34.0, 34.2, 36.0, 37.3, 36.4, 45.4, 39.6, 41.2)
round((15 - 1) * var(galdar) / q, 2)

Output:

[1] 0.9488
[1]  8.1 37.6

The interval hits in 95 % of samples, and with the Gáldar data it gives (8.10, 37.60), the one in the theory.

Proof 4: the difference of two normal means

What we want to prove

With X1,…,Xm X_1,\dots,X_m from N(μ1,σ1) N(\mu_1,\sigma_1) and Y1,…,Yn Y_1,\dots,Y_n from N(μ2,σ2) N(\mu_2,\sigma_2) independent:

(a) with σ1,σ2 \sigma_1, \sigma_2 known, (Xˉ−Yˉ)±z1−α/2σ12/m+σ22/n (\bar X – \bar Y) \pm z_{1-\alpha/2}\sqrt{\sigma_1^2/m + \sigma_2^2/n} ;

(b) with σ1=σ2=σ \sigma_1 = \sigma_2 = \sigma unknown, (Xˉ−Yˉ)±tm+n−2, 1−α/2 Sp1/m+1/n (\bar X – \bar Y) \pm t_{m+n-2,\,1-\alpha/2}\,S_p\sqrt{1/m+1/n} , with 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} .

Why it matters. It is the proof behind “do bunches from Gáldar and from Tazacorte weigh the same?”: if the interval for μ1−μ2 \mu_1-\mu_2 does not contain 0, there is a difference. The path is the usual one, with the difference of means playing the role of Xˉ \bar X ; what is new is pooling the two S2 S^2 in case (b).

What we start from

From rule 2 in each sample, Xˉ∼N(μ1,σ1/m) \bar X \sim N(\mu_1, \sigma_1/\sqrt m) and Yˉ∼N(μ2,σ2/n) \bar Y \sim N(\mu_2, \sigma_2/\sqrt n) , independent; from the fact that the difference of independent normals is normal, with variance the sum of the variances; and from rules 3, 4 and 5.

Step 1: the difference of means

Xˉ−Yˉ∼N(μ1−μ2, σ12m+σ22n) \bar X – \bar Y \sim N\left(\mu_1 – \mu_2,\ \sqrt{\frac{\sigma_1^2}{m} + \frac{\sigma_2^2}{n}}\right)

The variance is Var(Xˉ)+Var(Yˉ) \mathrm{Var}(\bar X) + \mathrm{Var}(\bar Y) : subtracting does not subtract variances, because Var(−Yˉ)=(−1)2Var(Yˉ) \mathrm{Var}(-\bar Y) = (-1)^2\mathrm{Var}(\bar Y) .

Step 2: case (a)

Standardising, Z=(Xˉ−Yˉ)−(μ1−μ2)σ12/m+σ22/n∼N(0,1) Z = \frac{(\bar X – \bar Y) – (\mu_1-\mu_2)}{\sqrt{\sigma_1^2/m + \sigma_2^2/n}} \sim N(0,1) , which is a pivot for μ1−μ2 \mu_1-\mu_2 . Solving as in proof 1 (with Xˉ−Yˉ \bar X – \bar Y playing the role of Xˉ \bar X ) gives interval (a). ∎

Step 3: case (b), the Z with a common σ

With σ1=σ2=σ \sigma_1 = \sigma_2 = \sigma , the denominator is σ2(1/m+1/n)=σ1/m+1/n \sqrt{\sigma^2(1/m+1/n)} = \sigma\sqrt{1/m+1/n} :

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

Step 4: pool the two variances

By rule 3, V1=(m−1)S12/σ2∼χ2(m−1) V_1 = (m-1)S_1^2/\sigma^2 \sim \chi^2(m-1) and V2=(n−1)S22/σ2∼χ2(n−1) V_2 = (n-1)S_2^2/\sigma^2 \sim \chi^2(n-1) , independent (they come from independent samples). By rule 5:

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

The last equality is the definition of Sp2 S_p^2 multiplied out: a mean of the two sample variances with weights m−1 m-1 and n−1 n-1 . And the degrees add up: 14 + 11 = 25.

And V is independent of Z, because the S2 S^2 are independent of the means (rule 3).

Step 5: build the t

By rule 4 with k=m+n−2 k = m+n-2 :

T=ZV/(m+n−2)=(Xˉ−Yˉ)−(μ1−μ2)σ1/m+1/n⋅σSp=(Xˉ−Yˉ)−(μ1−μ2)Sp1/m+1/n∼t(m+n−2) T = \frac{Z}{\sqrt{V/(m+n-2)}} = \frac{(\bar X – \bar Y) – (\mu_1-\mu_2)}{\sigma\sqrt{1/m+1/n}}\cdot\frac{\sigma}{S_p} = \frac{(\bar X – \bar Y) – (\mu_1-\mu_2)}{S_p\sqrt{1/m+1/n}} \sim t(m+n-2)

σ cancels as in proof 2. Solving for μ1−μ2 \mu_1-\mu_2 gives interval (b). ∎

Subtracting the variances in step 1 (“the difference of means has variance σ12/m−σ22/n \sigma_1^2/m – \sigma_2^2/n “). With two similar variances it would come out almost 0 or negative. Variances of independent variables always add.

For the curious. If the variances are unequal and unknown, (Xˉ−Yˉ)−(μ1−μ2)S12/m+S22/n \frac{(\bar X-\bar Y)-(\mu_1-\mu_2)}{\sqrt{S_1^2/m+S_2^2/n}} is not exactly a t; Welch approximated it with a t whose degrees of freedom depend on S12 S_1^2 and S22 S_2^2 . That is what t.test(x, y) does by default, and it is not proved in ME1.

Result for the cheat sheet. μ1−μ2 \mu_1-\mu_2 : known, (xˉ−yˉ)±zσ12/m+σ22/n (\bar x-\bar y) \pm z\sqrt{\sigma_1^2/m+\sigma_2^2/n} ; equal, (xˉ−yˉ)±tm+n−2 sp1/m+1/n (\bar x-\bar y) \pm t_{m+n-2}\,s_p\sqrt{1/m+1/n} with 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} .

Check you’ve got it: with 15 and 12 bunches, why does the t have 25 degrees and not 26?

Because each sample spends one degree estimating its own mean: 14 and 11, which rule 5 adds up. To get 26 you would have to use a single mean for both farms, which is exactly what you do not know is true.

Check it with R

We simulate step 4: if V is a χ2(25) \chi^2(25) with 15 and 12 bunches, its mean is 25 and its variance 50. And the pooled interval hits 95 %:

set.seed(4)
m <- 15; n <- 12; sigma <- 4
r <- replicate(10000, {
  x <- rnorm(m, 38, sigma); y <- rnorm(n, 34, sigma)
  sp2 <- ((m - 1) * var(x) + (n - 1) * var(y)) / (m + n - 2)
  V   <- (m + n - 2) * sp2 / sigma^2
  e   <- qt(0.975, m + n - 2) * sqrt(sp2) * sqrt(1 / m + 1 / n)
  c(V = V, hits = abs((mean(x) - mean(y)) - 4) <= e)
})
round(c(mean_V = mean(r["V", ]), var_V = var(r["V", ]), coverage = mean(r["hits", ])), 3)

Output:

  mean_V    var_V coverage 
  24.979   50.376    0.949 

The mean of V is around 25 and its variance 50, those of a χ2(25) \chi^2(25) , and the interval hits 95 %.

Proof 5: the ratio of variances

What we want to prove

That the (1−α)100 % (1-\alpha)100\,\% interval for σ12/σ22 \sigma_1^2/\sigma_2^2 is

(S12S22⋅1f1−α/2,  S12S22⋅1fα/2) \left(\frac{S_1^2}{S_2^2}\cdot\frac{1}{f_{1-\alpha/2}},\ \ \frac{S_1^2}{S_2^2}\cdot\frac{1}{f_{\alpha/2}}\right)

with fp f_p the quantiles of F(m−1,n−1) F(m-1, n-1) .

Why it matters. Case (b) of proof 4 assumes equal variances, and this interval checks it: if it contains 1, there is no reason to doubt it. With Gáldar and Tazacorte, (0.19, 1.37) at 90 %, which contains 1.

What we start from

From rule 3 in each sample and from rule 5.

Step 1: the pivot

With V1=(m−1)S12/σ12∼χ2(m−1) V_1 = (m-1)S_1^2/\sigma_1^2 \sim \chi^2(m-1) and V2=(n−1)S22/σ22∼χ2(n−1) V_2 = (n-1)S_2^2/\sigma_2^2 \sim \chi^2(n-1) independent, by rule 5:

F=V1/(m−1)V2/(n−1)=S12/σ12S22/σ22=S12S22⋅σ22σ12∼F(m−1, n−1) F = \frac{V_1/(m-1)}{V_2/(n-1)} = \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} = \frac{S_1^2}{S_2^2}\cdot\frac{\sigma_2^2}{\sigma_1^2} \sim F(m-1,\, n-1)

It depends on the samples and on the ratio σ12/σ22 \sigma_1^2/\sigma_2^2 (as σ22/σ12 \sigma_2^2/\sigma_1^2 , its reciprocal), and its distribution does not depend on it: it is a pivot.

Step 2: cut and solve

As with the variance, the F is not symmetric and only takes positive values: two different quantiles, α/2 \alpha/2 in each tail, and with probability 1−α 1-\alpha the pivot lies between them:

fα/2≤S12S22⋅σ22σ12≤f1−α/2 f_{\alpha/2} \le \frac{S_1^2}{S_2^2}\cdot\frac{\sigma_2^2}{\sigma_1^2} \le f_{1-\alpha/2}

Dividing by S12/S22>0 S_1^2/S_2^2 > 0 :

S22S12fα/2≤σ22σ12≤S22S12f1−α/2 \frac{S_2^2}{S_1^2}f_{\alpha/2} \le \frac{\sigma_2^2}{\sigma_1^2} \le \frac{S_2^2}{S_1^2}f_{1-\alpha/2}

Taking reciprocals (rule 6, it reverses):

S12S22⋅1f1−α/2≤σ12σ22≤S12S22⋅1fα/2 \frac{S_1^2}{S_2^2}\cdot\frac{1}{f_{1-\alpha/2}} \le \frac{\sigma_1^2}{\sigma_2^2} \le \frac{S_1^2}{S_2^2}\cdot\frac{1}{f_{\alpha/2}}

∎ Once again the big quantile ends up in the lower limit.

The degrees of freedom the wrong way round. If the ratio is S12/S22 S_1^2/S_2^2 , the F is F(m−1,n−1) F(m-1, n-1) : the first degree, the numerator’s. var.test(x, y) does it in that order; var.test(y, x) gives the interval for the reciprocal ratio.

Result for the cheat sheet. σ12/σ22 \sigma_1^2/\sigma_2^2 : (s12s221f1−α/2, s12s221fα/2) \big(\frac{s_1^2}{s_2^2}\frac{1}{f_{1-\alpha/2}},\ \frac{s_1^2}{s_2^2}\frac{1}{f_{\alpha/2}}\big) , with f f from F(m−1,n−1) F(m-1, n-1) .

Check you’ve got it: if you run var.test(tazacorte, galdar) at 90 %, what interval do you get and why?

(0.73, 5.14). The ratio is now the reciprocal, σ22/σ12 \sigma_2^2/\sigma_1^2 , with the F on degrees (11, 14). Since f0.95(11,14)=1/f0.05(14,11) f_{0.95}(11, 14) = 1/f_{0.05}(14, 11) , the ends are the reciprocals of the previous ones, swapped: 1/1.3678 = 0.73 and 1/0.1947 = 5.14. Same conclusion: it contains 1.

Check it with R

galdar    <- c(38.9, 36.7, 36.8, 28.8, 37.3, 38.6, 32.0, 34.0, 34.2, 36.0, 37.3, 36.4, 45.4, 39.6, 41.2)
tazacorte <- c(32.6, 44.8, 30.8, 26.1, 28.9, 30.8, 39.9, 36.0, 34.7, 36.9, 29.7, 29.2)
r  <- var(galdar) / var(tazacorte)
f  <- qf(c(0.95, 0.05), 14, 11)                     # at 90 %: the big one first
round(c(ratio = r, L = r / f[1], U = r / f[2]), 4)
round(var.test(galdar, tazacorte, conf.level = 0.90)$conf.int, 4)

Output:

 ratio      L      U 
0.5332 0.1947 1.3678 
[1] 0.1947 1.3678
attr(,"conf.level")
[1] 0.9

By hand and with var.test, the same (0.1947, 1.3678).

Proof 6: the exact exponential pivot

This is the one that comes up in EC2 as a whole exercise: with little data, the asymptotic interval for λ is not reliable, and there is an exact pivot.

What we want to prove

With X1,…,Xn X_1,\dots,X_n an s.r.s. from an exponential(λ) and T=∑Xi T = \sum X_i :

(a) T∼gamma(n,λ) T \sim \text{gamma}(n, \lambda) ;

(b) U=2λT∼χ2(2n) U = 2\lambda T \sim \chi^2(2n) ;

(c) the exact (1−α)100 % (1-\alpha)100\,\% interval for λ is (qα/22T, q1−α/22T) \left(\dfrac{q_{\alpha/2}}{2T},\ \dfrac{q_{1-\alpha/2}}{2T}\right) , with qp q_p the quantiles of χ2(2n) \chi^2(2n) ;

(d) the asymptotic interval is λ^±z1−α/2 λ^/n \hat\lambda \pm z_{1-\alpha/2}\,\hat\lambda/\sqrt n , with λ^=1/Xˉ=n/T \hat\lambda = 1/\bar X = n/T .

The path. The mgf says the sum is a gamma; a change of scale turns it into a chi-squared without λ, which is the pivot; and you solve. Part (d) goes separately.

What we start from

From rule 7 and from the moment generating function, which identifies a distribution.

Step 1: the distribution of T, with the mgf

The mgf of an exponential(λ) is MX(s)=λλ−s M_X(s) = \frac{\lambda}{\lambda – s} for s<λ s < \lambda . As the Xi X_i are independent, the mgf of the sum is the product:

MT(s)=∏i=1nMXi(s)=(λλ−s)n M_T(s) = \prod_{i=1}^n M_{X_i}(s) = \left(\frac{\lambda}{\lambda – s}\right)^n

which is the mgf of a gamma(n,λ) (n, \lambda) . By uniqueness of the mgf, T∼gamma(n,λ) T \sim \text{gamma}(n,\lambda) : (a).

Step 2: the density of U = 2λT

The density of T is fT(t)=λnΓ(n)tn−1e−λt f_T(t) = \frac{\lambda^n}{\Gamma(n)}t^{n-1}e^{-\lambda t} , t>0 t > 0 . U is a rescaling of T with c=2λ>0 c = 2\lambda > 0 , so by rule 7, with t=u/(2λ) t = u/(2\lambda) :

fU(u)=12λ λnΓ(n)(u2λ)n−1e−λu/(2λ) f_U(u) = \frac{1}{2\lambda}\,\frac{\lambda^n}{\Gamma(n)}\left(\frac{u}{2\lambda}\right)^{n-1}e^{-\lambda u/(2\lambda)}

Piece by piece: the 12λ \frac{1}{2\lambda} in front is the 1c \frac1c of rule 7, and every t is replaced by u/(2λ) u/(2\lambda) . Then 2λ (2λ)n−1=(2λ)n=2nλn 2\lambda\,(2\lambda)^{n-1} = (2\lambda)^n = 2^n\lambda^n cancels with the λn \lambda^n on top, and in the exponent λ⋅u/(2λ)=u/2 \lambda\cdot u/(2\lambda) = u/2 .

Step 3: simplify

Gathering the powers of λ: λn2λ (2λ)n−1=λn2nλn=12n \frac{\lambda^n}{2\lambda\,(2\lambda)^{n-1}} = \frac{\lambda^n}{2^n\lambda^n} = \frac{1}{2^n} . And the exponent becomes −u/2 -u/2 :

fU(u)=12n Γ(n) un−1e−u/2,u>0 f_U(u) = \frac{1}{2^n\,\Gamma(n)}\,u^{n-1}e^{-u/2},\quad u > 0

λ has disappeared. It is the density of a gamma(n,1/2) (n, 1/2) , which by rule 7 is a χ2(2n) \chi^2(2n) (the degrees of freedom are twice the shape): (b).

Step 4: the exact interval

U depends on the sample (through T) and on λ, and its distribution χ2(2n) \chi^2(2n) does not depend on λ: it is a pivot. So

P(qα/2≤2λT≤q1−α/2)=1−α P\left(q_{\alpha/2} \le 2\lambda T \le q_{1-\alpha/2}\right) = 1-\alpha

and dividing by 2T>0 2T > 0 (rule 6, nothing changes):

qα/22T≤λ≤q1−α/22T \frac{q_{\alpha/2}}{2T} \le \lambda \le \frac{q_{1-\alpha/2}}{2T}

Nothing flips here: λ is in the numerator of the pivot. (c) ∎

Step 5: the asymptotic one

By rule 8: the information of one exponential observation is i(λ)=1/λ2 i(\lambda) = 1/\lambda^2 (computed in the properties of estimators), so λ^≈N(λ,λ/n) \hat\lambda \approx N(\lambda, \lambda/\sqrt n) . Replacing λ with λ^ \hat\lambda in the standard deviation and standardising, λ^−λλ^/n≈N(0,1) \frac{\hat\lambda – \lambda}{\hat\lambda/\sqrt n} \approx N(0,1) , and solving as in proof 1 gives (d). ∎

The calculation that gets skipped: 1/(n i(λ))=λ2/n=λ/n \sqrt{1/(n\,i(\lambda))} = \sqrt{\lambda^2/n} = \lambda/\sqrt n , because λ > 0.

Simulated U = 2λT against the chi-squared with 24 degreesHistogram of ten thousand values of U equal to 2 lambda T, each from 12 exponential waits with rate 1 over 26, over an axis from 0 to 60. On top, the chi-squared curve with 24 degrees of freedom, in coral, following the shape of the histogram, with its peak near 22.0.000.020.040.060102030405060u = 2λTdensity10,000 values of Uχ²(24)
The distribution of 2λT does not depend on λ: that is why it is a pivot.

In the drawing, the histogram of 10,000 values of U=2λT U = 2\lambda T simulated with 12 exponential waits matches the χ2(24) \chi^2(24) curve, and would with any λ: that is λ disappearing from the distribution.

Giving the χ² n degrees of freedom. It is 2n 2n : gamma(n,1/2) (n, 1/2) is the χ2 \chi^2 with 2n 2n degrees. With n = 12, qchisq(…, 24), not qchisq(…, 12).

Result for the cheat sheet. Exponential(λ): ∑Xi∼gamma(n,λ) \sum X_i \sim \text{gamma}(n,\lambda) , 2λ∑Xi∼χ2(2n) 2\lambda\sum X_i \sim \chi^2(2n) ; exact (qα/2/(2∑xi), q1−α/2/(2∑xi)) \big(q_{\alpha/2}/(2\sum x_i),\ q_{1-\alpha/2}/(2\sum x_i)\big) ; asymptotic λ^±z λ^/n \hat\lambda \pm z\,\hat\lambda/\sqrt n .

Check you’ve got it: with 12 waiting times, which distribution do the quantiles of the exact 95 % interval come from, and what are they?

From the chi-squared with 2n = 24 degrees: 2λT 2\lambda T is a gamma(12, 1/2), and the χ2(k) \chi^2(k) is the gamma(k/2, 1/2). They are 12.40 and 39.36 (the chi2_24 row below), and the interval is (12.40/(2T), 39.36/(2T)). Nothing flips: λ is on top in the pivot.

Check it with R

set.seed(6)
n <- 12; lambda <- 1 / 26
U <- replicate(10000, 2 * lambda * sum(rexp(n, lambda)))
round(rbind(simulated = quantile(U, c(0.025, 0.5, 0.975)),
            chi2_24   = qchisq(c(0.025, 0.5, 0.975), 2 * n)), 2)
r <- replicate(10000, {
  x <- rexp(n, lambda); l <- 1 / mean(x)
  ex <- qchisq(c(0.025, 0.975), 2 * n) / (2 * sum(x))
  as <- l + c(-1, 1) * qnorm(0.975) * l / sqrt(n)
  c(exact_low = lambda < ex[1], exact_high = lambda > ex[2],      # misses on each side
    asym_low  = lambda < as[1], asym_high  = lambda > as[2])
})
round(rowMeans(r), 4)

Output:

           2.5%   50% 97.5%
simulated 12.25 23.27 39.74
chi2_24   12.40 23.34 39.36
 exact_low exact_high   asym_low  asym_high 
    0.0257     0.0235     0.0069     0.0368 

The simulated quantiles of U match those of χ2(24) \chi^2(24) . The second part counts which side each interval misses on: exact_low is the proportion of samples in which λ falls below the range, and exact_high, above it. The exact one misses 2.6 % on one side and 2.4 % on the other, as it should (2.5 % + 2.5 %). The asymptotic one misses about as much in total (4.4 %), but almost always on the same side: 3.7 % of the time λ is above it and only 0.7 % below. That is because λ^=1/Xˉ \hat\lambda = 1/\bar X is not symmetric with 12 values (it has a long right tail), and the symmetric range λ^±… \hat\lambda \pm \ldots does not capture that. With large n both sides even out; with little data, go for the exact one.

Proof 7: θ of a uniform(0, θ) with the maximum

What we want to prove

Lorries leave the farm on time, but reach the packing house with a delay that is uniform between 0 and θ minutes. With X1,…,Xn X_1,\dots,X_n an s.r.s. from a uniform(0, θ), the MLE is the maximum, X(n) X_{(n)} . We want to prove that W=X(n)/θ W = X_{(n)}/\theta is a pivot with FW(w)=wn F_W(w) = w^n on (0, 1), and that the shortest (1−α)100 % (1-\alpha)100\,\% interval based on it is

(X(n),  X(n)α1/n) \left(X_{(n)},\ \ \frac{X_{(n)}}{\alpha^{1/n}}\right)

Why it matters. There is no normal, t or chi-squared here: the pivot is built from the distribution of the maximum. And it shows that “equal tails” is a habit, not a rule: if the pivot’s density is not symmetric, there can be a shorter interval with the same confidence.

What we start from

From the distribution of the maximum (seen in the properties of estimators): P(X(n)≤x)=(x/θ)n P(X_{(n)} \le x) = (x/\theta)^n for 0≤x≤θ 0 \le x \le \theta , because the maximum is small only if they all are.

Step 1: the pivot

For 0≤w≤1 0 \le w \le 1 :

P(W≤w)=P(X(n)≤wθ)=(wθθ)n=wn P(W \le w) = P\left(X_{(n)} \le w\theta\right) = \left(\frac{w\theta}{\theta}\right)^n = w^n

θ is gone: W has distribution FW(w)=wn F_W(w) = w^n (density nwn−1 n w^{n-1} ) with no parameters, and it depends on the sample and on θ. It is a pivot.

Step 2: any interval

If P(a≤W≤b)=bn−an=1−α P(a \le W \le b) = b^n – a^n = 1-\alpha , solving for θ (taking reciprocals reverses, rule 6, then multiply by X(n)>0 X_{(n)} > 0 ):

a≤X(n)θ≤b  ⟺  X(n)b≤θ≤X(n)a a \le \frac{X_{(n)}}{\theta} \le b \iff \frac{X_{(n)}}{b} \le \theta \le \frac{X_{(n)}}{a}

Step 3: which one is shortest

The length is X(n)(1a−1b) X_{(n)}\left(\frac1a – \frac1b\right) . To make it small, a has to be as big as possible and so does b. As W never exceeds 1, the biggest b is b=1 b = 1 , and then 1−an=1−α 1 – a^n = 1-\alpha gives a=α1/n a = \alpha^{1/n} . Substituting:

X(n)1≤θ≤X(n)α1/n \frac{X_{(n)}}{1} \le \theta \le \frac{X_{(n)}}{\alpha^{1/n}}

∎ The lower limit is the maximum itself, which makes perfect sense: θ cannot be smaller than the largest delay you have seen.

Why b = 1: a and b are tied by bn−an=1−α b^n – a^n = 1-\alpha , so if b goes up, a goes up too. Raising b lengthens a little and raising a shortens, and the second wins: the length changes with b at rate 1/b2−bn−1/an+1 1/b^2 – b^{n-1}/a^{n+1} , negative because a < b. That is why b is pushed to its ceiling, 1.

Two 90 % intervals with the uniform pivotTwo panels with the density 12 w to the 11th between 0.6 and 1, packed against 1. Left, equal tails: 5 percent shaded below 0.779 and another above 0.996; the theta interval goes from 23.00 to 29.39, length 6.40. Right, all 10 percent to the left of 0.825; the interval goes from 22.90 to 27.74, length 4.84.048120.60.70.80.91.0wEqual tails (5 % + 5 %)0.779θ between 23.00 and 29.39length 6.40048120.60.70.80.91.0wAll on the left (10 %)0.825θ between 22.90 and 27.74length 4.84
Cutting the tail where the density is low gives the shortest interval, which starts at the maximum.

The drawing shows the density nwn−1 n w^{n-1} of W with n = 12, packed against 1. Two ways of leaving out 10 %: with equal tails (5 % on each side) or all on the left. The second cuts the area where the density is low, which is why it gives a shorter interval.

Using equal tails out of habit. It is valid (it has the required confidence), but it is not the shortest, and if the question asks for “the shortest interval”, it is the one with b=1 b = 1 .

Result for the cheat sheet. Uniform(0, θ): X(n)/θ X_{(n)}/\theta has F(w)=wn F(w) = w^n ; shortest interval (x(n), x(n)/α1/n) \big(x_{(n)},\ x_{(n)}/\alpha^{1/n}\big) .

Check you’ve got it: with the 12 lorries (maximum 22.9 minutes), what is the shortest 95 % interval?

a=0.051/12=0.78 a = 0.05^{1/12} = 0.78 , so (22.9, 22.9/0.051/12)=(22.9, 29.39) (22.9,\ 22.9/0.05^{1/12}) = (22.9,\ 29.39) minutes. Longer than the 90 % one, (22.9, 27.74): more confidence needs a wider range. The lower limit is still the maximum.

Check it with R

With the delays (in minutes) of 12 lorries and 90 % confidence:

delays <- c(5.2, 3.1, 7.3, 9.4, 21.2, 13.2, 13.0, 5.9, 8.2, 22.9, 10.4, 8.6)
n <- length(delays); mx <- max(delays); alpha <- 0.10
shortest <- c(mx, mx / alpha^(1 / n))
equal    <- c(mx / (1 - alpha / 2)^(1 / n), mx / (alpha / 2)^(1 / n))
round(rbind(shortest = c(shortest, length = diff(shortest)), equal = c(equal, diff(equal))), 2)
set.seed(7)
mean(replicate(10000, { x <- runif(n, 0, 25); max(x) <= 25 & 25 <= max(x) / alpha^(1 / n) }))

Output:

                    length
shortest 22.9 27.74   4.84
equal    23.0 29.39   6.40
[1] 0.8971

The shortest, (22.9, 27.74), is 4.84 minutes long; the equal-tails one, 6.40. And the shortest hits in 90 % of the simulated samples, as it should.

Proof 8: sample size

What we want to prove

(a) For the margin of error of the interval for the mean not to exceed δ, n≥(z1−α/2 σ/δ)2 n \ge \left(z_{1-\alpha/2}\,\sigma/\delta\right)^2 is enough.

(b) For a proportion, without knowing p, n≥(z1−α/2/(2δ))2 n \ge \left(z_{1-\alpha/2}/(2\delta)\right)^2 is enough.

Why it matters. The others go from the data to the interval; this one goes the other way: before collecting anything, how much data you need for the interval to be as narrow as you want. You solve the margin for n instead of μ.

What we start from

From the margin of each interval: z σ/n z\,\sigma/\sqrt n for the mean and zp(1−p)/n z\sqrt{p(1-p)/n} for the proportion (we write z for z1−α/2 z_{1-\alpha/2} ).

Step 1: the mean

Everything is positive, so multiplying, dividing and squaring do not change the direction (rule 6):

zσn≤δ  ⟺  zσ≤δn  ⟺  n≥zσδ  ⟺  n≥(zσδ)2 z\frac{\sigma}{\sqrt n} \le \delta \iff z\sigma \le \delta\sqrt n \iff \sqrt n \ge \frac{z\sigma}{\delta} \iff n \ge \left(\frac{z\sigma}{\delta}\right)^2

(a) ∎ As n is a whole number, you take the first integer that satisfies it: you round up.

Step 2: the proportion, with p known

Same as step 1: zp(1−p)/n≤δ  ⟺  n≥(z/δ)2 p(1−p) z\sqrt{p(1-p)/n} \le \delta \iff n \ge (z/\delta)^2\,p(1-p) .

Step 3: the worst case of p(1 − p)

Completing the square:

p(1−p)=p−p2=14−(p−12)2≤14 p(1-p) = p – p^2 = \frac14 – \left(p – \frac12\right)^2 \le \frac14

because a square is never negative. The maximum, 1/4, is reached at p=1/2 p = 1/2 . So if n≥(z/δ)2⋅14=(z2δ)2 n \ge (z/\delta)^2\cdot\frac14 = \left(\frac{z}{2\delta}\right)^2 , then also n≥(z/δ)2 p(1−p) n \ge (z/\delta)^2\,p(1-p) for any p. (b) ∎

The worst case of p(1 − p)The parabola p times 1 minus p between 0 and 1, with its maximum of one quarter at p equal to one half, marked with a coral line. A green dot at p equal to 0.115 marks 0.102, less than half the ceiling.0.000.050.100.150.200.250.00.20.40.60.81.0pp(1 − p)ceiling 1/4 at p = 1/2p̂ = 0.115 → 0.102
With p far from 1/2, the worst case asks for far more data: 1068 against 435.

In the drawing, the parabola p(1−p) p(1-p) peaks at 1/4 when p=1/2 p = 1/2 . If the real proportion is far from 1/2 (like the 11.5 % of rejected bunches), the worst case asks for much more data than needed: 1068 against 435 for a 3-point error.

The two figures, with δ = 0.03: with no information, (z/(2⋅0.03))2=1067.07 (z/(2\cdot 0.03))^2 = 1067.07 , rounded up to 1068; with p^=0.115 \hat p = 0.115 , (z/0.03)2⋅0.115⋅0.885=434.40 (z/0.03)^2\cdot 0.115\cdot 0.885 = 434.40 , rounded up to 435.

Rounding 61.46 to 61. With 61 bunches the margin is 1.96⋅4/61=1.004>1 1.96\cdot 4/\sqrt{61} = 1.004 > 1 : the requirement is no longer met.

Result for the cheat sheet. Mean: n≥(zσ/δ)2 n \ge (z\sigma/\delta)^2 (with a pilot S if σ is unknown). Proportion: n≥(z/δ)2p^(1−p^) n \ge (z/\delta)^2\hat p(1-\hat p) or, with no information, n≥(z/(2δ))2 n \ge (z/(2\delta))^2 . Always round up.

Check you’ve got it: with σ = 4 and 95 % confidence, how many bunches do you need for a margin of 0.5 instead of 1?

n≥(z⋅4/0.5)2=245.85 n \ge (z\cdot 4/0.5)^2 = 245.85 : 246 bunches, against 62. Halving the margin multiplies n by 4, because δ is squared.

Check it with R

z <- qnorm(0.975)
round(c(n61 = z * 4 / sqrt(61), n62 = z * 4 / sqrt(62)), 4)    # margin with 61 and with 62
p <- seq(0, 1, by = 0.1)
round(p * (1 - p), 2)

Output:

   n61    n62 
1.0038 0.9957 
 [1] 0.00 0.09 0.16 0.21 0.24 0.25 0.24 0.21 0.16 0.09 0.00

With 61 bunches the margin is above 1 (1.0038); with 62 it is not (0.9957). And p(1−p) p(1-p) rises to 0.25 in the middle and falls symmetrically.

Prove it yourself

Three derivations in the style of EC2. Try them on paper before opening the solution.

  1. Let X1,…,Xn X_1,\dots,X_n be an s.r.s. from N(μ,σ) N(\mu, \sigma) with μ known. Prove that ∑(Xi−μ)2/σ2∼χ2(n) \sum (X_i-\mu)^2/\sigma^2 \sim \chi^2(n) and derive the (1−α)100 % (1-\alpha)100\,\% interval for σ2 \sigma^2 .
See the solution to 1

Each (Xi−μ)/σ∼N(0,1) (X_i-\mu)/\sigma \sim N(0,1) , so its square is a χ2(1) \chi^2(1) , and the n of them are independent. By rule 5 (applied n − 1 times), Q=∑(Xi−μ)2/σ2∼χ2(n) Q = \sum (X_i-\mu)^2/\sigma^2 \sim \chi^2(n) . No degree of freedom is lost now because μ is not estimated.

Q is a pivot. With qp q_p from χ2(n) \chi^2(n) , P(qα/2≤Q≤q1−α/2)=1−α P(q_{\alpha/2} \le Q \le q_{1-\alpha/2}) = 1-\alpha , and solving as in proof 3 (taking reciprocals flips it):

(∑(xi−μ)2q1−α/2,  ∑(xi−μ)2qα/2) \left(\frac{\sum (x_i-\mu)^2}{q_{1-\alpha/2}},\ \ \frac{\sum (x_i-\mu)^2}{q_{\alpha/2}}\right)
  1. With the pivot of proof 6, derive the exact interval for the exponential mean, 1/λ 1/\lambda , and compute it with the 40 lorries from the theory (∑xi=1057.9 \sum x_i = 1057.9 ) at 95 %.
See the solution to 2

From qα/22T≤λ≤q1−α/22T \frac{q_{\alpha/2}}{2T} \le \lambda \le \frac{q_{1-\alpha/2}}{2T} , with all three sides positive, taking reciprocals (rule 6, it reverses):

2Tq1−α/2≤1λ≤2Tqα/2 \frac{2T}{q_{1-\alpha/2}} \le \frac{1}{\lambda} \le \frac{2T}{q_{\alpha/2}}

With n = 40, the quantiles are from χ2(80) \chi^2(80) : qchisq(0.975, 80) = 106.63 and qchisq(0.025, 80) = 57.15. Then 2T=2115.8 2T = 2115.8 and the interval is (2115.8/106.63, 2115.8/57.15) = (19.84, 37.02) minutes, the one in the theory.

  1. Let X1,…,Xn X_1,\dots,X_n be an s.r.s. from a Poisson(λ). Derive the (1−α)100 % (1-\alpha)100\,\% asymptotic interval for λ.
See the solution to 3

The MLE is λ^=Xˉ \hat\lambda = \bar X . From log⁡f(x∣λ)=xlog⁡λ−λ−log⁡x! \log f(x\mid\lambda) = x\log\lambda – \lambda – \log x! we get ∂2log⁡f/∂λ2=−x/λ2 \partial^2\log f/\partial\lambda^2 = -x/\lambda^2 , so i(λ)=E(X)/λ2=1/λ i(\lambda) = E(X)/\lambda^2 = 1/\lambda . By rule 8, Xˉ≈N(λ,λ/n) \bar X \approx N(\lambda, \sqrt{\lambda/n}) , and replacing λ with Xˉ \bar X in the standard deviation:

Xˉ−λXˉ/n≈N(0,1) \frac{\bar X – \lambda}{\sqrt{\bar X/n}} \approx N(0,1)

Solving as in proof 1: xˉ±z1−α/2xˉ/n \bar x \pm z_{1-\alpha/2}\sqrt{\bar x/n} .

When to use each result

If you are asked for…UseWatch out for…
an interval for μ of a normalZ if σ is known, T with t(n − 1) if notthe 1 − α/2 quantile, not 1 − α
an interval for σ² or σ(n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1) taking reciprocals swaps the quantiles
comparing two meansXˉ−Yˉ \bar X – \bar Y , variances that addknown, equal, unequal or paired?
comparing two variancesthe F of S12/S22 S_1^2/S_2^2 degrees in order: numerator first
an exact interval for λ of an exponential2λ∑Xi∼χ2(2n) 2\lambda\sum X_i \sim \chi^2(2n) 2n degrees, not n
an interval for θ of a uniform(0, θ)X(n)/θ X_{(n)}/\theta with F(w)=wn F(w) = w^n the shortest starts at the maximum
how much data is neededsolve for n from the marginalways round up

Common mistakes when proving

  • Solving without multiplying by −1. For the mean it works out by symmetry; for everything else, it does not.
  • Not flipping when taking reciprocals (variance, ratio, uniform and the exponential mean). If L > U, a flip is missing.
  • Keeping a pivot that still contains an unknown parameter. The Z with unknown σ is not a pivot; that is why you need the t.
  • Forgetting independence when building the t or the F: rule 3 is what lets you divide Z by V.
  • The χ² with n degrees for the exponential (it is 2n) or with n for the variance (it is n − 1, unless μ is known).
  • Subtracting variances in a difference of means.

Try it in the R playground

Paste this script into the R playground. It checks the exact exponential pivot with another sample size and another rate:

set.seed(11)
n <- 5; lambda <- 0.2                 # change n and lambda
U <- replicate(10000, 2 * lambda * sum(rexp(n, lambda)))
hist(U, breaks = 50, freq = FALSE, main = "2 lambda T", xlab = "u")
curve(dchisq(x, 2 * n), add = TRUE, lwd = 2, col = "red")
r <- replicate(10000, {
  x  <- rexp(n, lambda); l <- 1 / mean(x)
  ex <- qchisq(c(0.025, 0.975), 2 * n) / (2 * sum(x))
  as <- l + c(-1, 1) * qnorm(0.975) * l / sqrt(n)
  c(exact_low = lambda < ex[1], exact_high = lambda > ex[2],
    asym_low  = lambda < as[1], asym_high  = lambda > as[2])
})
round(rowMeans(r), 4)

What to look at:

  1. In Plots, the histogram of U and the red χ2(2n) \chi^2(2n) curve: they match for any lambda.
  2. rowMeans(r): the exact one misses 2.5 % on each side; the asymptotic one, with n = 5, almost never below and 4 % above.
  3. Raise n to 50: the two sides of the asymptotic one even out.
  4. Replace 2 * n with n in qchisq: the coverage of the exact one collapses (the degrees mistake).

Summary

IntervalPivotDistribution
μ, known σ(Xˉ−μ)/(σ/n) (\bar X-\mu)/(\sigma/\sqrt n) N(0, 1)
μ, unknown σ(Xˉ−μ)/(S/n) (\bar X-\mu)/(S/\sqrt n) t(n − 1)
σ²(n−1)S2/σ2 (n-1)S^2/\sigma^2 χ²(n − 1)
μ₁ − μ₂, unknown common σ(Xˉ−Yˉ)−(μ1−μ2)Sp1/m+1/n \frac{(\bar X-\bar Y)-(\mu_1-\mu_2)}{S_p\sqrt{1/m+1/n}} t(m + n − 2)
σ₁²/σ₂²S12/σ12S22/σ22 \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} F(m − 1, n − 1)
Exponential λ (exact)2λ∑Xi 2\lambda\sum X_i χ²(2n)
θ uniform(0, θ)X(n)/θ X_{(n)}/\theta F(w)=wn F(w) = w^n
Sample sizemargin ≤ δ—

Three ideas to take away:

  1. A pivot is half the proof. If you find a quantity with the parameter inside and a known distribution that does not depend on it, the interval comes out by solving.
  2. One inequality at a time. When you multiply by a negative or take reciprocals, everything flips: that is how the big quantile ends up in the lower limit of the variance.
  3. Check with a simulation. If your formula is right, it hits in 95 % of 10,000 samples; if not, the simulation tells you before the lecturer does.

Now it is time to practice it with data: in the confidence intervals practice you will simulate coverage, compare the two farms from start to finish and see when the interval for a proportion fails. And the confidence intervals exercises have derivations and calculations like those in EC2, with commented solutions.

Next step: practiceConfidence intervals in R — practice with simulated coverage, the two farms and when the asymptotic one fails

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