Hypothesis Testing & Null vs Alternative
Frame H0/H1, choose tests, and decide with evidence rather than vibes.
In plain words
You start by assuming nothing changed, then check whether your data would be very surprising if that were true; if it would, you doubt the assumption.
Think of it like…
A courtroom: the defendant is presumed innocent (H₀) until the evidence is strong enough to convict (reject H₀). Not guilty doesn't mean innocent; it means the evidence wasn't strong enough beyond reasonable doubt (α).
Where you’ve seen it
A delivery company claims an average of 30 minutes. A sample of n = 40 deliveries has mean 32.5 minutes and standard deviation 8. H₀: μ = 30, H₁: μ ≠ 30. The standard error is 8 / √40 ≈ 1.265, so t = (32.5 − 30) / 1.265 ≈ 1.98 with 39 degrees of freedom, giving a two-sided p ≈ 0.055. At α = 0.05 the team fails to reject H₀: the data are suggestive but not conclusive. The matching 95% CI, 32.5 ± 2.56 = (29.9, 35.1), includes 30 and shows plausible averages up to 35 minutes, so they collect more data instead of declaring the claim true.
Words you’ll hear
- Null hypothesis H₀
- The default claim of no effect or no difference.
- Alternative H₁
- The claim that there is an effect: two-sided (≠) or one-sided (> or <).
- Test statistic
- A standardised measure of how far the data are from H₀.
- Significance level α
- The false-positive rate you accept; chosen before looking at the data.
Visual diagram
Theory & deep dive
Steps and choosing a test
The workflow: (1) state H₀ and H₁ in terms of parameters; (2) pick α and the sample size before collecting data; (3) choose a test that matches the data type and design; (4) compute the test statistic and p-value; (5) decide; (6) report the effect size and interval, not just the verdict. The test statistic has the form (estimate − null value) / standard error, so it counts how many standard errors the estimate lies from H₀.
Choose the test by the question and data: one mean against a target (one-sample t), two independent means (Welch t), before-and-after on the same units (paired t), two proportions (z-test for proportions), category association (chi-square), three or more means (ANOVA), and non-parametric alternatives (Mann-Whitney, Wilcoxon) when assumptions fail. Decide one- vs two-sided before looking: a two-sided test detects increases and decreases, and switching to one-sided after seeing the direction halves the p-value dishonestly.
stats.ttest_1samp(delivery_minutes, popmean=30) returns the t statistic and two-sided p-value; use alternative="greater" only if the one-sided hypothesis was fixed in advance.
Interpreting outcomes and common mistakes
If p ≤ α you reject H₀: the data would be unusual if H₀ were true. If p > α you fail to reject: the data are compatible with H₀, but also with many other values (the confidence interval shows which). "Not significant" can mean there's no effect or that the sample was too small to detect one (low power). Statistical significance is not practical significance: with huge samples trivial differences become significant, and with small ones large effects may not.
Frequent mistakes: p-hacking (trying many tests or subsets and reporting the significant one), choosing hypotheses after seeing the data, ignoring multiple comparisons, using the wrong test for dependent data (treating before/after measurements as independent groups), stopping an experiment when significance appears, and treating α = 0.05 as a law of nature rather than a convention to adapt to the cost of errors. Document the plan, report all tests run, and prefer intervals and effect sizes alongside p-values.
"Mean delivery time 32.5 min (95% CI 29.9–35.1, n = 40) vs the 30-min target; t(39) = 1.98, p = 0.055. We can't rule out the target but can't rule out up to 5 minutes over it; recommend collecting 150 more deliveries."
How it works, step by step
Step 1 of 41. State hypotheses and α
Write H₀ and H₁ in terms of parameters, choose one- or two-sided, and fix α before looking.
- Before
- data
When to use it & trade-offs
What it is
Hypothesis testing asks whether data are consistent with a default claim. The null hypothesis H₀ is the "nothing special" statement (no difference, no effect, the claim is true); the alternative H₁ is what you're looking for (a difference, an effect). You compute a test statistic (such as a t or z value) that measures how far the data are from H₀ in standard-error units, find the probability of a result at least that extreme if H₀ were true (the p-value), and compare with a pre-chosen significance level α (often 0.05) to decide: reject H₀ or fail to reject it. Failing to reject is not proof that H₀ is true.
Why it matters: Teams constantly ask "is this difference real or noise?": did the redesign change conversion, is delivery time really above target, do two groups differ? Hypothesis tests give a disciplined, repeatable answer and expose how much evidence you have. Their misuse (choosing the test after seeing data, treating "not significant" as "no effect") is also the source of many false findings, so the framing matters.
When to reach for it
- Checking performance claims against targets
- Comparing groups in experiments and observational data
- Deciding whether more data is needed
When to avoid or be careful
- Choosing hypotheses or tails after seeing the data
- Reading "not significant" as "no effect"
- Running many tests and reporting only the significant one
Choosing a test
Strengths: Robust for moderate n; standard.
Watch out: Assumes roughly normal means or large n.
Strengths: Direct for binary and count data.
Watch out: Needs adequate expected counts.
Strengths: Few assumptions.
Watch out: Less powerful if parametric assumptions hold.
Interview signals & numbers to know
When this topic comes up
- “Is the difference real or noise?”
- “What's the null hypothesis?”
- “One-sided or two-sided test?”
- p-hacking
- Test selection
Benchmarks & rules of thumb
- 0.05
- the conventional α
- t ≈ 1.98 · p ≈ 0.055
- the delivery-time example
- two-sided
- default tail choice
Common mistakes & follow-ups
Common interview mistakes
- Switching to a one-sided test after seeing which direction the data went.
- Reporting "no difference" when the sample was too small to detect one.
- Treating before-and-after measures of the same users as independent samples.
Likely interviewer follow-ups
- What do "reject" and "fail to reject" mean?
- How do you choose between a one-sided and a two-sided test?
- Why isn't p > 0.05 evidence that there's no effect?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Hypothesis Testing & Null vs Alternative with data science interview Q&A and hands-on practice.