Hypothesis Testing
Statistics & ProbabilityWhere this fitsContinues from Confidence Intervals. Hypothesis testing is one of the most important topics in inferential statistics and a favorite in data-science and data-analyst interviews. This note covers the why, the core vocabulary, and the rejection-region approach. The follow-up, P-values and T-tests, covers the more refined p-value approach and specific tests.
Why hypothesis testing exists
We often have an idea (a hypothesis) and want to check whether the data supports it.
YouTube video style (hypothetical)Average view duration is 6 minutes. You think a new shooting style (standing in front of the screen) will increase it. You shoot one video and it runs 13 minutes. Can you conclude the new style works? No. A single result could be luck (a trending topic that day, etc.). You need many samples and a formal test.
Lays packet weightA packet claims 50 g. A consumer watchdog suspects it is not exactly 50 g. They weigh a random sample of packets and test the claim.
Hypothesis testing lets us make probabilistic statements about population parameters from sample data. It is used to compare treatments, compare group means/proportions, analyze relationships, check goodness of fit, and run A/B tests.
The two hypotheses
Every test starts with two competing statements.
| Hypothesis | Symbol | What it says |
|---|---|---|
| Null hypothesis | Nothing new is happening; the status quo holds. Usually contains an equality. | |
| Alternate hypothesis | or | The opposite of the null; the effect the researcher wants to demonstrate. |
They are mutually exclusive: exactly one will be supported at the end.
Rule of thumb for choosing the nullalways says “nothing changed”. You changed the video style but the average duration is still 6 minutes. You opened the chips packet but the weight is still exactly 50 g.
Writing them formallyYouTube: min, min. Lays: g, g.
What the whole test does
We collect evidence against the null hypothesis in the hope of rejecting it.
Failing to reject ≠ proving trueNot being able to reject does not prove is true. It only means we lacked enough evidence to reject it.
Courtroom analogy
- : the accused is innocent (“no crime”).
- : the accused is guilty.
- The lawyer (like the researcher) presents evidence to convince the judge of guilt.
- If the lawyer fails to bring enough evidence, it does not prove the accused is innocent, it just means guilt wasn’t established.
Significance level ()
The significance level is a threshold, chosen before testing. Common values are 0.05 (5%) and 0.01 (1%).
It is the probability of rejecting when is actually true (this is a Type I error, covered below). If , then in the long run about 5 out of 100 true nulls would be wrongly rejected.
Notemust be fixed in advance, otherwise you have no threshold against which to decide whether to reject the null.
The rejection-region approach (step by step)
This is the first, most basic technique. The general flow:
- Formulate and .
- Choose the significance level (e.g. 0.05).
- Check assumptions about the data (e.g. normality, known ) to pick the right test.
- Decide the test (Z-test if known and data normal; t-test if unknown; chi-square for categorical, etc.).
- Select the test statistic and compute it.
- Conduct the test: compare the statistic against the critical value(s) to see if it lands in the rejection region.
- Conclusion: reject , or fail to reject it.
Worked example: one-sample Z-test (rejection region)
Training programA car factory produces on average cars/day with . After a training program, a sample of employees shows a sample mean of . Did productivity increase? Use .
Step 1. , .
Step 2. .
Step 3. (CLT → normality holds), and is known → use a Z-test.
Step 5–6. Compute the Z statistic:
Because is , this is a one-tailed (right-tailed) test. Put all of in the right tail. The critical value is .
Step 7. , so the statistic lands in the rejection region. We reject : the training program significantly increased productivity.
| rejection region (α = 0.05)
| ┌───────
─────────┴─────────────────┤
0 1.645 3.28 ✗ (falls here → reject H0)
One-tailed vs two-tailed tests
The alternate hypothesis decides which one you use.
| contains | Test type | Rejection region |
|---|---|---|
| or (a direction) | one-tailed (one-sided) | all in one tail |
| (just “different”) | two-tailed (two-sided) | in each tail |

Lays packet (two-tailed), . With , put 0.025 in each tail, giving critical values . Compute . Since lies between and (the no-rejection region), we fail to reject . There isn’t enough evidence that the weight differs from 50 g.
Type I and Type II errors
Because we decide from a sample, we can be wrong in two ways.
| is true | is false | |
|---|---|---|
| Reject | Type I error (false positive), prob | correct |
| Fail to reject | correct | Type II error (false negative), prob |
- Type I error (false positive): rejecting a true null. Example: the innocent person gets convicted. Its probability is .
- Type II error (false negative): failing to reject a false null. Example: the guilty person walks free. Its probability is .
- Power of the test .
The trade-off
Lowering shrinks the rejection region and grows the “fail to reject” region. That reduces Type I errors but increases Type II errors, and vice versa. You cannot minimize both at once; you strike a balance (which is why 0.05 is a common default).

How shapes the regions (intuition)
Picture a two-tailed test. The white middle region is “fail to reject”; the shaded tails are “reject”.
- Decrease (e.g. 0.05 → 0.01): the white region grows, so it’s harder to reject (fewer Type I errors).
- Increase : the white region shrinks, so even a true is more likely to be (wrongly) rejected.
The value from the Z/t table that separates the regions is the critical value; the shaded area is the rejection region.
The weakness of the rejection-region approach
This approach gives a binary answer (reject or not) but ignores how strong the evidence is.
ExampleIf the critical value is 1.96 and your statistic is 1.97, you reject; if it’s 1.95, you don’t, even though the two are almost identical. And a statistic of 15 (very strong evidence) is treated the same as one of 2 (borderline). The rejection-region approach can’t express this difference in strength.
The fix is the p-value approach, covered in P-values and T-tests.
Where hypothesis testing is used in ML
| Use case | How |
|---|---|
| Model comparison | test whether one model’s accuracy is significantly better across CV folds (paired t-test) |
| Feature selection | test whether a feature is significantly related to the target (t-test, chi-square, ANOVA) |
| Hyperparameter tuning | compare performance across parameter settings |
| Checking model assumptions | test linearity/normality of residuals (e.g. for linear regression) |
Libraries like scikit-learn use these tests internally; understanding them helps you use those tools wisely.
Summary
- Hypothesis testing checks whether data supports an idea about a population parameter.
- (null) says “nothing new”; (alternate) is the effect we want to show; the goal is to gather evidence against .
- Failing to reject does not prove it true.
- (significance level, often 0.05) is the pre-chosen probability of a Type I error.
- The rejection-region approach: compute a test statistic and check if it falls beyond the critical value.
- One-tailed tests (direction in ) put in one tail; two-tailed tests () split it into both tails.
- Type I = false positive (prob ); Type II = false negative (prob ); they trade off; power .
- The rejection-region approach ignores the strength of evidence, which the p-value approach fixes.