Sub topic 7
Checking whether the data are normal
Prerequisites
This chapter assumes you can read a histogram and a box plot. It also assumes you know what a mean and a standard deviation are, and that you have met the idea of a p-value. If p-values are still unclear, review the earlier chapter on the decision rule first.
Why normality is checked at all
Many tests in the test selection map, such as the one-sample t-test, the two-sample t-test, the paired t-test and one-way ANOVA, are called parametric tests. They assume the data come from a normal distribution, the symmetric bell curve described by a mean and a standard deviation. When that assumption holds, these tests are the most powerful choice. When it is badly wrong, their p-values can mislead you.
Normality is a decision input, not a goal. You check it to choose between two branches: a parametric test, or a non-parametric alternative such as Mann-Whitney or Kruskal-Wallis. A later chapter covers the non-parametric tests.
What exactly must be normal
The assumption is about the population from which each sample was drawn. In practice, you check it on the following:
- One-sample t-test: the single sample.
- Two-sample t-test: each group, separately.
- Paired t-test: the differences between the pairs, not the raw columns.
- ANOVA and regression: the residuals (each value minus its group mean or fitted value).
A common error is to pool two groups with different means into one histogram. The pooled data look bimodal and fail a normality check even when each group is perfectly normal.
Graphical checks come first
Plot before you test. Two plots do most of the work.
- Histogram. Look for a single peak, rough symmetry, and no long tail on one side. Histograms of fewer than about 30 points are unreliable, because the bar shapes change with the bin width.
- Normal probability plot (Q-Q plot). Each observation is plotted against the value a perfect normal sample would have at the same rank. Normal data fall close to a straight line. A curve bending away at one end indicates skew. An S-shape indicates heavy or light tails. A staircase pattern indicates rounded or low-resolution measurements.
Process data often fail in recognizable ways. Cycle times and wait times are right-skewed, since they cannot go below zero and have occasional long delays. Defect counts and measurements near a physical limit are also skewed. A mixture of two machines or shifts produces two peaks.
Formal normality tests
A formal test turns the picture into a p-value. The hypotheses are:
- H0: the data come from a normal distribution.
- H1: the data do not come from a normal distribution.
Notice that the usual logic is reversed. A small p-value (below alpha, typically 0.05) is evidence against normality. A large p-value means only that you found no evidence against it. It does not prove the data are normal.
| Test | Typical use | Notes |
|---|---|---|
| Shapiro-Wilk | Small to moderate samples | Good power; the scipy default choice |
| Anderson-Darling | Default in Minitab | Sensitive to departures in the tails |
| Kolmogorov-Smirnov (Lilliefors) | Rarely the best choice | Weaker power; the plain KS test is invalid when the mean and standard deviation are estimated from the same data |
Running the checks in Python
The script below draws Q-Q plots and runs Shapiro-Wilk on two samples. One is a symmetric fill weight. The other is a skewed cycle time. It saves the plots to qq_plots.png.
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from scipy import stats
rng = np.random.default_rng(1)
samples = {
"fill_weight": rng.normal(loc=500, scale=4, size=40),
"cycle_time": rng.lognormal(mean=2.0, sigma=0.6, size=40),
}
fig, axes = plt.subplots(1, 2, figsize=(9, 4))
for ax, (name, x) in zip(axes, samples.items()):
stats.probplot(x, dist="norm", plot=ax)
ax.set_title(name)
w = stats.shapiro(x)
print(f"{name}: W={w.statistic:.3f}, p={w.pvalue:.4f}, skew={stats.skew(x):.2f}")
fig.tight_layout()
fig.savefig("qq_plots.png", dpi=120)
# A log transform often repairs right-skewed data
log_cycle = np.log(samples["cycle_time"])
print("log(cycle_time) Shapiro p =", round(stats.shapiro(log_cycle).pvalue, 4))Expect the fill weight to give a large p-value with points hugging the line. Expect the cycle time to give a small p-value, positive skew, and a Q-Q curve that bends upward at the right end. After the log transform, the cycle time should look much closer to normal, because the data were generated from a lognormal distribution. Real data will not always behave so neatly.
Sample size changes how to read the test
The p-value of a normality test depends on sample size, and this is the most important gotcha in this chapter.
- Small samples (n below about 15). The test has little power. Almost anything passes, even clearly skewed data. Lean on your process knowledge and the plot, and be cautious.
- Large samples (n in the hundreds or more). The test detects tiny departures that do not matter. A sample of 500 can fail Shapiro-Wilk because of slight tail differences, while the t-test remains accurate.
The central limit theorem helps here. It says the sampling distribution of the mean approaches normal as n grows, even when individual values are not normal. For means-based tests, moderate skew is usually tolerable at around n = 30 per group or more. Heavy skew, strong outliers, or very small groups still cause trouble.
What to do when normality fails
First find the cause, because the fix depends on it.
- Check for outliers and data errors. One mistyped value can cause the failure. Investigate it; do not delete it just to pass the test.
- Check for mixed sources. If two machines or shifts are blended, stratify the data and test each group separately.
- Check measurement resolution. Coarse rounding creates ties and a staircase on the Q-Q plot.
- Consider a transformation. A log or square-root transform can fix right skew. Then you run the test on the transformed values and interpret the results on that scale.
- Switch to a non-parametric test. Use this when the data are skewed or outlier-prone and a transformation does not help or is hard to explain to the team.
Common errors
- Testing the pooled data instead of each group, or the raw columns instead of the paired differences or residuals.
- Reading a high p-value as proof of normality.
- Relying on the p-value alone with a very small or very large sample.
- Deleting inconvenient points to force a pass.
- Using a plain Kolmogorov-Smirnov test with parameters estimated from the same data.
- Forgetting that a transformed analysis must be reported on the transformed scale, or back-transformed with care.
Exercise
A team compares cycle times from two machines, 25 observations each. They pool all 50 values, run Shapiro-Wilk, get p = 0.003, and conclude that a t-test is not allowed. What did they do wrong, and what should they do instead?
Show answer
They tested the pooled data. If the machines have different means, the pooled values form a mixture that can fail the test even when each machine is normal. They should check normality separately for each machine (or the residuals after subtracting each group mean), look at Q-Q plots, and only then choose between the two-sample t-test and a non-parametric alternative.
Exercise
A sample of 12 measurements gives a Shapiro-Wilk p-value of 0.21, but the Q-Q plot shows a clear upward bend at the right end. Should you conclude the data are normal?
Show answer
No. With n = 12 the test has low power, so a large p-value is weak evidence. The plot suggests right skew. Look for an outlier or a skewed process, consider a log transform, and consider a non-parametric test.