P-values and Hypothesis Test Setup › Setting Up a Hypothesis Test
Machine Learning from ScratchAll chapters 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 () 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 ( or ) is what we're trying to establish. It contradicts the null and represents the research claim.
Example 1: Drug efficacy
- : The drug has no effect on blood pressure (mean change = 0)
- : The drug affects blood pressure (mean change ≠ 0)
Example 2: A/B test
- : The new design has the same conversion rate as the old (rate_new = rate_old)
- : The new design has a different conversion rate (rate_new ≠ rate_old)
Example 3: Quality control
- : The machine is calibrated correctly (mean weight = 50g)
- : The machine is miscalibrated (mean weight ≠ 50g)
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:
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:
- (or )
- (right-tailed)
Or:
- (or )
- (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).


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.