One-Sample Z-Test
Hypothesis Testing
The Classic Test When σ is Known
The one-sample z-test compares a sample mean to a hypothesized population mean when the population standard deviation is known. It is the foundation for understanding all parametric hypothesis tests.
- Manufacturing — Testing whether production meets specified standards with known process variability
- Benchmarking — Comparing performance against established population parameters
- Regulatory Compliance — Verifying products meet labeled specifications
The z-test is the simplest parametric test — master it first.
What You'll Learn
- 1Recognise the few situations where a population standard deviation is legitimately known
- 2Compute the z-statistic, its p-value, and the matching confidence interval by hand
- 3Explain the exact duality between a two-sided test and a confidence interval
- 4Decide when a z-test is appropriate and when the t-test must replace it
The one-sample z-test tests whether a population mean equals a hypothesized value when the population standard deviation (σ) is known and the sample is large (n ≥ 30).
The statistic has a plain-language reading: it counts standard errors between the observed mean and the value claimed by the null. The standard error shrinks with the square root of the sample size, so the same raw gap becomes more convincing as evidence the more observations support it.
When σ Is Genuinely Known
In most research the population standard deviation is unknown and the z-test is a textbook artefact — which is exactly why the t-test exists. A handful of situations make σ legitimate, and they are worth naming because they determine whether the test is appropriate. Published normative scales fix their parameters: IQ tests are defined to have σ = 15, standardized exam score distributions are published by the testing body, and manufacturing processes under statistical control have a documented long-run standard deviation from years of production records. A benchmark target quoted with its own tolerance band supplies σ directly.
The distinction is not cosmetic. Using the sample standard deviation in place of makes the reference distribution slightly wider than the normal, because itself fluctuates from sample to sample; that extra width is precisely what Student's t distribution captures. For the difference is negligible, for it is visible in the tails, and for it changes decisions near the threshold.
Assumptions
Independence is the assumption most often violated in practice. A sample of 200 measurements taken from 20 machines with 10 readings each does not contain 200 independent observations, and treating it as such understates the standard error. When the sampling is clustered, the effective sample size is closer to the number of clusters than the number of rows.
Step-by-Step Procedure
A Worked Example by Hand
Suppose the national mean on a certified test is with a published , and a school samples students whose mean is . The standard error is , so
Two standard errors above the null is already unusual, so the two-sided p-value is , comfortably below 0.05. The 95 percent confidence interval is , giving 101.24 to 109.56. The interval excludes 100 exactly as the test rejected, which is not a coincidence but the duality described in the next section.
Two further quantities belong beside the p-value. The standardised effect is small to moderate, and the power of this design at that effect is about 72 percent. Raising power to 80 percent needs roughly observations, a calculation worth doing before collecting data rather than after the result arrives.
Confidence Intervals and the Duality
A two-sided test at level α rejects precisely when falls outside the confidence interval for . The two procedures are the same inversion viewed from different sides: the interval collects every null value that would not be rejected, and the test checks whether your particular candidate is among them. This equivalence has a practical payoff. Whenever a p-value sits just above 0.05, the corresponding interval will just include the null, and reporting the interval shows the reader how close the call really was instead of hiding it behind a binary label.
| Confidence level | Two-sided α | Critical value z* | One-sided α = 0.05 critical |
|---|---|---|---|
| 90% | 0.10 | 1.645 | 1.645 |
| 95% | 0.05 | 1.960 | 1.645 |
| 99% | 0.01 | 2.576 | 2.326 |
Critical Region Visualization
x = np.linspace(-4, 4, 1000)
y = stats.norm.pdf(x)
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(x, y, 'b-', linewidth=2)
# Rejection regions (two-tailed, α=0.05)
ax.fill_between(x, y, where=x <= -z_crit, alpha=0.4, color='red', label=f'Reject H₀ (each α/2={alpha/2})')
ax.fill_between(x, y, where=x >= z_crit, alpha=0.4, color='red')
ax.fill_between(x, y, where=(-z_crit <= x) & (x <= z_crit), alpha=0.2, color='blue', label='Fail to reject H₀')
ax.axvline(z, color='green', linewidth=2, linestyle='--', label=f'Observed z = {z:.3f}')
ax.axvline(-z_crit, color='black', linewidth=1.5, linestyle=':', label=f'z* = ±{z_crit:.3f}')
ax.axvline(z_crit, color='black', linewidth=1.5, linestyle=':')
ax.set_title(f'One-Sample Z-Test (Two-Tailed, α={alpha})')
ax.set_xlabel('z')
ax.set_ylabel('Density')
ax.legend()
plt.tight_layout()
plt.savefig('z_test.png', dpi=150)
plt.show()
The shaded tails hold 2.5 percent of the area each. The observed statistic lands in one of them only when the data are far enough from the null that chance alone would produce something that extreme less than one time in twenty.
One-Tailed Tests
The direction of the alternative must be fixed before the data are seen. A one-sided test costs half the critical threshold — 1.645 instead of 1.96 — and that saving is only honest if a result in the opposite direction would have been reported as a non-finding rather than reanalysed as significant. Splitting α across several planned one-sided comparisons reintroduces the multiple testing problem covered elsewhere in this course.
Z-Test for a Proportion
The same name covers a different quantity. When the outcome is binary, the parameter of interest is a proportion rather than a mean, and under the null the sampling distribution is approximated by a normal with standard error :
This version needs no appeal to the central limit theorem about the underlying data, only that and both exceed about 10. It underpins quality-control checks of defect rates and A/B test comparisons of conversion, and it is far more common in applied work than the mean-based version.
Common Mistakes
Substituting the sample standard deviation into the z formula and calling it a z-test
Fix: If you estimated σ from the data, the reference distribution is t with n − 1 degrees of freedom. Use the t-test, or acknowledge that for large n the two agree to three decimals.
Choosing a one-sided alternative after seeing which direction is significant
Fix: Pre-specify the direction. A two-sided test applied to data that only look promising in one direction is the standard defence against inflated significance.
Reporting the p-value without the effect size or the confidence interval
Fix: Give d = (x̄ − μ₀)/σ and the interval for μ. A significant z with a tiny effect describes a real but negligible difference.
Best Practices
- Compute the required sample size from the smallest effect worth detecting before collecting data
- Report z, the p-value, the confidence interval for the mean, and Cohen's d together
- Use the confidence interval to show how close borderline decisions actually are
Key Takeaways
- The z-statistic counts standard errors between the sample mean and the null value: z = (x̄ − μ₀)/(σ/√n)
- |z| beyond 1.96 rejects at α = 0.05 two-sided; 1.645 does so one-sided
- A two-sided test rejects exactly when the matching confidence interval excludes μ₀ — they are the same procedure
- Known σ is rare; when σ is estimated from the data the correct reference distribution is Student's t
Frequently Asked Questions
Why does anyone still teach the z-test if σ is almost never known?
Because it isolates the logic of hypothesis testing from the complication of estimating variance. Every quantity — the standard error, the critical value, the p-value, the confidence interval — appears in its simplest form, and the t-test is then introduced as the same procedure with an uncertainty correction for the estimated spread.
Does the central limit theorem make the z-test valid for any sample size?
No. The theorem guarantees that the sample mean becomes approximately normal as grows, so a non-normal population is fine at or more. It says nothing about small samples from skewed or heavy-tailed populations, where the z-test can badly misstate the tail probability.
What is the difference between the mean-based and proportion-based z-test?
The mean version compares to using and needs σ from an external source. The proportion version compares to using , where the null itself fixes the standard error, so no external parameter is required beyond the claimed proportion.
Interview Questions
Q1: When is a z-test the correct test?
When the population standard deviation is known independently of the sample, the observations are independent, and either the population is normal or the sample is large enough for the central limit theorem. Typical real cases are normative scales such as IQ with σ = 15 and processes with documented long-run variability.
Q2: How is the confidence interval related to the hypothesis test?
They are inversions of each other. A two-sided test at α rejects μ₀ exactly when μ₀ lies outside the (1 − α) confidence interval, so the interval shows both the decision and the precision behind it.
Q3: What are the critical values you should memorise?
1.96 for a two-sided 5 percent test, 1.645 for one-sided 5 percent or two-sided 10 percent, and 2.576 for a two-sided 1 percent test.
Q4: A z-test returns p = 0.04. What else belongs in the report?
The sample mean, σ, n, the z-statistic, the 95 percent confidence interval for the mean, and the standardised effect d = (x̄ − μ₀)/σ, so a reader can judge whether the statistically significant difference is also practically meaningful.