Hypothesis Testing and p-values

Using significance tests to judge whether an observed difference is likely real, and avoiding the common misreadings.

Intermediate · about 6 hours · difficulty 3/5

Learn first: Estimation and Confidence Intervals

Hypothesis testing asks: if there were really no difference, how surprising would our data be?

The mechanics

  1. State a null hypothesis (no difference) and an alternative.
  2. Choose a significance level, often 0.05.
  3. Compute a test statistic and its p-value: the probability of seeing a result at least this extreme if the null were true.
  4. If p is below the threshold, reject the null; otherwise, you failed to find evidence (which is not proof of no effect).

Choosing a test

  • Compare two means: t-test (Welch's version by default).
  • Compare two proportions: two-proportion z-test or chi-square test.
  • Relationship between two categorical variables: chi-square test of independence.
  • Skewed data, small samples: Mann-Whitney U or bootstrap.
  • More than two groups: ANOVA, then pairwise comparisons.

Errors and power

  • Type I error: false positive. Type II error: missed a real effect.
  • Power is the chance of detecting an effect of a given size; it depends on sample size and noise.
  • Practical significance matters more than statistical significance: a 0.01% lift can be "significant" with millions of rows yet worthless.

Pitfalls: testing many metrics or segments and reporting the one that hit p < 0.05 (multiple comparisons), and reading p as "probability the null is true". Move on when you can pick a test for a scenario and explain its result to a non-technical colleague in two sentences.

Key concepts

  • Null and alternative hypotheses
  • p-values and significance levels
  • t-tests
  • Chi-square and proportion tests
  • Non-parametric tests
  • Type I and II errors, power
  • Multiple comparisons
  • Practical vs statistical significance
  • ANOVA

Mini project

Using the Kaggle 'Students Performance in Exams' dataset, test whether test-preparation course completion is associated with higher maths scores, and report effect size alongside the p-value.

Check yourself

A p-value of 0.03: what does it tell you, and what does it NOT tell you?

Free resources