Shapiro–Wilk Test
Test a sample for normality, with the Q–Q plot that shows what kind of departure you have.
1 is a perfectly straight Q–Q line
against α = 0.05
values in the sample
p = 0.7354 is above α, so there is no evidence against normality. That is not proof the data is normal — with n = 20 the test may simply lack the power to see a modest departure.
Q–Q plot
The Shapiro–Wilk test asks whether a sample could plausibly have come from a normal distribution. W measures how closely the sorted values track the straight line a normal sample would follow: 1 is a perfect fit, and a p-value below α is evidence against normality.
W is a Q–Q plot reduced to one number
Sort your sample. A normal sample of that size would, on average, have its ith smallest value at a predictable place — the normal score for that position. Plot your sorted values against those scores and a normal sample gives a straight line. W is essentially the squared correlation of that plot, rescaled: it is the ratio of the best linear estimate of the variance to the ordinary sample variance, and those two agree only when the points really do lie on a line.
This is why the test and the picture belong together. W tells you whether the sample departs from normal; the Q–Q plot tells you how. A smooth curve means skew, both ends pulling away from the line means heavy tails, and a single point far off the line means an outlier — three quite different problems that produce the same small p-value.
Why it beats the alternatives
Shapiro–Wilk is generally the most powerful of the common normality tests, which is why R, SPSS and SciPy all offer it and why it is usually the one reported. The Kolmogorov–Smirnov test, its main rival, is substantially weaker against realistic alternatives — and in its textbook form it assumes you knew the mean and variance in advance rather than estimating them from the sample, which is almost never true.
x(ᵢ) is the ith smallest value; the weights aᵢ come from the expected normal order statistics
- 1 Sort the sample. W is built from the order statistics, so the ordering is the whole input.
- 2 Work out the normal scores. For position i out of n, that is Φ⁻¹((i − 0.375) ÷ (n + 0.25)) — where a normal sample’s ith value would sit.
- 3 Turn the scores into weights. Royston’s algorithm normalises them and corrects the two most extreme, which is what makes W comparable across sample sizes.
- 4 Form the ratio. The squared weighted sum over the ordinary sum of squares. W lies between 0 and 1.
- 5 Read the p-value, then look at the plot. A p above α leaves normality intact. A p below it means look at the Q–Q plot to see whether you have skew, heavy tails or one stray point.
How often the test catches a uniform distribution
Share of samples rejected at α = 0.05, from 2,000 simulated uniform samples at each size. Power depends on sample size, not just on how non-normal the data is.
| Sample size | Rejected at α = 0.05 |
|---|---|
| 20 | 20% |
| 30 | 40% |
| 50 | 75% |
| 100 | 99.6% |
| 200 | 100% |
The two ways this test misleads people
The first is reading a non-significant result as proof of normality. It is not. The table above measures the problem directly: a uniform distribution is about as un-bell-shaped as a bounded distribution gets, and at n = 20 this test misses it four times out of five. A large p-value with a small sample means you have not detected a departure, which is a much weaker statement than there being none.
The second is the mirror image. With a few thousand observations the test detects departures so slight that nothing downstream would notice them, and flags perfectly workable data as non-normal. This matters less than people fear, because the procedures that assume normality — t-tests, ANOVA, regression — rely on the sampling distribution of the mean rather than of the data, and the central limit theorem takes care of that as n grows. The irony is real: the test becomes most sensitive exactly when the assumption stops mattering.
The practical position most statisticians take is to treat the Q–Q plot as the primary tool and the test as a sanity check on it. The plot shows magnitude and kind of departure; the test converts that into a number whose meaning depends heavily on n. This page reports W and p to the same precision as R and SciPy, using Royston’s AS R94 algorithm, and draws the plot alongside so you can read both.