Week 10.2: Z-test & p-value
637 words
3 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Week 10.2: Z-test & p-value > **Prerequisites:** Hypothesis Testing Intro ([Week 10.1: Introduction to Hypothesis Testing](/notes/01-foundation-bsma1004-stats-2-week10-25-hypothesis-testing-intro)), CLT ([Week 5.2: Law of Large Numbers & Central Limit Theorem](/notes/01-foundation-bsma1004-stats-2-week05-16-lln-cl...

Week 10.2: Z-test & p-value
Prerequisites: Hypothesis Testing Intro (Week 10.1: Introduction to Hypothesis Testing), CLT (Week 5.2: Law of Large Numbers & Central Limit Theorem) Cross-links: BSMA3012 (Linear Stat Models) — Wald tests Core question: How do we test hypotheses about the mean when variance is known?
1. Intuition: The Simplest Test
The Z-test is used when:
- Testing H0:μ=μ0 vs H1:μ=μ0 (or one-sided)
- Known population variance σ2
- Data is normal OR sample size is large (CLT) The test statistic:
2. The p-value Approach
Definition (p-value) The p-value is the probability, assuming H0 is true, of observing a test statistic as extreme or more extreme than the one actually observed. Decision rule: Reject H0 if p-value <α. p-value for different alternatives:
| Alternative | p-value |
|---|---|
| H1:μ=μ0 | $2 \cdot \mathbb{P}(Z \geq \ |
| H1:μ>μ0 | P(Z≥zobs) |
| H1:μ<μ0 | P(Z≤zobs) |
3. Worked Examples
Example 1: Two-Sided Z-test
A manufacturer claims their batteries last 100 hours on average. Test this at α=0.05. Population SD is known to be 10 hours. Sample of 25 batteries gives xˉ=96 hours.
Step 1: H0:μ=100, H1:μ=100. Step 2: α=0.05. Step 3: Z=10/2596−100=2−4=−2. Step 4 (critical value): z0.025=1.96. Reject if ∣Z∣>1.96. Step 5: ∣Z∣=2>1.96. Reject H0. Step 6 (p-value): 2⋅P(Z≥2)=2⋅0.0228=0.0456<0.05.
Conclusion: There is sufficient evidence that the mean battery life differs from 100 hours.
Example 2: One-Sided Z-test
Test if student scores have increased from last year's mean of 70. Known SD = 15. Sample of 36 students: xˉ=74. α=0.05.
Step 1: H0:μ=70, H1:μ>70. Step 2: α=0.05. Step 3: Z=15/3674−70=2.54=1.6. Step 4: Critical value z0.05=1.645. Reject if Z>1.645. Step 5: 1.6<1.645. Fail to reject H0. Step 6 (p-value): P(Z≥1.6)=0.0548>0.05.
Conclusion: Insufficient evidence that mean has increased.
4. Critical Values vs p-value
(Diagram)
Both approaches give the same decision.
5. Practice Questions
Q1 (Easy)
n=64, xˉ=52, σ=8. Test H0:μ=50 vs H1:μ=50 at α=0.05.
Full SolutionZ=(52−50)/(8/64)=2/(1)=2. z0.025=1.96. ∣Z∣=2>1.96 → Reject H0. p-value =2(0.0228)=0.0456<0.05.
Q2 (Medium)
n=100, xˉ=980, σ=50. Test H0:μ=1000 vs H1:μ<1000 at α=0.01.
Full SolutionZ=(980−1000)/(50/10)=−20/5=−4. z0.01=−2.326. Z=−4<−2.326 → Reject H0. p-value =P(Z<−4)≈0.00003<0.01.
Q3 (Hard)
A factory claims defect rate ≤ 1%. Sample of 500 items finds 8 defects. Test at α=0.05.
Full SolutionH0:p=0.01, H1:p>0.01. p^=8/500=0.016.Z=0.01⋅0.99/5000.016−0.01=0.00001980.006=0.004450.006≈1.35.z0.05=1.645. 1.35<1.645 → Fail to reject H0. Insufficient evidence that defect rate exceeds 1%.
Next topic: Week 11.1: t-test & Chi-Square Test — t-test and Chi-square test. Join Discord PreviousWeek 10.1: Introduction to Hypothesis TestingNextWeek 11.1: t-test & Chi-Square Test