Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Descriptive and inferential statistics

Hypothesis Testing: p-values, Type I/II Errors, Power

A hypothesis test decides whether data are surprising enough to reject a default claim (the null). You will build tests from test statistics, compute and correctly interpret p-values, balance false alarms (type I, α) against misses (type II, β), compute power and the sample size needed to detect an effect, run exact binomial tests, learn the Neyman–Pearson lemma and likelihood-ratio tests, and apply the χ² NEES test that checks whether a Kalman filter's uncertainty is honest.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Innocent until proven guilty

A new grasp policy is claimed to beat the old one. A test starts by assuming nothing changed (the null hypothesis). Then it asks: if nothing changed, how surprising are the results we got? If they’d be very surprising, say a 1-in-50 fluke, we reject “nothing changed”.

A test can go wrong in two ways:

  • False alarm (type I): declaring an improvement that isn’t real.
  • Miss (type II): failing to notice a real improvement.

Tests are designed to keep false alarms rare, and enough data keeps misses rare too.

False alarms vs misses: the two errors of a test
H₀: μ = 0H₁: μ = δ
critical value x̄ > 0.658 · type I error (false alarm) 5.0% · type II error (miss) 65.4% · power 34.6% · n for 80% power: 99
Uncoloured curve: the sampling distribution of x̄ if there is no effect. Blue: if the effect is δ. Reject H₀ to the right of the green line. Orange area = α (rejecting a true H₀). Blue area = β (missing a real effect). Lowering α moves the line right and costs power. Only more data or less noise separates the curves, since the SE is σ/√n.
Why engineers care

Is the new controller really better? Is this sensor faulty, or was that a fluke? Is the filter’s uncertainty honest? Hypothesis tests turn these into decisions with known error rates, and power analysis tells you how many trials to run before you start.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A test begins by assuming…
  2. 2. Declaring an effect that isn't real is a…
  3. 3. More data generally reduces…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Ingredients of a test

  1. A null hypothesis H0H_0 (e.g. μ=μ0\mu = \mu_0) and an alternative H1H_1 (e.g. μ>μ0\mu > \mu_0, or ≠\ne).
  2. A test statistic with known distribution under H0H_0, e.g. z=xˉ−μ0σ/nz = \frac{\bar x - \mu_0}{\sigma/\sqrt n}.
  3. A level α\alpha (often 0.05). Reject when the statistic lands in the most extreme α\alpha of its null distribution.

The p-value

The p-value is the probability, if H0H_0 were true, of a statistic at least as extreme as the one observed. Reject when p≤αp\le\alpha. For example, z=2z = 2 gives two-sided p=0.046p = 0.046.

A p-value is not:

  • the probability that H0H_0 is true;
  • the probability the result is a fluke;
  • the size or importance of the effect.

A tiny effect with huge nn can have a tiny pp.

The two errors

H0H_0 true H0H_0 false
Reject type I error (rate α\alpha) correct (power 1−β1 - \beta)
Don’t reject correct type II error (rate β\beta)
📝 Quick check (Level 1)
0/3 answered
  1. 1. z = 1.96 gives two-sided p ≈
  2. 2. p = 0.03 means…
  3. 3. Power is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Power and sample size

For a one-sided z test of μ0\mu_0 against μ0+δ\mu_0 + \delta,

power=Φ(δnσ−z1−α),n=((z1−α+z1−β)σδ)2\text{power} = \Phi\Big(\frac{\delta\sqrt n}\sigma - z_{1-\alpha}\Big), \qquad n = \Big(\frac{(z_{1-\alpha} + z_{1-\beta})\sigma}\delta\Big)^2

For a two-sided test, replace z1−αz_{1-\alpha} by z1−α/2z_{1-\alpha/2}. Halving the detectable effect needs 4× the data. Plan the sample size before collecting data. An under-powered study usually finds nothing, and when it does find something, it exaggerates the effect (the “winner’s curse”).

Exact tests for counts

Did a policy that succeeded 46 times out of 50 beat a known 80% rate? Under H0:p=0.8H_0: p = 0.8, P(X≥46)=∑j≥46(50j)0.8j0.250−j≈0.018P(X\ge46) = \sum_{j\ge46}\binom{50}j0.8^j0.2^{50-j}\approx0.018. Exact binomial tests avoid normal approximations for small samples.

Statistical vs practical significance

Always report the effect size and its confidence interval (A5.1-6), not just “p < 0.05”. A 0.1% throughput gain can be “significant” with a million trials and still be worthless. A 20% gain can be “not significant” with 5 trials and still be worth a bigger test.

🐍 Exercise 1: p-values, type I error and power
Implement the z-test p-value, the one-sided power formula and the sample size for 80% power. Check by simulation that the test rejects 5% of the time under H0, and that the empirical power matches the formula for several effect sizes.
📝 Quick check (Level 2)
0/3 answered
  1. 1. To detect half the effect with the same power you need…
  2. 2. Lowering α from 0.05 to 0.01 (same n) makes power…
  3. 3. Under H₀, p-values are distributed…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

The Neyman–Pearson lemma

For simple hypotheses H0:f0H_0: f_0 vs H1:f1H_1: f_1, the most powerful level-α\alpha test rejects when the likelihood ratio Λ=f1(x)/f0(x)\Lambda = f_1(x)/f_0(x) exceeds a threshold kk chosen so that P0(Λ>k)=αP_0(\Lambda > k) = \alpha.

Proof sketch: let ϕ\phi be the LR test and ψ\psi any other level-α\alpha test. Then (ϕ−ψ)(f1−kf0)≥0(\phi - \psi)(f_1 - kf_0)\ge0 pointwise. Integrate: power(ϕ)−power(ψ)≥k(α−αψ)≥0\text{power}(\phi) - \text{power}(\psi)\ge k(\alpha - \alpha_\psi)\ge0. ∎

For normal means, the LR is monotone in xˉ\bar x, so the z-test is most powerful. That makes it uniformly most powerful against all μ>μ0\mu > \mu_0.

Generalized likelihood-ratio tests

For composite hypotheses, use λ=sup⁡H0Lsup⁡L\lambda = \frac{\sup_{H_0}L}{\sup L}. Wilks’ theorem: −2log⁡λ→dχk2-2\log\lambda\xrightarrow d\chi^2_k, where kk is the number of constrained parameters (A5.1-4). The t-test, the χ² tests and model-comparison tests are all GLRTs.

p-values are uniform under H₀

If the statistic TT is continuous with null CDF FF, then p=1−F(T)p = 1 - F(T) and P(p≤u)=P(F(T)≥1−u)=uP(p\le u) = P(F(T)\ge1 - u) = u (the probability integral transform, A4.3-2). So rejecting at p≤αp\le\alpha has exactly rate α\alpha under the null. Every extra look at the data adds another chance at α\alpha, which is why peeking inflates false alarms (A4.4-7).

Exercise 3.1: Derive the power formula

Under μ=μ0+δ\mu = \mu_0 + \delta, z=xˉ−μ0σ/n∼N(δn/σ,1)z = \frac{\bar x - \mu_0}{\sigma/\sqrt n}\sim\mathcal N(\delta\sqrt n/\sigma, 1). So P(z>z1−α)=1−Φ(z1−α−δn/σ)=Φ(δn/σ−z1−α)P(z > z_{1-\alpha}) = 1 - \Phi(z_{1-\alpha} - \delta\sqrt n/\sigma) = \Phi(\delta\sqrt n/\sigma - z_{1-\alpha}).

📝 Quick check (Level 3)
0/3 answered
  1. 1. The most powerful test for simple hypotheses thresholds…
  2. 2. −2 log λ for a GLRT tends to…
  3. 3. Looking at the data repeatedly with a fixed-α test makes the overall false-alarm rate…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Is my filter honest? The NEES test

A Kalman filter reports an error covariance PP. If it’s consistent, the normalized estimation error squared NEES=e⊤P−1e\text{NEES} = e^\top P^{-1}e follows χd2\chi^2_d. Averaged over NN Monte Carlo runs, N⋅NEES‾∼χNd2N\cdot\overline{\text{NEES}}\sim\chi^2_{Nd}. That gives a two-sided acceptance band. If you tune the process noise too small, the filter becomes overconfident: its NEES sits far above the band, and it may later diverge. The same test on innovations (NIS) works with real data where the truth is unknown (Bar-Shalom, Li and Kirubarajan, 2001). This is standard practice for validating navigation filters before flight.

🐍 Exercise 2 (research): NEES consistency test for a Kalman filter
Run 50 Monte Carlo runs of a 1-D Kalman filter with correctly tuned and with 10×-too-small process noise. Average the NEES over runs, compare with the χ² band (Wilson–Hilferty quantiles), and show that the tuned filter passes while the overconfident one is rejected.

Hypothesis testing in AI, robotics and aerospace

  • Fault detection. χ² residual tests flag sensor or actuator faults. GNSS receiver autonomous integrity monitoring (RAIM) tests the residuals of redundant satellite measurements, with α set by the allowed false-alarm rate (Brown, 1992).
  • A/B tests and policy comparison need power analysis up front, fixed stopping rules, and multiple-testing control (A5.1-10).
  • Reproducibility. Under-powered studies and p-hacking produce false findings (Ioannidis, 2005). The ASA statement on p-values (Wasserstein and Lazar, 2016) lists what p-values do and don’t mean.
  • Distribution shift detection. Two-sample tests (KS, MMD) on model inputs or embeddings warn when deployment data differ from training data (Rabanser et al., 2019).
  • Change detection. CUSUM and the generalized likelihood ratio detect regime changes online in telemetry (Page, 1954; Basseville and Nikiforov, 1993).

References

  1. J. Neyman, E. Pearson (1933). “On the problem of the most efficient tests of statistical hypotheses.” Phil. Trans. R. Soc. A, 231.
  2. R. A. Fisher (1925). Statistical Methods for Research Workers. Oliver & Boyd.
  3. E. Lehmann, J. Romano (2005). Testing Statistical Hypotheses, 3rd ed. Springer.
  4. R. Wasserstein, N. Lazar (2016). “The ASA statement on p-values: context, process, and purpose.” The American Statistician, 70(2).
  5. J. Ioannidis (2005). “Why most published research findings are false.” PLoS Medicine, 2(8).
  6. J. Cohen (1988). Statistical Power Analysis for the Behavioral Sciences, 2nd ed. Erlbaum.
  7. Y. Bar-Shalom, X. R. Li, T. Kirubarajan (2001). Estimation with Applications to Tracking and Navigation, Ch. 5. Wiley.
  8. R. G. Brown (1992). “A baseline GPS RAIM scheme and a note on the equivalence of three RAIM methods.” Navigation, 39(3).
  9. M. Basseville, I. Nikiforov (1993). Detection of Abrupt Changes. Prentice Hall.
  10. S. Rabanser, S. Günnemann, Z. Lipton (2019). “Failing loudly: an empirical study of methods for detecting dataset shift.” NeurIPS.