P-values and Hypothesis Test Setup › Setting Up a Hypothesis Test

Michael BrenndoerferUpdated January 12, 20264 min read
Machine Learning from ScratchAll chapters
Part 2 of 9Hypothesis Testing
Chapter 12P-values and Hypothesis Test Setup › Setting Up a Hypothesis Test
Reading section 4 of 9 · Setting Up a Hypothesis Test · 4 minSection 4 of 9 · 4 min

Book contents

Section 4 of 9 · 4 min read

P-values and Hypothesis Test Setup › Setting Up a Hypothesis TestOne section · Sections in this chapter4 / 9 ↓
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

With p-values understood, let's examine the mechanics of conducting a test. Every hypothesis test has the same structure: formulate hypotheses, choose a test, collect data, compute a test statistic, and make a decision.

Null and Alternative Hypotheses

The null hypothesis (H0H_0) represents the skeptical position. It typically claims "nothing interesting is happening": no effect, no difference, no relationship. The null is what we assume true unless the data provide strong evidence otherwise.

The alternative hypothesis (H1H_1 or HaH_a) is what we're trying to establish. It contradicts the null and represents the research claim.

Example 1: Drug efficacy

  • H0H_0: The drug has no effect on blood pressure (mean change = 0)
  • H1H_1: The drug affects blood pressure (mean change ≠ 0)

Example 2: A/B test

  • H0H_0: The new design has the same conversion rate as the old (rate_new = rate_old)
  • H1H_1: The new design has a different conversion rate (rate_new ≠ rate_old)

Example 3: Quality control

  • H0H_0: The machine is calibrated correctly (mean weight = 50g)
  • H1H_1: The machine is miscalibrated (mean weight ≠ 50g)
The Asymmetry of Hypothesis Testing

We never "accept" the null hypothesis. We either reject it (if evidence is strong enough) or fail to reject it (if evidence is insufficient). Failing to reject doesn't prove the null is true. It just means we don't have enough evidence to claim otherwise. This asymmetry reflects the logic: we're testing whether the data are inconsistent with the null, not whether they prove it.

One-Sided vs Two-Sided Tests

The alternative hypothesis can be directional (one-sided) or non-directional (two-sided).

A two-sided test considers alternatives in both directions:

  • H0:μ=μ0H_0: \mu = \mu_0
  • H1:μ≠μ0H_1: \mu \neq \mu_0

Use this when deviations in either direction are scientifically meaningful. If you're testing whether a new drug affects blood pressure, you care whether it raises OR lowers it.

A one-sided test considers alternatives in only one direction:

  • H0:μ=μ0H_0: \mu = \mu_0 (or μ≤μ0\mu \leq \mu_0)
  • H1:μ>μ0H_1: \mu > \mu_0 (right-tailed)

Or:

  • H0:μ=μ0H_0: \mu = \mu_0 (or μ≥μ0\mu \geq \mu_0)
  • H1:μ<μ0H_1: \mu < \mu_0 (left-tailed)

Use this when only one direction matters. If you're testing whether a new treatment improves outcomes, you might not care if it makes things worse (that's a different problem).

Out[5]:
Visualization
Normal distribution with two-sided rejection regions shaded in both tails.
Two-sided test: The rejection region is split between both tails. We reject H0 if the test statistic is unusually large OR unusually small.
Normal distribution with one-sided rejection region shaded in right tail.
One-sided test (right-tailed): The entire rejection region is in the right tail. We reject H0 only if the test statistic is unusually large.

The tradeoff: One-sided tests have more power to detect effects in the hypothesized direction because the entire significance level is concentrated in one tail. But they completely miss effects in the opposite direction. If you use a right-tailed test and the true effect is negative, you'll never reject the null, no matter how strong the effect.

Rule of thumb: Unless you have a clear scientific reason to expect the effect in only one direction, use a two-sided test. It's more conservative and avoids interpretive problems.