Z-Test

Z-Test

Definition

Core Statement

A Z-Test is a statistical test used to determine whether a sample mean differs significantly from a population mean when the Population Standard Deviation (σ) is Known and/or the sample size is Large (n30).

Z=x¯μ0σ/n

Z-Test vs T-Test

Feature Z-Test T-Test
Standard Deviation Known (σ) Unknown (use sample s)
Sample Size Large (n30) Any (esp. Small n<30)
Distribution Standard Normal (Z) Student's t (fatter tails)
Practical Reality

In real life, we almost never know the true population σ. Therefore, T-tests are almost always preferred, even for large samples (where t approaches Z anyway). Z-tests are mostly taught for theoretical introduction.


One-Sample Z-Test Example

IQ Test

National Average IQ = 100, σ=15. (We know this from census).
A school samples 50 students with Mean IQ = 105.

Calculation:

SE=15/502.12Z=1051002.12=52.122.36

Decision:

  • Critical Z (95% confidence) = 1.96.
  • 2.36>1.96. Reject Null.
  • This school is significantly smarter than average.

Two-Proportion Z-Test

This is the most common real-world use case for Z-tests (A/B Testing).
Used for comparing two conversion rates (p1 vs p2).

Z=p^1p^2p^(1p^)(1n1+1n2)

Python Implementation

from statsmodels.stats.weightstats import ztest

# 1. One Sample Mean
# (Requires raw data, treats sample std as population std if n is large)
stat, p = ztest(data, value=100)

# 2. Proportions (A/B Test) - The more common use
from statsmodels.stats.proportion import proportions_ztest
count = [30, 45]     # Successes
nobs = [1000, 1000]  # Total observations
z_stat, p_val = proportions_ztest(count, nobs)