Mathwords logoMathwords

Two-Sample z-Test — Definition, Formula & Example

A two-sample z-test is a hypothesis test that checks whether the difference between two sample means is large enough to suggest the two population means really differ. You can use it only when you know the standard deviation of each population.

Given independent random samples of sizes n1n_1 and n2n_2 from populations with known standard deviations σ1\sigma_1 and σ2\sigma_2, the two-sample z-test evaluates H0:μ1−μ2=Δ0H_0: \mu_1 - \mu_2 = \Delta_0 (usually Δ0=0\Delta_0 = 0). Under H0H_0, the test statistic below follows the standard normal distribution N(0,1)N(0, 1) exactly if both populations are normal, and approximately if both samples are large (commonly n1,n2≥30n_1, n_2 \geq 30). The p-value comes from this distribution.

Key Formula

z=(xˉ1−xˉ2)−Δ0σ12n1+σ22n2z = \frac{(\bar{x}_1 - \bar{x}_2) - \Delta_0}{\sqrt{\dfrac{\sigma_1^2}{n_1} + \dfrac{\sigma_2^2}{n_2}}}
Where:
  • xˉ1,xˉ2\bar{x}_1, \bar{x}_2 = Sample means of groups 1 and 2
  • Δ0\Delta_0 = Hypothesized difference μ1−μ2\mu_1 - \mu_2 under H0H_0, usually 0
  • σ1,σ2\sigma_1, \sigma_2 = Known population standard deviations
  • n1,n2n_1, n_2 = Sample sizes
  • σ12/n1+σ22/n2\sqrt{\sigma_1^2/n_1 + \sigma_2^2/n_2} = Standard error of xˉ1−xˉ2\bar{x}_1 - \bar{x}_2

Worked Example

Problem: Years of data show that exam scores have population standard deviation σ1=10\sigma_1 = 10 at School A and σ2=12\sigma_2 = 12 at School B. A random sample of 50 students from School A has mean score 78. A random sample of 72 students from School B has mean score 74. At α=0.05\alpha = 0.05, test H0:μ1−μ2=0H_0: \mu_1 - \mu_2 = 0 against Ha:μ1−μ2≠0H_a: \mu_1 - \mu_2 \neq 0.
Step 1: Compute the standard error of the difference in sample means.
SE=10250+12272=2+2=2SE = \sqrt{\frac{10^2}{50} + \frac{12^2}{72}} = \sqrt{2 + 2} = 2
Step 2: Compute the test statistic.
z=(78−74)−02=2z = \frac{(78 - 74) - 0}{2} = 2
Step 3: Find the two-sided p-value from the standard normal distribution and compare it with α\alpha.
p=2P(Z≥2)≈2(0.02275)≈0.0455<0.05p = 2P(Z \geq 2) \approx 2(0.02275) \approx 0.0455 < 0.05
Answer: With z=2z = 2 and p≈0.0455<0.05p \approx 0.0455 < 0.05, reject H0H_0. The data give convincing evidence that the mean exam scores at the two schools differ.

Why It Matters

On the AP Statistics exam, choosing the correct procedure is graded directly. Real data almost never come with known values of σ\sigma, so you will usually use a two-sample t-test for means. The z version shows where the t-test's structure comes from. Comparisons of two proportions use a separate procedure, the two-proportion z-test.

Common Mistakes

Mistake: Using a two-sample z-test when only the sample standard deviations s1s_1 and s2s_2 are given.
Correction: Replacing σ\sigma with ss adds extra variability, so the statistic no longer follows N(0,1)N(0,1). Use the two-sample t-test instead, which accounts for this through its degrees of freedom.

Related Terms