← All notes

Statistical note

Normality and goodness-of-fit diagnostics

Shapiro–Wilk, D’Agostino–Pearson, Anderson–Darling, Q–Q thinking, and why testing normality is not a checkbox.

8 min read

Normality tests evaluate compatibility with a normal distribution; they do not certify that a downstream model is correct. Shapiro–Wilk uses a correlation-like comparison between ordered observations and expected normal order statistics.

Q-Q patterns for compatible and heavy-tailed samples

import numpy as np
from scipy import stats

residuals = np.array([-1.2, -0.7, -0.2, 0.0, 0.1, 0.4, 0.8, 1.1])
print(stats.shapiro(residuals))
print(stats.normaltest(residuals))       # requires a sufficient sample size
print(stats.anderson(residuals, dist="norm"))

Mathematics and interpretation

A goodness-of-fit statistic measures a discrepancy D(Fn,F0)D(F_n,F_0) between the empirical distribution FnF_n and a reference F0F_0. Different tests weight the center and tails differently. A p-value answers how surprising that discrepancy is under the fitted null procedure.

Case study: model residuals

For cell-intensity regression, inspect residual Q–Q structure, residuals versus fitted values, and clusters by experiment. At large nn, tiny harmless deviations can be significant; at small nn, damaging departures can be undetected. The relevant question is whether inference is robust to the observed departure.

Functions: scipy.stats.shapiro, normaltest, anderson, cramervonmises, and goodness_of_fit. The normal model is commonly written as

XN(μ,σ2).X\sim\mathcal{N}(\mu,\sigma^2).