Monday , November 30 2026
What p-values mean, computed exactly and by simulation, the 0.05 threshold, statistical vs practical significance and common mistakes.

P-Values Explained Simply (with Python Simulation)

Updated: 29 November 2026Level: IntermediateReading time: about 8 minutesSciPy · tested

A p-value is the probability of seeing results at least as extreme as yours if the null hypothesis were true. It is the most used – and most misunderstood – number in statistics.

What You Will Learn

  • What a p-value really means
  • Compute one exactly and by simulation
  • The 0.05 threshold
  • Statistical vs practical significance
  • Common misinterpretations

Prerequisites

Hypothesis Testing.

Example: Is the Coin Fair?

You toss a coin 100 times and get 62 heads. H₀: the coin is fair (p = 0.5).

Example
from scipy import stats
res = stats.binomtest(62, 100, p=0.5)
print(round(res.pvalue, 4))
Output
0.021
Example
import numpy as np
rng = np.random.default_rng(7)
sims = rng.binomial(100, 0.5, 100_000)                 # 100,000 fair-coin experiments
print(round(np.mean(np.abs(sims - 50) >= 12), 4))      # as extreme as 62 (or 38)
Output
0.0209

Explanation: Both methods agree: only about 2% of fair-coin experiments give a result as far from 50 as 62 heads. Since 0.021 < 0.05, we reject H₀ at the 5% level. The simulation shows what a p-value literally is.

Reading p-values

p-value Usual reading
< 0.01 Strong evidence against H₀
0.01 – 0.05 Evidence against H₀ (significant at 5%)
> 0.05 Not enough evidence to reject H₀ – not proof that H₀ is true

Significant Is Not the Same as Important

Example
a = rng.normal(100, 15, 200_000)
b = rng.normal(100.3, 15, 200_000)
t, p = stats.ttest_ind(a, b)
print(f"{p:.2e}", round(b.mean() - a.mean(), 2))
Output
1.52e-09 0.29

Explanation: With huge samples even a tiny difference (0.29 points on a scale of 100) becomes “highly significant”. Always report the effect size and a confidence interval, and ask whether the difference matters in practice.

Common Mistakes

  • ❌ “p = 0.03 means a 3% chance H₀ is true.” – It is the chance of the data given H₀, not of H₀ given the data.
  • ❌ “p > 0.05 proves no effect.” – You may just have too little data.
  • ❌ Testing many things and reporting only p < 0.05 (p-hacking). Correct for multiple tests (e.g. Bonferroni).
  • ❌ Treating 0.049 and 0.051 as completely different results.

Series

Maths & Statistics series: Introduction to Statistics · Descriptive Statistics · Probability · Bayes’ Theorem · Distributions · Inferential Statistics · Hypothesis Testing · P-Values · Correlation & Covariance · Linear Algebra · Eigenvalues · Calculus · Optimization · Interview Questions

Interview Questions

Q: Define a p-value.
The probability, assuming the null hypothesis is true, of observing data at least as extreme as what was observed.

Q: Why can large samples give tiny p-values for trivial effects?
Standard errors shrink with n, so even very small differences become statistically detectable.

Practice Exercises

  1. Find the p-value for 58 heads in 100 tosses.
  2. Simulate the p-value for rolling six sixes in 20 rolls of a fair die.

Summary

A p-value measures how surprising the data are under H₀. Below 0.05 is conventionally significant, but always consider effect size, sample size and multiple testing.

Next: Correlation and Covariance

About Machine Learning

Check Also

Bayes’ Theorem Explained with a Spam Filter Example

Bayes theorem with prior, likelihood and posterior, a tested spam-filter example, sequential updating, the base-rate fallacy and Naive Bayes.