Statistical Tests Open Access

Shapiro-Wilk Test

Diagram contrasting a bell-shaped normal distribution with a skewed distribution, illustrating what the Shapiro-Wilk Test detects when checking a sample for normality.
Figure 1. The Shapiro-Wilk Test measures how closely a sample's ordered values match the pattern expected under a normal distribution, comparing a weighted combination of the order statistics against the sample variance to produce the W statistic.

Introduction

The Shapiro-Wilk Test checks whether a sample of data plausibly came from a normally distributed population. It's one of the most common checks run before applying a parametric test-a t-test, ANOVA, or linear regression-since many of those methods lean on a normality assumption to guarantee their p-values are trustworthy. If your data looks roughly bell-shaped but you want more than a visual impression, this is usually the first test statisticians reach for.

By the end of this article you will be able to state exactly when a Shapiro-Wilk Test applies, compute the W statistic completely by hand on two contrasting worked examples, understand why the test becomes overly sensitive at large sample sizes, know when to pair it with a Q-Q plot or reach for the Kolmogorov-Smirnov Test instead, and run the same test in one line of Python with scipy.stats.

What Is the Shapiro-Wilk Test?

Introduced by Samuel Shapiro and Martin Wilk in 1965, the Shapiro-Wilk Test is widely regarded as the most powerful formal test of normality, particularly for small to moderate sample sizes. Rather than comparing the data's histogram shape to a bell curve by eye, it measures how well a specific weighted combination of the sorted sample values lines up with what those same order statistics would look like if drawn from a perfect normal distribution.

The result is a single statistic, \( W \), bounded between 0 and 1. Values close to 1 mean the sample's shape closely tracks a normal distribution; values noticeably below 1 indicate skewness, heavy tails, or other departures from normality. A p-value attached to \( W \) then tells you whether that departure is large enough to be statistically significant given the sample size.

Core idea in one line: sort the data, compare a carefully weighted combination of those sorted values against the sample's overall spread-the closer that comparison matches what a true normal sample would produce, the closer \( W \) sits to 1.

When to Use It

Use a Shapiro-Wilk Test whenever you need to check whether a continuous sample plausibly comes from a normal distribution-most often as a preliminary check before running a parametric test whose validity depends on that assumption, and ideally with a sample size that isn't so large that trivial deviations become statistically significant (see The Sample Size Problem).

ScenarioData Being CheckedWhat's Being Checked
Pre-t-test diagnosticResiduals or raw sample valuesWhether normality holds before trusting the t-test's p-value
Regression diagnosticsModel residualsWhether residuals are normally distributed, as OLS assumes
Quality controlMeasurements from a manufacturing processWhether a process output follows the expected normal spread
FinanceDaily asset returnsWhether returns deviate from normality (commonly they do, due to fat tails)
Choosing a testAny small sample before a parametric vs non-parametric decisionWhether to proceed with a parametric test or switch to a non-parametric alternative

The key requirement: continuous data and a genuine question about whether normality can be assumed-if your sample is very large, treat the p-value with caution and lean more heavily on a Q-Q plot instead.

Key Assumptions

  • Continuous data. The test is designed for continuous measurements; applying it to heavily rounded, discrete, or count data can produce misleading results.
  • Independent observations. Each observation is assumed independent of the others, which can be violated by repeated measures or clustered data.
  • Identically distributed observations. All observations are assumed to be drawn from the same underlying distribution-mixing two different populations in one sample can produce an apparent non-normality that has nothing to do with either population individually.
  • No extreme ties or heavy rounding. Large numbers of exactly repeated values can distort the test, since it relies on the relative spacing of sorted order statistics.
  • Sample size in a reasonable range. The test is most informative for small to moderate samples; see The Sample Size Problem for why very large samples require extra caution.

Hypotheses

  • Null Hypothesis (\( H_0 \)): the sample was drawn from a normally distributed population.
  • Alternative Hypothesis (\( H_1 \)): the sample was not drawn from a normally distributed population.

(Note the asymmetry: failing to reject \( H_0 \) never proves normality-it only means the test did not find enough evidence, in this sample, to rule it out.)

The Formula, Explained

Let \( x_{(1)} \le x_{(2)} \le \cdots \le x_{(n)} \) be the sample values sorted in ascending order. The Shapiro-Wilk statistic is:

\[ W = \frac{\left( \sum_{i=1}^{n} a_i \, x_{(i)} \right)^2}{\sum_{i=1}^{n} (x_i - \bar{x})^2} \]

The denominator is simply the sample's total sum of squared deviations from the mean-a measure of overall spread. The numerator is a weighted sum of the sorted values, where the weights \( a_1, \ldots, a_n \) are constants derived from the expected values and covariance structure of order statistics of a standard normal sample of size \( n \). These weights are antisymmetric (\( a_i = -a_{n+1-i} \)) and are published in standard statistical tables or computed internally by software.

In practice, the numerator is usually organized as a sum over paired extreme values working inward:

\[ \sum_{i=1}^{n} a_i \, x_{(i)} = \sum_{k=1}^{\lfloor n/2 \rfloor} a_{n-k+1} \left( x_{(n-k+1)} - x_{(k)} \right) \]

where each term pairs the \( k \)-th smallest value with the \( k \)-th largest value. \( W \) is bounded between 0 and 1; values close to 1 indicate the sample closely matches the shape expected under normality, and small p-values arise when \( W \) is unusually low for the given sample size, based on tables (or software) derived from the sampling distribution of \( W \) under \( H_0 \).

Worked Example 1: An Approximately Normal Sample

Suppose 10 measurements are collected and sorted in ascending order:

\( i \)12345678910
\( x_{(i)} \)11.812.312.613.013.413.714.014.114.915.2

For \( n = 10 \), the standard published Shapiro-Wilk coefficients (Shapiro & Wilk, 1965) for the five paired terms are:

\( k \)PairCoefficient \( a_{n-k+1} \)
1\( x_{(10)} - x_{(1)} \)0.5739
2\( x_{(9)} - x_{(2)} \)0.3291
3\( x_{(8)} - x_{(3)} \)0.2141
4\( x_{(7)} - x_{(4)} \)0.1224
5\( x_{(6)} - x_{(5)} \)0.0399

Computing each pair's difference and multiplying by its coefficient:

\[ \begin{aligned} b &= 0.5739(15.2 - 11.8) + 0.3291(14.9 - 12.3) + 0.2141(14.1 - 12.6) \\ &\quad + 0.1224(14.0 - 13.0) + 0.0399(13.7 - 13.4) \\ &= 0.5739(3.4) + 0.3291(2.6) + 0.2141(1.5) + 0.1224(1.0) + 0.0399(0.3) \\ &= 1.9513 + 0.8557 + 0.3212 + 0.1224 + 0.0120 \\ &\approx 3.2624 \end{aligned} \]

The sample mean is \( \bar{x} = 13.9 \), and the sum of squared deviations works out to \( \sum (x_i - \bar{x})^2 = 10.90 \). So:

\[ W = \frac{(3.2624)^2}{10.90} = \frac{10.643}{10.90} \approx 0.976 \]

For \( n = 10 \), a \( W \) of \( 0.976 \) corresponds to a p-value well above \( 0.05 \) (software gives \( p \approx 0.943 \))-we fail to reject \( H_0 \). \( W \) sits very close to 1, consistent with this sample being drawn from a normal distribution.

Worked Example 2: A Clearly Skewed Sample

Now suppose 10 values are collected that are obviously skewed, with one large outlier pulling the tail far to the right:

\( i \)12345678910
\( x_{(i)} \)11222334522

Using the same coefficients as Worked Example 1:

\[ \begin{aligned} b &= 0.5739(22 - 1) + 0.3291(5 - 1) + 0.2141(4 - 2) \\ &\quad + 0.1224(3 - 2) + 0.0399(3 - 2) \\ &= 0.5739(21) + 0.3291(4) + 0.2141(2) + 0.1224(1) + 0.0399(1) \\ &= 12.0519 + 1.3164 + 0.4282 + 0.1224 + 0.0399 \\ &\approx 13.9588 \end{aligned} \]

The sample mean is \( \bar{x} = 4.5 \), and the sum of squared deviations is \( \sum (x_i - \bar{x})^2 = 354.5 \). So:

\[ W = \frac{(13.9588)^2}{354.5} = \frac{194.85}{354.5} \approx 0.550 \]

A \( W \) of \( 0.550 \) is far below 1, and for \( n = 10 \) this corresponds to a p-value far below \( 0.001 \) (software gives \( p \approx 1.4 \times 10^{-5} \))-we reject \( H_0 \) decisively. This matches how the data was constructed: a single large outlier is exactly the kind of departure the Shapiro-Wilk Test is very good at catching.

Python Example

In practice you'll almost never look up coefficients and compute \( W \) by hand. Python's scipy.stats.shapiro computes the statistic directly from the raw sample:

from scipy.stats import shapiro

data = [11.8, 12.3, 12.6, 13.0, 13.4, 13.7, 14.0, 14.1, 14.9, 15.2]

W, p_value = shapiro(data)

print(f"W statistic: {W:.4f}")
print(f"p-value: {p_value:.4f}")

Output:

W statistic: 0.9764
p-value: 0.9429

This matches Worked Example 1 to four decimal places (the tiny difference from the hand calculation is rounding in the published coefficient table). For a quick visual companion to the numeric test, pair it with statsmodels.api.qqplot or scipy.stats.probplot-see Q-Q Plots below.

How to Interpret Results

ResultInterpretation
p-value \( < \) significance level (e.g., 0.05)Reject \( H_0 \)-sample significantly departs from normality
p-value \( \geq \) significance levelFail to reject \( H_0 \)-no significant evidence against normality
\( W \) close to 1Sample shape closely matches what a normal sample would produce
\( W \) noticeably below 1, especially with large \( n \)Meaningful departure from normality-inspect a Q-Q plot to see the shape of the deviation

Always pair the p-value with a visual check-the Shapiro-Wilk Test tells you whether the sample departs from normality, not how (skewed left, skewed right, heavy-tailed, bimodal), and the shape of the departure often matters more for choosing a next step than the p-value itself.

Q-Q Plots: Seeing Normality Visually

A quantile-quantile (Q-Q) plot plots the sample's sorted values against the quantiles a normal distribution would predict at the same percentiles. If the sample is normal, the points fall approximately on a straight diagonal line. Systematic curvature at the ends indicates skewness or heavy tails, and isolated points far from the line flag outliers-exactly the kind of value that drove Worked Example 2's low \( W \).

import matplotlib.pyplot as plt
from scipy import stats

data = [11.8, 12.3, 12.6, 13.0, 13.4, 13.7, 14.0, 14.1, 14.9, 15.2]

stats.probplot(data, dist="norm", plot=plt)
plt.title("Q-Q Plot")
plt.show()

A Q-Q plot is especially valuable alongside the Shapiro-Wilk Test at large sample sizes, where the test's p-value becomes hypersensitive-see The Sample Size Problem-since the plot lets you judge whether a statistically significant departure is actually large enough to matter for your downstream analysis.

The Sample Size Problem

Like most goodness-of-fit tests, the Shapiro-Wilk Test's power increases with sample size-but this becomes a practical liability once \( n \) grows into the hundreds or thousands. At that scale, the test can detect tiny, real-but-inconsequential deviations from a perfect normal shape and return a very small p-value, even when the data is close enough to normal that any parametric test relying on it would behave perfectly well in practice.

Sample SizeTypical Behavior
Small (\( n < 50 \))Test has good power to detect meaningful departures without being oversensitive
Moderate (\( 50 \le n \le 300 \))Generally reliable; still the recommended range for the test
Large (\( n > 1000 \))Even trivial deviations become significant-rely more on Q-Q plots and effect-size judgment

In large-sample settings, many practitioners skip the formal p-value entirely and rely on a Q-Q plot, histogram, or skewness/kurtosis values to judge whether normality is a reasonable working assumption-the Central Limit Theorem also means many parametric tests are fairly robust to mild non-normality once sample sizes are large anyway.

Common Pitfalls and How to Avoid Them

  • Treating a non-significant result as proof of normality. A large p-value means insufficient evidence of non-normality was found, not that normality is confirmed-especially relevant with small samples that simply lack power to detect real departures.
  • Blindly trusting the p-value at large sample sizes. With very large \( n \), even negligible departures become significant; see The Sample Size Problem.
  • Running the test on data that includes multiple subgroups. If a sample actually mixes two different populations, the combined data can look non-normal even if each subgroup is individually normal-check subgroups separately when relevant.
  • Ignoring the shape of the departure. A significant result alone doesn't say whether the data is skewed, heavy-tailed, or has isolated outliers-always inspect a Q-Q plot alongside the test.
  • Over-relying on formal tests instead of judgment. Many parametric methods are fairly robust to mild non-normality, particularly with reasonably large samples-statistical significance in a normality test doesn't automatically mean the downstream analysis is invalid.

Advantages

  • Widely regarded as the most powerful normality test for small to moderate sample sizes.
  • Produces a single, easy-to-report statistic (\( W \)) with a well-established p-value.
  • Simple to compute, extremely widely implemented, and a standard first check before parametric testing.
  • More sensitive than general-purpose goodness-of-fit tests specifically for detecting non-normality.
  • Works well even with fairly small samples, where visual inspection alone can be ambiguous.

Limitations

  • Oversensitive at large sample sizes. Trivial, practically unimportant departures from normality become statistically significant-see The Sample Size Problem.
  • No diagnosis of the type of departure. The test only produces a p-value, not information about whether the data is skewed, heavy-tailed, or has outliers-pair it with a Q-Q plot.
  • Sensitive to outliers. A single extreme value, as in Worked Example 2, can dominate the statistic and drive a strong rejection even if the rest of the sample is fairly normal.
  • Designed for continuous data. Heavily rounded or discrete data can distort results.
  • A significant result doesn't quantify how non-normal the data is. \( W \) has no direct, intuitive effect-size interpretation the way a correlation coefficient does.

When NOT to Use It

  • When the sample size is very large and even negligible deviations would trigger a significant result-lean on a Q-Q plot and practical judgment instead.
  • When the data is discrete, heavily rounded, or contains many tied values.
  • When you need to test goodness-of-fit against a distribution other than normal-use the Kolmogorov-Smirnov Test or Anderson-Darling test instead.
  • When the downstream analysis is known to be robust to mild non-normality (e.g., large-sample t-tests relying on the Central Limit Theorem)-a significant Shapiro-Wilk result may not be practically relevant.
  • When the sample actually mixes multiple distinct subpopulations that should be analyzed separately.

Shapiro-Wilk vs Kolmogorov-Smirnov vs Anderson-Darling vs Q-Q Plot

AspectShapiro-WilkKolmogorov-SmirnovAnderson-DarlingQ-Q Plot
What it producesA single p-value for departure from normalityA p-value for departure from any specified distributionA p-value, with extra weight on tail departuresA visual comparison-no p-value
Best for normality specificallyYes-generally the most powerful choiceWeaker than Shapiro-Wilk for normalityStrong, especially for tail behaviorAlways useful as a companion, not a substitute
Works for small samplesYes-designed for this rangeLess powerful in small samplesReasonableYes, but subjective at very small \( n \)
Sensitive to large \( n \)Yes-can overreact to trivial deviationsYes, similarlyYes, similarlyNo-visual judgment doesn't scale the same way
Typical useDefault normality check before parametric testingGeneral distributional goodness-of-fitNormality checks with emphasis on tail fitVisual companion to any formal normality test

Common Misconceptions

  • "A non-significant Shapiro-Wilk Test proves the data is normal." It only means no significant departure was detected at the given sample size-see Common Pitfalls. Small samples in particular often lack the power to detect real, moderate departures.
  • "A significant result always matters for my analysis." Not necessarily-many parametric methods are fairly robust to mild non-normality, and at large sample sizes the test can flag departures too small to practically affect results; see The Sample Size Problem.
  • "The Shapiro-Wilk Test tells you what kind of non-normality you have." It only tells you whether the data departs from normal, not whether it's skewed, heavy-tailed, or has outliers-pair it with a Q-Q plot for that.
  • "You should always test for normality before every t-test or ANOVA." With reasonably large samples, the Central Limit Theorem often makes these tests robust to mild non-normality anyway, so a formal test isn't always necessary or the most useful step.
  • "Outliers should just be dropped before running the test." Dropping data points before testing changes the question you're actually answering-outliers are often the reason the test is significant in the first place, and should be investigated, not silently removed.

Interview Questions

  1. Explain in your own words what the Shapiro-Wilk Test measures, and why it uses sorted (order) statistics rather than raw sample moments like skewness and kurtosis.
  2. Walk through how the W statistic is constructed from the weighted sum of paired order statistics and the sample's sum of squared deviations.
  3. Why does the Shapiro-Wilk Test become unreliable as a standalone decision rule at very large sample sizes, and what would you use instead or alongside it?
  4. What does a non-significant Shapiro-Wilk result actually tell you, and what does it not tell you?
  5. How would you decide between the Shapiro-Wilk Test and the Kolmogorov-Smirnov Test for a given normality-checking task?
  6. Why can a single outlier have such a large effect on the Shapiro-Wilk statistic, as in Worked Example 2?
  7. How does a Q-Q plot complement a formal normality test, and what patterns in a Q-Q plot indicate skewness versus heavy tails?
  8. If a Shapiro-Wilk Test is significant on a large sample but a Q-Q plot looks nearly straight, how would you explain that to a non-technical stakeholder?
  9. Why might normality testing be unnecessary before a t-test on a very large sample?
  10. Describe a situation where mixing two subpopulations in one sample could produce a misleading Shapiro-Wilk result.

Frequently Asked Questions

  • The Shapiro-Wilk Test is a hypothesis test that checks whether a sample plausibly comes from a normally distributed population. It is the most commonly recommended normality test for small to moderate sample sizes, and is typically run as a preliminary check before applying a parametric method-such as a t-test, ANOVA, or linear regression-whose validity relies on an assumption of normality.
  • The W statistic is computed as the square of a weighted linear combination of the sorted sample values, divided by the sum of squared deviations of the sample from its mean. The weights come from the expected values and covariance structure of order statistics drawn from a standard normal distribution, so W is close to 1 when the sample's shape closely resembles a normal sample, and drops noticeably below 1 as the sample departs from normality.
  • A small p-value, conventionally below 0.05, indicates the sample significantly departs from a normal distribution. A large p-value means the test did not find sufficient evidence of non-normality; this does not prove the data is normal, only that no statistically significant departure was detected given the available sample.
  • The Shapiro-Wilk Test is purpose-built to detect departures from normality specifically, and is generally the more powerful choice for that job, particularly with small samples. The Kolmogorov-Smirnov Test is a more general-purpose goodness-of-fit test that can compare a sample against any fully specified distribution (not just normal), but when the target distribution is normal, it is typically less sensitive than Shapiro-Wilk at detecting real departures.
  • The test assumes the observations are independent of one another and identically distributed, and that the underlying data is continuous. Its main practical limitation is sample-size sensitivity: with very large samples it can flag statistically significant but practically trivial departures from normality, so results should always be interpreted alongside a visual check such as a Q-Q plot.
  • Not especially well as a standalone decision rule. As sample size grows into the many hundreds or thousands, the test's power increases to the point where even tiny, practically unimportant deviations from a perfect normal shape become statistically significant. In that regime, a Q-Q plot or histogram, combined with a judgment about how much the deviation actually matters for the downstream analysis, is generally more useful than the p-value alone.

Key Takeaways

  • The Shapiro-Wilk Test checks whether a sample plausibly came from a normal distribution by comparing a weighted combination of the sorted sample values against the sample's overall variance.
  • The statistic \( W = \frac{(\sum a_i x_{(i)})^2}{\sum (x_i-\bar{x})^2} \) is bounded between 0 and 1, with values close to 1 indicating a close match to normality.
  • It is widely regarded as the most powerful normality test for small to moderate sample sizes, but becomes oversensitive to trivial departures once samples grow very large-see The Sample Size Problem.
  • A significant result only says the data departs from normal-it doesn't say how (skewed, heavy-tailed, outlier-driven); always pair it with a Q-Q plot.
  • In Python, scipy.stats.shapiro computes the statistic directly from raw data in one line.
  • A non-significant result never proves normality-it only means no significant departure was detected given the sample size and data at hand.
  • For goodness-of-fit against distributions other than normal, use the Kolmogorov-Smirnov Test instead.

The Shapiro-Wilk Test remains the standard first check for normality because the question it answers-does this sample plausibly come from a normal distribution-underlies so many other statistical methods, from the humble t-test to full regression models. Its main strength, sensitivity, is also its main limitation: at large sample sizes it can flag departures too small to matter in practice, which is why the test is best used alongside a Q-Q plot and a dose of practical judgment rather than as an automatic gatekeeper.

The two worked examples above show how directly the test reads from sorted data-a nearly-normal sample produces a \( W \) close to 1 and a large p-value, while a single dominant outlier collapses \( W \) and produces an overwhelmingly small p-value. Check the sample size before trusting the p-value at face value, look at a Q-Q plot alongside the number, and remember that many parametric tests tolerate mild non-normality reasonably well-together, these habits make the Shapiro-Wilk Test a genuinely useful diagnostic rather than a rigid gate.