4.9.20Probability Theory & Statistics

Hypothesis testing — null - alternative, test statistic, p-value, errors (Type I & II)

1,950 words9 min readdifficulty · medium6 backlinks

WHY does hypothesis testing exist?

We have a sample, but we want to make a decision about the whole population. The sample is noisy: even if nothing special is happening, random fluctuation produces patterns. So we need a disciplined rule that controls how often we get fooled by randomness. Hypothesis testing is exactly that rule.

WHAT is a test statistic? A single number computed from the data that measures how far the sample sits from what H0H_0 predicts, measured in units of standard error so we know its random distribution.


HOW to derive the z-test statistic from first principles

We want to test H0:μ=μ0H_0:\mu=\mu_0 using sample mean Xˉ\bar X from nn observations with known population SD σ\sigma.

Step 1 — distribution of Xˉ\bar X. Each XiX_i has mean μ\mu and variance σ2\sigma^2. The sample mean is Xˉ=1nXi\bar X=\frac1n\sum X_i.

E[Xˉ]=μ,Var(Xˉ)=1n2Var(Xi)=σ2n.\mathbb E[\bar X]=\mu,\qquad \operatorname{Var}(\bar X)=\frac{1}{n^2}\sum\operatorname{Var}(X_i)=\frac{\sigma^2}{n}. Why this step? Variance of a sum of independent variables adds; the 1/n21/n^2 comes from the constant factor squared.

Step 2 — standard error. So the spread of Xˉ\bar X is SE=σ/n\operatorname{SE}=\sigma/\sqrt n. Why? SD is the square root of variance.

Step 3 — standardize under H0H_0. Assume H0H_0 true, so μ=μ0\mu=\mu_0. By the Central Limit Theorem, Xˉ\bar X is approximately normal, hence

  Z=Xˉμ0σ/n  N(0,1).\boxed{\;Z=\dfrac{\bar X-\mu_0}{\sigma/\sqrt n}\;}\sim \mathcal N(0,1). Why this step? Subtract the assumed mean, divide by SE → a unit-free score telling us how many standard errors the data is from H0H_0.


p-value: the probability of being fooled this badly


Figure — Hypothesis testing — null - alternative, test statistic, p-value, errors (Type I & II)

The two ways to be wrong

WHY there's a tradeoff: lowering α\alpha (being stricter about rejecting) pushes the critical cutoff farther out, which makes it harder to detect true effects → β\beta rises. The only way to shrink both is to increase nn (narrows both distributions).


Worked Example 1 — z-test, two-tailed

A machine should fill bottles to μ0=500\mu_0=500 ml, σ=8\sigma=8 ml. We sample n=64n=64 bottles, get Xˉ=497\bar X=497 ml. Test at α=0.05\alpha=0.05 whether the machine is off.

  • H0:μ=500H_0:\mu=500, H1:μ500H_1:\mu\ne 500. Why two-tailed? "Off" means either too high or too low.
  • SE=8/64=1\operatorname{SE}=8/\sqrt{64}=1. Why? σ/n\sigma/\sqrt n.
  • z=4975001=3z=\dfrac{497-500}{1}=-3. Why? Standardize the observed mean.
  • p=2P(Z3)2(0.00135)=0.0027p=2P(Z\ge 3)\approx 2(0.00135)=0.0027. Why doubled? Both tails are "as extreme."
  • 0.0027<0.050.0027<0.05reject H0H_0. The machine is mis-calibrated.

Worked Example 2 — right-tailed t-test

A new teaching method claims to raise scores above the old mean μ0=70\mu_0=70. Sample: n=16n=16, Xˉ=74\bar X=74, s=6s=6. Test at α=0.05\alpha=0.05.

  • H0:μ=70H_0:\mu=70, H1:μ>70H_1:\mu>70. Why right-tailed? Claim is only "higher."
  • T=74706/16=41.5=2.667T=\dfrac{74-70}{6/\sqrt{16}}=\dfrac{4}{1.5}=2.667 with df=15df=15. Why tt not zz? σ\sigma unknown.
  • Critical t0.05,151.753t_{0.05,15}\approx1.753. Since 2.667>1.7532.667>1.753, p<0.05p<0.05reject H0H_0: evidence the method helps.

Worked Example 3 — interpreting a non-rejection

Same as Ex.2 but Xˉ=71\bar X=71: T=11.5=0.667<1.753T=\frac{1}{1.5}=0.667<1.753fail to reject. Why this wording? We did not prove the method useless; we just lack evidence. Absence of evidence ≠ evidence of absence.



Recall Feynman: explain it to a 12-year-old

Imagine you suspect a coin is rigged. You start by believing it's fair (that's the null). You flip it 100 times and get 80 heads. Now ask: "If the coin really were fair, how often would pure luck give me something this lopsided?" If the answer is "almost never" (tiny p-value), you stop believing it's fair. If "eh, happens sometimes," you shrug and keep believing it's fair — not because you proved it, but because you have no good reason to doubt it. A Type I error is yelling "rigged!" about a perfectly fair coin. A Type II error is calling a loaded coin fair.


Active Recall

What always contains the equality, H0H_0 or H1H_1?
The null hypothesis H0H_0.
Define the p-value precisely.
P(test statistic as or more extreme than observedH0 true)P(\text{test statistic as or more extreme than observed} \mid H_0 \text{ true}).
Decision rule with significance level α\alpha?
Reject H0H_0 if pαp \le \alpha; otherwise fail to reject.
Derive the z-statistic for testing μ=μ0\mu=\mu_0.
Xˉ\bar X has mean μ0\mu_0, variance σ2/n\sigma^2/n under H0H_0; standardize: Z=(Xˉμ0)/(σ/n)N(0,1)Z=(\bar X-\mu_0)/(\sigma/\sqrt n)\sim N(0,1).
When use tt instead of zz?
When population σ\sigma is unknown and estimated by sample ss; then Ttn1T\sim t_{n-1}.
What is a Type I error and its probability?
Rejecting a true H0H_0 (false alarm); probability α\alpha.
What is a Type II error and its probability?
Failing to reject a false H0H_0 (a miss); probability β\beta.
Define statistical power.
1β1-\beta = probability of correctly rejecting a false H0H_0.
Why can't we lower both α\alpha and β\beta freely?
A stricter cutoff lowers α\alpha but raises β\beta; only larger nn shrinks both.
Two-tailed p-value from zobsz_{obs}?
p=2P(Zzobs)p = 2P(Z \ge |z_{obs}|).
Why is "fail to reject" not "accept"?
The test may lack power; absence of evidence isn't evidence of absence.
Prosecutor's fallacy here?
Confusing P(dataH0)P(\text{data}\mid H_0) (the p-value) with P(H0data)P(H_0\mid \text{data}).

Connections

  • Central Limit Theorem — justifies the normal distribution of Xˉ\bar X.
  • Standard Error — the denominator of every test statistic.
  • Confidence Intervals — dual of two-tailed tests (reject ⇔ μ0\mu_0 outside CI).
  • Normal Distribution and Student t-distribution — reference distributions.
  • Bayesian Inference — gives P(H0data)P(H_0\mid \text{data}) directly (what p-values don't).
  • Statistical Power & Sample Size — controlling β\beta.

Concept Map

motivates

assumes true

seeks evidence for

shape decides

standardize under

computes

justifies normal

SE from

gives

too small rejects

controls chance of

Sample from population

Hypothesis testing

Null H0 equality no effect

Alternative H1 the claim

One or two tailed

Test statistic Z or T

Central Limit Theorem

Standard error sigma over sqrt n

p-value

Type I and Type II errors

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hypothesis testing ka basic idea ek courtroom jaisa hai. Hum pehle null hypothesis H0H_0 ko sach maan lete hain — yeh "kuch special nahi ho raha" wala boring claim hota hai (jaise machine theek hai, ya nayi method ka koi farak nahi). Phir hum apne data ko dekhte hain aur poochte hain: "agar H0H_0 sach hota, to itna ajeeb data milne ki probability kitni hoti?" Yeh probability hi p-value hai. Agar p-value bahut chhota hai (chosen α\alpha, usually 0.05, se kam), matlab data H0H_0 ke under bahut hi rare fluke hai — to hum H0H_0 ko reject kar dete hain.

Test statistic sirf ek number hai jo batata hai data H0H_0 se kitna door hai, standard error ke units mein. Jaise z=(Xˉμ0)/(σ/n)z = (\bar X - \mu_0)/(\sigma/\sqrt n). Iska derivation simple hai: sample mean Xˉ\bar X ka variance σ2/n\sigma^2/n hota hai (CLT se), to standardize karke humein N(0,1)N(0,1) score milta hai. Agar σ\sigma pata nahi, to ss use karke tt-test lagate hain.

Do tarah ki galtiyan ho sakti hain. Type I error (α\alpha) — sach H0H_0 ko galti se reject kar dena, yaani false alarm (innocent ko convict). Type II error (β\beta) — galat H0H_0 ko reject na karna, yaani asli effect ko miss kar dena. Yaad rakho: dono ko ek saath kam karna mushkil hai — strict banoge (α\alpha chhota) to β\beta badh jayega; dono ko chhota karna hai to sample size nn badhao.

Sabse common galti: log sochte hain p-value matlab "H0H_0 ke sach hone ki probability". Galat! p-value P(dataH0)P(\text{data} \mid H_0) hai, na ki P(H0data)P(H_0 \mid \text{data}). Aur "fail to reject" ka matlab H0H_0 prove ho gaya nahi hota — bas itna ki abhi enough evidence nahi mila. Yeh distinctions exam aur real research dono mein bahut important hain.

Go deeper — visual, from zero

Test yourself — Probability Theory & Statistics

Connections