Quiz 2

Week 10.2: Z-test & p-value

637 words
3 min read
Python Week 1: the first filter for runtime behavior
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:μ=μ0H_0: \mu = \mu_0 vs H1:μμ0H_1: \mu \neq \mu_0 (or one-sided)
  • Known population variance σ2\sigma^2
  • Data is normal OR sample size is large (CLT) The test statistic:
Z=Xˉμ0σ/nN(0,1) under H0.Z = \frac{\bar{X} - \mu_0}{\sigma/\sqrt{n}} \sim \mathcal{N}(0,1) \text{ under } H_0.

2. The p-value Approach

Definition (p-value) The p-value is the probability, assuming H0H_0 is true, of observing a test statistic as extreme or more extreme than the one actually observed. Decision rule: Reject H0H_0 if p-value <α< \alpha. p-value for different alternatives:
Alternativep-value
H1:μμ0H_1: \mu \neq \mu_0$2 \cdot \mathbb{P}(Z \geq \
H1:μ>μ0H_1: \mu > \mu_0P(Zzobs)\mathbb{P}(Z \geq z_{\text{obs}})
H1:μ<μ0H_1: \mu < \mu_0P(Zzobs)\mathbb{P}(Z \leq z_{\text{obs}})

3. Worked Examples

Example 1: Two-Sided Z-test

A manufacturer claims their batteries last 100 hours on average. Test this at α=0.05\alpha = 0.05. Population SD is known to be 10 hours. Sample of 25 batteries gives xˉ=96\bar{x} = 96 hours. Step 1: H0:μ=100H_0: \mu = 100, H1:μ100H_1: \mu \neq 100. Step 2: α=0.05\alpha = 0.05. Step 3: Z=9610010/25=42=2Z = \frac{96 - 100}{10/\sqrt{25}} = \frac{-4}{2} = -2. Step 4 (critical value): z0.025=1.96z_{0.025} = 1.96. Reject if Z>1.96|Z| > 1.96. Step 5: Z=2>1.96|Z| = 2 > 1.96. Reject H0H_0. Step 6 (p-value): 2P(Z2)=20.0228=0.0456<0.052 \cdot \mathbb{P}(Z \geq 2) = 2 \cdot 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\bar{x} = 74. α=0.05\alpha = 0.05. Step 1: H0:μ=70H_0: \mu = 70, H1:μ>70H_1: \mu > 70. Step 2: α=0.05\alpha = 0.05. Step 3: Z=747015/36=42.5=1.6Z = \frac{74 - 70}{15/\sqrt{36}} = \frac{4}{2.5} = 1.6. Step 4: Critical value z0.05=1.645z_{0.05} = 1.645. Reject if Z>1.645Z > 1.645. Step 5: 1.6<1.6451.6 < 1.645. Fail to reject H0H_0. Step 6 (p-value): P(Z1.6)=0.0548>0.05\mathbb{P}(Z \geq 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=64n=64, xˉ=52\bar{x}=52, σ=8\sigma=8. Test H0:μ=50H_0: \mu=50 vs H1:μ50H_1: \mu \neq 50 at α=0.05\alpha=0.05.
Full Solution
Z=(5250)/(8/64)=2/(1)=2Z = (52-50)/(8/\sqrt{64}) = 2/(1) = 2. z0.025=1.96z_{0.025} = 1.96. Z=2>1.96|Z| = 2 > 1.96Reject H0H_0. p-value =2(0.0228)=0.0456<0.05= 2(0.0228) = 0.0456 < 0.05.

Q2 (Medium)

n=100n=100, xˉ=980\bar{x}=980, σ=50\sigma=50. Test H0:μ=1000H_0: \mu=1000 vs H1:μ<1000H_1: \mu < 1000 at α=0.01\alpha=0.01.
Full Solution
Z=(9801000)/(50/10)=20/5=4Z = (980-1000)/(50/10) = -20/5 = -4. z0.01=2.326z_{0.01} = -2.326. Z=4<2.326Z = -4 < -2.326Reject H0H_0. p-value =P(Z<4)0.00003<0.01= \mathbb{P}(Z < -4) \approx 0.00003 < 0.01.

Q3 (Hard)

A factory claims defect rate ≤ 1%. Sample of 500 items finds 8 defects. Test at α=0.05\alpha = 0.05.
Full Solution
H0:p=0.01H_0: p = 0.01, H1:p>0.01H_1: p > 0.01. p^=8/500=0.016\hat{p} = 8/500 = 0.016.
Z=0.0160.010.010.99/500=0.0060.0000198=0.0060.004451.35Z = \frac{0.016 - 0.01}{\sqrt{0.01 \cdot 0.99 / 500}} = \frac{0.006}{\sqrt{0.0000198}} = \frac{0.006}{0.00445} \approx 1.35.
z0.05=1.645z_{0.05} = 1.645. 1.35<1.6451.35 < 1.645Fail to reject H0H_0. Insufficient evidence that defect rate exceeds 1%.

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.