4.9.19Probability Theory & Statistics

Confidence intervals — derivation for mean, proportion

1,907 words9 min readdifficulty · medium

1. The raw material: the sampling distribution

WHY does variance shrink by nn? Variance of a sum of independent variables adds: Var ⁣(Xi)=nσ2    Var ⁣(1nXi)=1n2nσ2=σ2n.\operatorname{Var}\!\left(\sum X_i\right)=n\sigma^2 \implies \operatorname{Var}\!\left(\tfrac1n\sum X_i\right)=\tfrac{1}{n^2}\cdot n\sigma^2=\frac{\sigma^2}{n}. The standard deviation of Xˉ\bar X — called the standard error — is σ/n\sigma/\sqrt n.

HOW do we know its shape? The Central Limit Theorem says for large nn, XˉN ⁣(μ, σ2n)Z=Xˉμσ/nN(0,1).\bar X \approx \mathcal N\!\left(\mu,\ \frac{\sigma^2}{n}\right) \quad\Longleftrightarrow\quad Z=\frac{\bar X-\mu}{\sigma/\sqrt n}\approx \mathcal N(0,1).


2. Deriving the CI for the mean (σ known)

Common zα/2z_{\alpha/2}: 90% → 1.645, 95% → 1.96, 99% → 2.576.

Figure — Confidence intervals — derivation for mean, proportion

3. σ unknown → the t-distribution

WHY swap to tt? When σ\sigma is unknown we plug in the sample SD ss. But ss is itself random and tends to underestimate σ\sigma for small nn, so the statistic has fatter tails. The exact distribution (for normal data) is Student's tt with n1n-1 degrees of freedom.

As nn\to\infty, tn1N(0,1)t_{n-1}\to \mathcal N(0,1), so for big samples the two methods agree.


4. Deriving the CI for a proportion

WHY is this just a special case? A 0/1 (Bernoulli) variable has mean pp and variance p(1p)p(1-p). So p^\hat p is a sample mean of Bernoulli's: E[p^]=p,Var(p^)=p(1p)n.E[\hat p]=p,\qquad \operatorname{Var}(\hat p)=\frac{p(1-p)}{n}. By CLT, p^N ⁣(p, p(1p)n)\hat p\approx \mathcal N\!\big(p,\ \tfrac{p(1-p)}{n}\big) for large nn.


5. Worked examples


6. Common mistakes (Steel-man + fix)


7. Active recall

Recall Quick self-test (answer before peeking)
  1. What does "95% confidence" actually mean?
  2. Why does the interval use σ/n\sigma/\sqrt n not σ\sigma?
  3. When do we use tt instead of zz?
  4. What's the variance of a Bernoulli, and how does it give the proportion SE?

Answers: (1) 95% of intervals built this way capture μ\mu over repeated sampling. (2) We bound the mean, whose SE is σ/n\sigma/\sqrt n. (3) When σ\sigma unknown (esp. small nn). (4) p(1p)p(1-p); SE =p(1p)/n=\sqrt{p(1-p)/n}, estimated by p^\hat p.

Recall Feynman: explain to a 12-year-old

Imagine you taste a few spoons of a giant pot of soup to guess its average saltiness. You won't be exactly right, so instead of saying "the soup is exactly 5 salty," you say "I'm pretty sure it's between 4.5 and 5.5." If lots of friends each taste their own spoons and each draw such a range, about 95 out of 100 friends' ranges would actually contain the true saltiness. That range is the confidence interval, and it gets tighter the more spoons you taste (bigger nn).


8. Connections

  • Central Limit Theorem — engine that makes Xˉ\bar X normal.
  • Standard Error — the σ/n\sigma/\sqrt n shrinking spread.
  • Student's t-distribution — fatter tails for estimated σ\sigma.
  • Hypothesis Testing — CI ↔ test duality (μ0\mu_0 outside CI ⇔ reject at level α\alpha).
  • Bernoulli & Binomial Distributions — basis of proportion variance.
  • Sample Size Determination — invert margin formula to solve for nn.

What does a 95% confidence interval actually mean?
Over many repeated samples, 95% of the intervals constructed this way contain the true parameter (a property of the procedure, not of one interval).
Standard error of the sample mean?
σ/n\sigma/\sqrt n (or s/ns/\sqrt n when σ unknown).
Why does Var(Xˉ)=σ2/n\operatorname{Var}(\bar X)=\sigma^2/n?
Variance of independent sum adds to nσ2n\sigma^2; dividing by nn scales variance by 1/n21/n^2, giving σ2/n\sigma^2/n.
CI for mean with σ known?
Xˉ±zα/2σ/n\bar X \pm z_{\alpha/2}\,\sigma/\sqrt n.
CI for mean with σ unknown?
Xˉ±tα/2,n1s/n\bar X \pm t_{\alpha/2,n-1}\,s/\sqrt n.
Why use tt instead of zz?
ss estimates σ\sigma and adds uncertainty; tn1t_{n-1} has fatter tails, becoming normal as nn\to\infty.
Why n1n-1 degrees of freedom?
One constraint (XiXˉ)=0\sum(X_i-\bar X)=0 is used computing ss, leaving n1n-1 free deviations.
Variance of a Bernoulli(p)?
p(1p)p(1-p).
CI for a proportion (Wald)?
p^±zα/2p^(1p^)/n\hat p \pm z_{\alpha/2}\sqrt{\hat p(1-\hat p)/n}.
Validity rule for proportion CI?
np^5n\hat p\ge 5 and n(1p^)5n(1-\hat p)\ge 5.
Why split α into α/2 per tail?
Two-sided interval leaves equal probability in each tail so the central band holds exactly 1α1-\alpha.
zα/2z_{\alpha/2} for 95%?
1.96 (NOT 1.645, which is one-sided).
How does margin of error change with n?
Shrinks like 1/n1/\sqrt n — quadruple n to halve the margin.

Concept Map

average

E of X-bar

Var = sigma^2 over n

large n

standardize

isolate mu, split alpha

z times SE

sigma unknown, plug in s

fatter tails, n-1 df

n to infinity

1-alpha coverage

i.i.d. sample Xi

Sample mean X-bar

Population mean mu

Standard error sigma over sqrt n

Central Limit Theorem

Z statistic approx N 0,1

CI for mean sigma known

Margin of error E

t statistic

CI for mean sigma unknown

Statement about procedure

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, confidence interval ka idea simple hai. Hum poori population ka mean μ\mu nahi jaante, isliye ek sample lekar uska average Xˉ\bar X nikaalte hain. Lekin Xˉ\bar X exactly μ\mu ke barabar kabhi nahi hota — thoda idhar-udhar hota hai. Is "idhar-udhar" ko measure karta hai standard error =σ/n=\sigma/\sqrt n. Jitna bada sample, utna chhota error, kyunki n\sqrt n neeche hai. Isliye CI ki width bhi tab kam hoti hai.

Derivation yaad rakhne ka tarika: Z=(Xˉμ)/(σ/n)Z=(\bar X-\mu)/(\sigma/\sqrt n) approximately standard normal hota hai (CLT ki wajah se). Ab 95% probability ke liye hum bolte hain 1.96Z1.96-1.96\le Z\le 1.96, phir is inequality ko μ\mu ke liye solve kar dete hain — bas mil gaya formula Xˉ±1.96σ/n\bar X \pm 1.96\,\sigma/\sqrt n. Agar σ\sigma pata nahi hai to uski jagah sample SD ss daalo aur zz ki jagah tn1t_{n-1} use karo, kyunki tab thodi extra uncertainty hoti hai (isliye tt ki tails moti hoti hain).

Proportion ke liye bhi same logic hai — kyunki 0/1 wala Bernoulli variable ka variance p(1p)p(1-p) hota hai, to p^\hat p ka SE =p^(1p^)/n=\sqrt{\hat p(1-\hat p)/n} ban jaata hai, aur CI =p^±1.96p^(1p^)/n=\hat p \pm 1.96\sqrt{\hat p(1-\hat p)/n}.

Sabse important baat (exam aur samajh dono ke liye): "95% confidence" ka matlab yeh nahi hai ki is particular interval mein μ\mu hone ki 95% chance hai. Matlab yeh hai ki agar tum baar-baar experiment karo, to 100 mein se lagbhag 95 intervals sach mein μ\mu ko pakad lenge. Yeh procedure ke baare mein statement hai, ek number ke baare mein nahi.

Go deeper — visual, from zero

Test yourself — Probability Theory & Statistics

Connections