Mathwords logoMathwords

Shapiro-Wilk Test — Definition, Formula & Example

The Shapiro-Wilk test is a hypothesis test that tells you whether a sample looks like it came from a normal distribution. It produces a single number, W, between 0 and 1. Values near 1 mean the data fit a normal pattern well.

Given an ordered sample x(1)≤x(2)≤⋯≤x(n)x_{(1)} \le x_{(2)} \le \cdots \le x_{(n)}, the Shapiro-Wilk test evaluates H0H_0: the population is normally distributed, against HaH_a: it is not. The test statistic WW is the squared weighted combination of the order statistics divided by the sum of squared deviations from the mean. The weights aia_i come from the expected values and covariances of standard normal order statistics. The test is left-tailed: you reject H0H_0 when WW is at or below the critical value, or when the p-value is less than α\alpha.

Key Formula

W=(∑i=1nai x(i))2∑i=1n(xi−xˉ)2W = \frac{\left(\sum_{i=1}^{n} a_i\, x_{(i)}\right)^2}{\sum_{i=1}^{n} \left(x_i - \bar{x}\right)^2}
Where:
  • WW = The test statistic, with 0<W≤10 < W \le 1
  • x(i)x_{(i)} = The ii-th smallest value in the sorted sample
  • aia_i = Tabulated coefficients that depend only on nn. They satisfy ai=−an+1−ia_i = -a_{n+1-i}, so the middle value gets weight 0 when nn is odd.
  • xˉ\bar{x} = The sample mean
  • nn = The sample size

Worked Example

Problem: A coffee shop records 5 customer wait times in minutes: 1, 2, 2, 3, 12. For n=5n = 5, the Shapiro-Wilk table gives a5=0.6646a_5 = 0.6646, a4=0.2413a_4 = 0.2413, and a3=0a_3 = 0, with a1=−a5a_1 = -a_5 and a2=−a4a_2 = -a_4. The critical value at α=0.05\alpha = 0.05 is 0.762. Test whether these wait times come from a normal distribution.
Step 1: The data are already sorted. Find the mean, then add up the squared deviations to get the denominator.
xˉ=205=4,(−3)2+(−2)2+(−2)2+(−1)2+82=82\bar{x} = \frac{20}{5} = 4, \qquad (-3)^2 + (-2)^2 + (-2)^2 + (-1)^2 + 8^2 = 82
Step 2: Build the numerator by pairing the largest value with the smallest and the second largest with the second smallest. Weight each gap by its coefficient. The middle value has weight 0, so it drops out.
b=0.6646(12−1)+0.2413(3−2)=7.3106+0.2413=7.5519b = 0.6646(12 - 1) + 0.2413(3 - 2) = 7.3106 + 0.2413 = 7.5519
Step 3: Square bb and divide by the denominator. Then compare the result with the critical value. Small values of WW count as evidence against normality.
W=7.5519282≈57.031282≈0.696<0.762W = \frac{7.5519^2}{82} \approx \frac{57.0312}{82} \approx 0.696 < 0.762
Answer: W≈0.696W \approx 0.696, which is below the critical value 0.762, so you reject H0H_0 at the 0.05 level. There is convincing evidence that the wait times do not come from a normal distribution. The single long wait of 12 minutes creates strong right skew.

Why It Matters

The t-procedures you learn in AP Statistics assume the data come from a roughly normal population when samples are small. AP Statistics teaches you to check that assumption with a normal probability plot. The Shapiro-Wilk test puts the same check into numbers, and software such as R and Python reports it routinely in college statistics and research.

Common Mistakes

Mistake: Rejecting normality because WW is large, as if it worked like a z or t statistic where bigger means more extreme.
Correction: WW measures how closely the data match a normal pattern, so values near 1 support normality. Only small values of WW give evidence against H0H_0. Also, with very small samples the test often fails to detect non-normal data, so check a graph as well.

Related Terms