Data Science Track · Lesson 8

Hypothesis Testing

The null hypothesis, p-values, t-tests — and the critical distinction between statistical significance and practical significance.

The Question Hypothesis Testing Answers

You observe that weekend delivery times average 28 minutes while weekday times average 22 minutes. Is that a real difference — or could it just be random variation in your sample? If you drew a different sample, might the weekday times be higher by chance?

Hypothesis testing is a formal procedure for answering: "Is the pattern I see in my data likely to be real, or likely to be noise?"

It doesn't prove anything. It quantifies how surprising your data would be if the effect you're looking for didn't actually exist.

The Null and Alternative Hypotheses

Every hypothesis test starts with two competing statements:

H₀ — The Null Hypothesis

The "boring" baseline: there is no effect, no difference, nothing interesting going on. Example: "Weekday and weekend delivery times are the same." We assume this is true until evidence says otherwise.

H₁ — The Alternative Hypothesis

What you actually suspect is true. Example: "Weekend delivery times are longer than weekday times." This is the claim you're trying to find evidence for.

The logic is deliberately conservative: you never directly "prove" H₁. Instead, you try to show that H₀ is so unlikely given your data that you're willing to reject it in favour of H₁.

Why start with the null? Science is built on falsification, not confirmation. It's easier (and more rigorous) to define what "no effect" looks like and then ask whether your data is consistent with it. If the data is wildly inconsistent with "no effect," you have evidence for an effect. This prevents wishful thinking from driving conclusions.

The p-Value

The p-value is the probability of observing data as extreme as yours (or more extreme) if the null hypothesis were actually true.

p = P(observing this result | H₀ is true)

A small p-value means: "If there really were no difference, seeing this data would be very unlikely — so maybe the null is wrong." A large p-value means: "Even if there's no real difference, you'd often see results like this just by chance."

What p-value does NOT mean p = 0.03 does NOT mean "there's a 97% chance the effect is real" or "there's a 3% chance this is due to chance." The p-value says nothing about probabilities of hypotheses being true. It's only a statement about data probability under H₀. This is one of the most persistent misconceptions in all of statistics.

The Significance Threshold (α)

Before running the test, you pick a threshold α (alpha) — typically 0.05. If p < α, you "reject the null hypothesis." The choice of 0.05 is a convention (Ronald Fisher suggested it in the 1920s), not a law of nature. For medical research, α = 0.01 is common. For exploratory data science, 0.05 or 0.10 is standard.

The Welch t-Test

When comparing the means of two groups, the standard tool is the t-test. The Welch t-test is a variant that doesn't assume the two groups have equal variance — making it more robust and the default choice for most real-world comparisons.

t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)

The numerator is the observed difference in means. The denominator is a measure of how much sampling variability you'd expect. A large t-statistic means the difference is large relative to the noise — unusual if H₀ were true.

When to use a t-test

Statistical vs. Practical Significance

This is the second most important lesson in hypothesis testing (after understanding the p-value correctly).

Statistical significance ≠ practical significance With a large enough sample, almost any difference becomes statistically significant. If you have 1 million observations, a 0.1-minute difference in delivery time will give p < 0.0001 — statistically "highly significant." But is a 6-second difference operationally meaningful? Almost certainly not. The p-value tells you the difference is real; it says nothing about whether it matters.

Effect size measures translate statistical results into practical terms:

Good practice Always report both the p-value AND the effect size (or at minimum the raw difference with a CI). The p-value answers "Is this real?" The effect size answers "Does this matter?"

Type I and Type II Errors

Type I Error (False Positive)

Rejecting H₀ when it's actually true. Concluding there's a difference when there isn't one. Probability = α. With α = 0.05, you'll falsely reject 1 in 20 true nulls by chance alone.

Type II Error (False Negative)

Failing to reject H₀ when it's actually false. Missing a real effect. Its probability (β) depends on sample size, effect size, and α. Power = 1 − β.

These errors trade off: lowering α (being stricter) reduces Type I errors but increases Type II errors. The right balance depends on the cost of each type of mistake in your specific context.

In the FoodHub Project

A Welch two-sample t-test compared delivery times for weekday vs. weekend orders. Result: t-statistic = −7.09, p-value ≈ 0.000000000 (essentially zero). Conclusion: reject H₀ — weekend delivery times are significantly longer. Effect size: weekends averaged ~6 minutes longer. Both statistically significant AND operationally meaningful — enough to warrant a business action like weekend staffing increases. See Chapter 9 — Hypothesis Testing →