The Z-Test › Computing P-Values from Z-Statistics

Michael BrenndoerferUpdated January 12, 20262 min read
Machine Learning from ScratchAll chapters
Part 2 of 9Hypothesis Testing
Chapter 14The Z-Test › Computing P-Values from Z-Statistics
Reading section 4 of 11 · Computing P-Values from Z-Statistics · 2 minSection 4 of 11 · 2 min

Book contents

Section 4 of 11 · 2 min read

The Z-Test › Computing P-Values from Z-StatisticsOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Once you have a z-statistic, you need to convert it to a p-value. The process depends on whether you're doing a one-sided or two-sided test.

Two-Sided Test

For a two-sided test (testing whether the mean differs from μ0\mu_0 in either direction):

p-value=2×P(Z>∣z∣)=2×Φ(−∣z∣)\text{p-value} = 2 \times P(Z > |z|) = 2 \times \Phi(-|z|)

where Φ\Phi is the standard normal CDF. We double the probability because we're interested in extreme values in both tails.

One-Sided Tests

For a right-tailed test (testing whether the mean is greater than μ0\mu_0):

p-value=P(Z>z)\text{p-value} = P(Z > z)

For a left-tailed test (testing whether the mean is less than μ0\mu_0):

p-value=P(Z<z)\text{p-value} = P(Z < z)
Out[5]:
Visualization
Standard normal with two-sided p-value regions shaded.
Two-sided p-value: For z = 2.1, we calculate the probability of being more than 2.1 standard deviations away from zero in either direction. The p-value is the total area in both tails.
Standard normal with one-sided p-value region shaded.
One-sided p-value (right-tailed): For the same z = 2.1, the one-sided p-value only includes the right tail. This makes one-sided tests more powerful in the hypothesized direction but unable to detect effects in the opposite direction.