ADescribe · Guide test 104
Shapiro–Wilk test
Tests normality through the relationship between ordered observations and expected normal order statistics.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- Normality tests (battery) — Is a numeric variable (or each group of it) plausibly normal — by tests and by shape?
- Normality test (one test) — Is a numeric variable (or each group of it) plausibly normally distributed?
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
Sinh–arcsinh shape: 0 is symmetric.
Below 1: heavier tails than normal; 1 with ε = 0 is exactly normal.
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how W varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .135).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- the ordered data
- weights from expected normal order statistics
- 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 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
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.
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))
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
- SciPy — SciPy · shapirodocs.scipy.org
- scipy.stats.shapirodocs.scipy.org
- 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.