Module 7 · Statistics: Describing and Deciding · Lesson 25 of 51
Hypothesis tests: is the difference real?
Null and alternative hypotheses, p-values, significance level, type I and II errors, power, the t-test and chi-square test, and statistical versus practical significance.
In this lesson · about 45 minutes
- State a null and alternative hypothesis for a business question
- Run and interpret a t-test and a chi-square test with SciPy
- Explain p-values, errors and power without the common mistakes
The steps
- Hypotheses. H₀: weekend and weekday average sales at Campus are equal. H₁: they differ.
- Significance level α, chosen in advance: usually 0.05.
- Test statistic and p-value from the data.
- Decide: if p < α, reject H₀ ("statistically significant"); otherwise "not enough evidence".
- Report the size of the effect with a confidence interval, not just the p-value.
Which test?
| Question | Test | SciPy |
|---|---|---|
| Two group means differ? | Welch's t-test | stats.ttest_ind(a, b, equal_var=False) |
| Same units measured twice (before/after)? | Paired t-test | stats.ttest_rel(before, after) |
| Two categorical variables related? | Chi-square test | stats.chi2_contingency(pd.crosstab(a, b)) |
| Two conversion rates differ? | Two-proportion z-test | Module 9 |
| Skewed data, small samples? | Mann–Whitney U | stats.mannwhitneyu(a, b) |
Errors and power
- Type I error (false positive): rejecting H₀ when it's true. Its rate is α.
- Type II error (false negative): missing a real effect. Its rate is β.
- Power = 1 − β: the chance of detecting a real effect of a given size. Bigger samples and bigger effects mean more power. 80% is the usual target.
What a p-value is not
It is not the probability that H₀ is true, and not the size or importance of the effect. With huge samples, trivial differences become "significant": a 3-cent difference in average order can have p < 0.001 and still not matter. Always ask: is it practically significant, big enough to change a decision?
t-test and chi-square on café data
Exercise
Do promotions lift sales?
For Airport (ap), compare sales on promo days (promo == 1) with non-promo days using Welch's t-test (equal_var=False). Set lift to the difference in means (promo − no promo, rounded to 1 decimal), p to the p-value, and significant to True if p < 0.05.
Code that runs before yours
import pandas as pd
import numpy as np
daily = pd.read_csv("kc_daily.csv", parse_dates=["date"])
from scipy import stats
ap = daily[daily["branch"] == "Airport"]Performance-based question (PBQ)
Name the error
In each case, the truth is known afterwards. Decide what kind of result the test gave.
Pick the outcome for each case.
- A new menu layout 'won' with p = 0.03, but a re-run shows it has no effect.
- A loyalty discount truly raised visits 8%, but a small test gave p = 0.31 and it was dropped.
- A button colour with no real effect gave p = 0.62; the team kept the old one.
- Free refills truly lifted sales; the test gave p = 0.002 and they were rolled out.
Flashcards
Module 7 flashcards
0 of 10 known
Say the answer out loud, flip the card, then be honest: cards you miss come back at the end.
Practice exam
Module 7 checkpoint
10 questions, 12 minutes.
- 10 questions · 12 minutes
- No feedback until you submit. Flag questions to come back to them.
- Aim for 85% or better before you move on. The real exam's 750 out of 900 is roughly 80–83%.
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.