Hypothesis Testing
Make decisions using data — with confidence, not guesses 🧠📊
1️⃣ What is Hypothesis Testing?
Hypothesis Testing is a statistical method to decide whether a claim (about a population) is supported by sample data.
We never "prove" with 100% certainty — we measure how strong the evidence is and then decide.
- 🔹 State two opposite statements: Null (H₀) and Alternative (H₁).
- 🔹 Compute a test statistic from sample data.
- 🔹 Use p-value or critical values to decide: reject or fail to reject H₀.
2️⃣ Null & Alternative Hypothesis (Quick)
One-sample Mean
H₁: μ ≠ 70
Two-sample Difference
H₁: μ₁ ≠ μ₂
Proportion Test
H₁: p > 0.5
3️⃣ One-tailed vs Two-tailed (Visual)
Which side(s) of the distribution represent extreme values?
Two-Tailed Test (≠)
Rejection region on both sides
One-Tailed Test (Right >)
Rejection region on one side only
4️⃣ P-value — Intuition
P-value = "If H₀ is true, how likely is the observed result (or more extreme)?"
Rule of Thumb:
- 📉 Small p-value (< 0.05) → Strong evidence against H₀ (Reject).
- 📈 Large p-value (> 0.05) → Weak evidence against H₀ (Fail to Reject).
Visualizing P-value
5️⃣ Case Study: The "30-Min Delivery" Claim
Manual Calculation vs Python Code
The Problem
A pizza shop claims average delivery time is 30 mins. You think it's longer. You collect 10 random delivery times:
[32, 35, 29, 34, 33, 36, 30, 32, 31, 33]
Maths Breakdown 🧮
Step 1: Standard Error
SE = s / √n = 2.27 / 3.16 = 0.718
Step 2: t-statistic
t = (x̄ - μ) / SE
t = (32.5 - 30) / 0.718
t = 2.5 / 0.718 = 3.48
Step 3: Decision
For df=9, critical t is 1.83.
Since 3.48 > 1.83, we Reject H₀.
import scipy.stats as stats # 1. The Data data = [32, 35, 29, 34, 33, 36, 30, 32, 31, 33] # 2. Perform t-test # 'greater' because we test if time > 30 t_stat, p_val = stats.ttest_1samp( data, popmean=30, alternative='greater' ) print(f"T-statistic: {t_stat:.2f}") print(f"P-value: {p_val:.4f}")
> P-value: 0.0034
Conclusion: p-value (0.0034) is less than 0.05. The data proves the shop takes longer than 30 mins!
6️⃣ Type I & Type II Errors (Visual)
This graph shows the trade-off between the two error types.
7️⃣ Decision Flowchart
Interview Checkpoint 🎯 (5)
1. What is a p-value in simple terms? ▼
2. When do you use a one-tailed test? ▼
3. What is the difference between Type I and Type II errors? ▼
Type II (β): False Negative (You failed to reject H₀, but H₀ was false).