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

  1. Hypotheses. H₀: weekend and weekday average sales at Campus are equal. H₁: they differ.
  2. Significance level α, chosen in advance: usually 0.05.
  3. Test statistic and p-value from the data.
  4. Decide: if p < α, reject H₀ ("statistically significant"); otherwise "not enough evidence".
  5. Report the size of the effect with a confidence interval, not just the p-value.

Which test?

QuestionTestSciPy
Two group means differ?Welch's t-teststats.ttest_ind(a, b, equal_var=False)
Same units measured twice (before/after)?Paired t-teststats.ttest_rel(before, after)
Two categorical variables related?Chi-square teststats.chi2_contingency(pd.crosstab(a, b))
Two conversion rates differ?Two-proportion z-testModule 9
Skewed data, small samples?Mann–Whitney Ustats.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.
0 of 4 answered

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.

10 left in the deck

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

Tip: solve each exercise first. Press Check to test your code.

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.