Skip to content

ADescribe · Guide test 104

Shapiro–Wilk test

Tests normality through the relationship between ordered observations and expected normal order statistics.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

In Normality test (one test), choose Test = Shapiro–Wilk.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Shapiro–Wilk test

40
0.60

Sinh–arcsinh shape: 0 is symmetric.

1.00

Below 1: heavier tails than normal; 1 with ε = 0 is exactly normal.

0.050

Your data

Drag a point or use ↑/↓ to change it
Sample · n = 40 · mean 0.63

If H₀ were true

W = 0.96
  1. The reference: how W varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .135).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

W=(∑iai x(i))2∑i(xi−xˉ)2W = \dfrac{\left(\sum_i a_i\,x_{(i)}\right)^2}{\sum_i (x_i-\bar x)^2}

With your numbers

W=0.96,n=40W = 0.96,\qquad n = 40
x(i)x_{(i)}
the ordered data
aia_i
weights from expected normal order statistics
WW
near 1 for normal data; small W means non-normal

The verdict

W = 0.96, p = .135

p > α = .050: compatible with H₀

Powerful against most departures. With large n it flags trivial departures; judge the Q–Q plot and whether the analysis is robust, not just p.

Statistic
0.957
p-value
0.1350
Shapiro–Wilk test on Sample: n = 40: W = 0.96, p = .135. The p-value is above α = .050, so the data are compatible with H0.

Shapiro–Wilk test on Sample: n = 40: W = 0.96, p = .135. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: observations follow a normal distribution.

Assumptions

Independent identically distributed continuous observations; H0 is a normal distribution with unknown mean and positive variance. Censoring, truncation, clustering and fitted regression residuals require different calibration.

Formula

W=(∑iaix(i))2∑i(xi−xˉ)2a=V−1mmTV−2m\begin{gathered}W=\frac{(\sum_i a_ix_{(i)})^2}{\sum_i(x_i-\bar x)^2}\\[5pt] a=\frac{V^{-1}m}{\sqrt{m^TV^{-2}m}}\end{gathered}

Parameters and notation

x(i) are order statistics; m,V are the means and covariance of standard normal order statistics. Practical implementations approximate the coefficients and null distribution.

Structure of the method

Sort observations, contrast the order statistics using weights derived or approximated from normal-order-statistic moments, and normalize by total centered squared variation. Small W indicates poor alignment with the expected normal order pattern; a dedicated algorithm maps W and sample size to a p-value.

Estimated and nuisance parameters

The sample mean and scale are estimated but removed through location-scale invariance. Order-statistic coefficients depend on n rather than being tuned to the observed shape. They are not regression weights estimated to maximize the chance of accepting normality.

Settings and design choices

Prespecify the sample being assessed, transformations, missing-value treatment, and alpha. R accepts 3–5000 nonmissing observations; SciPy warns that large-n p-values beyond 5000 may be inaccurate despite an accurate W. These implementation limits are distinct from universal power or validity claims.

Fitting and adaptation

Recompute W and its n-dependent calibration for a new independent sample. If applying the statistic to regression residuals, simulate and refit the full regression under the null when model-aware calibration is needed. Neural fine-tuning is inapplicable; choosing transformations until normality is accepted is selection.

Sensitivity and robustness

Rounding ties, censoring, mixtures, dependence, and model-fitted residual constraints alter interpretation. Large samples detect small scientifically irrelevant departures; small samples may miss important tails. Combine the result with a Q–Q plot and assess whether the downstream procedure truly requires normal observations.

How to use and calibrate

Small W rejects normality. Use a validated Shapiro–Wilk p-value algorithm within its documented sample size range.

Example application

Check a plausible normal sampling model alongside a Q–Q plot.

Interpretation and pitfalls

Watch out

Nonsignificance does not prove normality. Testing raw outcomes is not the same as checking a regression error model.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Normality is assessed for independent observations. For model diagnostics, test residual assumptions in context; do not automatically choose a downstream test based on a preliminary normality p-value.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x=rng.normal(size=60)
print(stats.shapiro(x))
Output
ShapiroResult(statistic=np.float64(0.9762044523331548), pvalue=np.float64(0.28956693535477557))
R

Validated — Executed successfully in the validation environment · needs Base/standard library

set.seed(2026)
x <- rnorm(60)
print(shapiro.test(x))
Output
	Shapiro-Wilk normality test

data:  x
W = 0.97888, p-value = 0.383

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 104, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT104.