Normality tests are not verdicts
The eleven normality tests in CodeSplash, what each one looks at, and why a plot and a question about robustness matter more than a p-value.
What runs in CodeSplash
- STAT104Shapiro–Wilk test Runs in CodeSplash
- STAT105Shapiro–Francia test Runs in CodeSplash
- STAT106D’Agostino–Pearson omnibus test Runs in CodeSplash
- STAT107Jarque–Bera test Runs in CodeSplash
- STAT108Lilliefors normality test Runs in CodeSplash
- STAT109Anderson–Darling normality test Runs in CodeSplash
- STAT110Cramér–von Mises normality test Runs in CodeSplash
- STAT111Pearson chi square normality test Runs in CodeSplash
- STAT112D’Agostino skewness test Runs in CodeSplash
- STAT113Anscombe–Glynn kurtosis test Runs in CodeSplash
- STAT114Filliben probability plot correlation test Runs in CodeSplash
- Normality test (one test) Verified in Python and R
- Normality tests (battery) Verified in Python and R
You will be able to
- Group normality tests by what they measure
- Explain why large samples reject trivial departures
- Combine a Q–Q plot, a test and a question about robustness
Read first
What's the question?
ReadA normality test asks: are these data compatible with a normal distribution?
That's rarely what you need. What you usually need is: will my method be misled by this much non-normality, at this sample size? A t test on 200 values barely notices moderate skew. A test can flag it anyway, and on 8 values a test can miss a serious problem.
Build a Q–Q plot
ExploreA Q–Q plot compares your sorted values with the values a normal distribution would give. Points on the line are compatible with normality. An S-shape suggests tail problems, and a curve suggests skew.
Change the shape and learn the patterns.
AExplorable · Build a Q–Q plot
How do skewness and heavy tails show up in a normal Q–Q plot?
Before plotting: what pattern will the points make?
Below 1: heavier tails.
Commit your prediction above to see the result
Make your prediction to see the result.
Sample size changes the verdict
PredictPredict first
A column is slightly non-normal, a departure no method would care about. At which sample size does a normality test reject more often?
Reveal
The answer: At n = 5,000
At 5,000. Large samples detect trivial departures, and small samples miss real ones. Try it below: the rejection rate climbs with n, as the shape stays the same.
AExplorable · The normality-test paradox
Why is a normality test least helpful exactly when you might rely on it?
How often does Shapiro–Wilk reject this skew at n = 1,000?
Commit your prediction above to see the result
Make your prediction to see the result.
The tests, by what they look at
Read| Group | Tests |
|---|---|
| Correlation with normal order statistics | Shapiro–Wilk, Shapiro–Francia, Filliben PPCC |
| Moments | skewness, kurtosis, D'Agostino–Pearson, Jarque–Bera |
| Distance from the normal CDF | Lilliefors, Anderson–Darling, Cramér–von Mises |
| Binned counts | Pearson |
Shapiro–Wilk is a strong general default. Anderson–Darling gives more weight to tails. The moment tests tell you which feature departs.
Skewed ozone
In the appOzone is the obvious suspect. All 116 readings go through the battery, and every test rejects.
Shapiro–Francia gives 0.879, p < .001. D'Agostino–Pearson gives 26.5, and Jarque–Bera gives 35.8.
The skewness test has 4.66, and the kurtosis test has 2.20. So skew is the main story.
New York air quality, 1973Not every sample fails
In the appThe battery on three small PlantGrowth groups gives one verdict for each:
0 of 3 groups of weight depart from normality by the n-dependent rule.
- Tests rejecting
- 0
- Tests run
- 11
- Departing
- 0
- Groups
- 3
Plots
View data
| weight |
|---|
| 4.170 |
| 5.580 |
| 5.180 |
| 6.110 |
| 4.500 |
| 4.610 |
| 5.170 |
| 4.530 |
| 5.330 |
| 5.140 |
View data
| weight |
|---|
| 4.810 |
| 4.170 |
| 4.410 |
| 3.590 |
| 5.870 |
| 3.830 |
| 6.030 |
| 4.890 |
| 4.320 |
| 4.690 |
View data
| weight |
|---|
| 6.310 |
| 5.120 |
| 5.540 |
| 5.500 |
| 5.370 |
| 5.290 |
| 4.920 |
| 6.150 |
| 5.800 |
| 5.260 |
Normality tests
| group | Test | Statistic | p | Rejects at .05 |
|---|---|---|---|---|
| ctrl | Shapiro–Wilk | 0.9567 | .747 | no |
| ctrl | Shapiro–Francia | 0.9553 | .694 | no |
| ctrl | Filliben probability-plot correlation | 0.9771 | .657 | no |
| ctrl | Anderson–Darling | 0.2829 | .555 | no |
| ctrl | Lilliefors (Kolmogorov–Smirnov) | 0.1735 | .528 | no |
| ctrl | Cramér–von Mises | 0.0495 | .482 | no |
| ctrl | D'Agostino–Pearson omnibus | 0.2335 | .890 | no |
| ctrl | Jarque–Bera | 0.3120 | .856 | no |
| ctrl | D'Agostino skewness | 0.4831 | .629 | no |
| ctrl | Anscombe–Glynn kurtosis | 0.0104 | .992 | no |
| ctrl | Pearson χ² | 4.400 | .221 | no |
| trt1 | Shapiro–Wilk | 0.9304 | .452 | no |
| trt1 | Shapiro–Francia | 0.9380 | .474 | no |
| trt1 | Filliben probability-plot correlation | 0.9687 | .473 | no |
| trt1 | Anderson–Darling | 0.3298 | .444 | no |
| trt1 | Lilliefors (Kolmogorov–Smirnov) | 0.1865 | .410 | no |
| trt1 | Cramér–von Mises | 0.0490 | .491 | no |
| trt1 | D'Agostino–Pearson omnibus | 0.9677 | .616 | no |
| trt1 | Jarque–Bera | 0.6962 | .706 | no |
| trt1 | D'Agostino skewness | 0.9832 | .326 | no |
| trt1 | Anscombe–Glynn kurtosis | 0.0329 | .974 | no |
| trt1 | Pearson χ² | 3.200 | .362 | no |
| trt2 | Shapiro–Wilk | 0.9410 | .564 | no |
| trt2 | Shapiro–Francia | 0.9467 | .578 | no |
| trt2 | Filliben probability-plot correlation | 0.9730 | .563 | no |
| trt2 | Anderson–Darling | 0.3089 | .503 | no |
| trt2 | Lilliefors (Kolmogorov–Smirnov) | 0.1874 | .403 | no |
| trt2 | Cramér–von Mises | 0.0513 | .456 | no |
| trt2 | D'Agostino–Pearson omnibus | 1.013 | .603 | no |
| trt2 | Jarque–Bera | 0.7585 | .684 | no |
| trt2 | D'Agostino skewness | 1.004 | .315 | no |
| trt2 | Anscombe–Glynn kurtosis | −0.0725 | .942 | no |
| trt2 | Pearson χ² | 2 | .572 | no |
Shape and verdict
| group | n | Tests rejecting | Skewness (G1) | z | Excess kurtosis (G2) | z | Verdict |
|---|---|---|---|---|---|---|---|
| ctrl | 10 | 0 | 0.3210 | 0.4672 | −0.2291 | −0.1717 | no evidence against normality |
| trt1 | 10 | 0 | 0.6590 | 0.9591 | −0.2028 | −0.1520 | no evidence against normality |
| trt2 | 10 | 0 | 0.6732 | 0.9799 | −0.3242 | −0.2430 | no evidence against normality |
- Verdict: n < 50 → Shapiro–Wilk at α = .05; 50–299 → |z| of skewness or kurtosis > 3.29; n ≥ 300 → |G1| > 2 or excess kurtosis > 4 (Kim 2013). With large samples every test rejects trivial departures, so the magnitudes decide.
- All eleven tests estimate the mean and SD (composite null). Shapiro–Wilk needs 3–5,000 values, Shapiro–Francia 5–5,000, Anderson–Darling, Cramér–von Mises, Pearson χ² and the D'Agostino tests at least 8, Lilliefors at least 5.
- Filliben's p compares r with 1999 normal samples of the same size (seed 42); the tests overlap, so 'k of 11 reject' is a summary of agreement, not a combined test.
The exact R script · R R version 4.5.1 (2025-06-13)
# Normality tests (battery)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method normality.battery 1.1.1 · spec 443cb27941ed89ce
# Dataset: plantgrowth (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/plantgrowth.parquet", col_select = c("weight", "group")))
n_input <- nrow(df)
df[["group"]] <- factor(df[["group"]], levels = c("ctrl", "trt1", "trt2")) # stored level order
df <- df[stats::complete.cases(df[c("weight", "group")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("weight", "group")) # infinite values stop the run (registry/errors.yaml)
# %% Tests
y <- "weight"
g <- "group"
parts <- lapply(levels(df[[g]]), function(lv) list(level = lv, x = df[[y]][df[[g]] == lv]))
if (nrow(df) >= 2 && length(unique(df[[y]])) < 2) cs_error("CS_E_CONSTANT", column = y) # no variation: every test and shape measure is undefined
alpha <- 0.05
verdict <- function(n, sw_p, m, flat = FALSE) {
# n-dependent rule (Kim 2013): tests for small n, standardized shape for moderate n, magnitudes for large n.
if (n < 8) return(list(FALSE, "too few values to judge"))
if (flat) return(list(FALSE, "no variation to judge")) # every value the same: tests and shape are undefined
if (n < 50) {
bad <- is.finite(sw_p) && sw_p < alpha
return(list(bad, if (bad) "departs from normality (Shapiro–Wilk)" else "no evidence against normality"))
}
if (n < 300) {
bad <- abs(m$skewness_z) > 3.29 || abs(m$kurtosis_z) > 3.29
return(list(bad, if (bad) "departs from normality (|z| of skewness or kurtosis > 3.29)" else "approximately normal in shape"))
}
bad <- abs(m$skewness) > 2 || m$kurtosis > 4
list(bad, if (bad) "substantially non-normal (|G1| > 2 or G2 > 4)" else "approximately normal in shape (large n: judged by magnitude)")
}
# Each test: c(statistic key, p key) in the published values.
keys <- list(shapiro_wilk = c("sw_w", "sw_p"), shapiro_francia = c("sf_w", "sf_p"), filliben = c("ppcc_r", "ppcc_p"),
anderson_darling = c("ad_a", "ad_p"), lilliefors = c("lillie_d", "lillie_p"), cramer_von_mises = c("cvm_w2", "cvm_p"),
dagostino_pearson = c("k2", "k2_p"), jarque_bera = c("jb", "jb_p"), skewness = c("skew_z", "skew_p"),
kurtosis = c("kurt_z", "kurt_p"), pearson_chisq = c("chisq", "chisq_p"))
seed <- 42 # Filliben's p: normal samples from the shared Wichmann-Hill stream
reps <- as.integer(1999)
rows <- list()
tests <- list()
values <- list(n_total = nrow(df))
for (pt in parts) {
x <- pt$x[!is.na(pt$x)]
n <- length(x)
part <- list(n = n)
n_tests <- 0
n_reject <- 0
for (name in cs_normality_test_names()) {
r <- cs_normality_test(x, name, seed = seed, reps = reps)
part[[keys[[name]][1]]] <- r$statistic
part[[keys[[name]][2]]] <- r$p
if (name == "pearson_chisq") part$chisq_df <- if (is.null(r$df) || r$df == 0) NaN else r$df
tested <- is.finite(r$p)
n_tests <- n_tests + tested
n_reject <- n_reject + (tested && r$p < alpha)
tests[[length(tests) + 1]] <- c(if (!is.null(g)) list(group = pt$level),
list(test = r$label, statistic = r$statistic, p = r$p,
reject = if (tested) (if (r$p < alpha) "yes" else "no") else "not computed"))
}
m <- cs_moments(x)
vd <- verdict(n, part$sw_p, m, flat = n > 0 && diff(range(x)) == 0)
part <- c(part, list(n_tests = n_tests, n_reject = n_reject, skewness = m$skewness, skewness_z = m$skewness_z,
kurtosis = m$kurtosis, kurtosis_z = m$kurtosis_z, depart = vd[[1]], verdict = vd[[2]]))
for (k in names(part)) values[[sprintf("%s[%s]", k, pt$level)]] <- part[[k]]
rows[[length(rows) + 1]] <- c(if (!is.null(g)) list(group = pt$level), part)
}
# %% Result
departing <- Filter(function(r) isTRUE(r$depart), rows)
values$n_parts <- length(rows)
values$n_departing <- length(departing)
values$lead <- parts[[1]]$level
group_col <- if (!is.null(g)) list(list(key = "group", label = g, type = "string")) else list()
charts <- list()
for (i in seq_len(min(6, length(parts)))) {
x <- parts[[i]]$x
if (length(x) < 3) next
rc <- unique(round(seq(1, length(x), length.out = min(length(x), 5000))))
charts[[length(charts) + 1]] <- cs_chart(sprintf("qq-%d", i - 1), "qq",
paste0("Normal Q–Q: ", y, if (!is.null(g)) sprintf(" (%s)", parts[[i]]$level) else ""),
list(x = cs_col(y, x[rc])))
}
cs_publish(list(
method = "normality.battery",
methodVersion = "1.1.1",
title = "Normality tests",
engine = cs_engine_info("stats", "nanoparquet"),
n = nrow(df),
summary = paste0(
if (is.null(g)) sprintf("%d of %d tests reject normality at α = .05 for %s; by the n-dependent rule it %s from normality.",
rows[[1]]$n_reject, rows[[1]]$n_tests, y, if (isTRUE(rows[[1]]$depart)) "departs" else "does not depart")
else sprintf("%d of %d groups of %s depart from normality by the n-dependent rule.", length(departing), length(rows), y),
if (any(vapply(rows, function(r) r$n >= 300, logical(1)))) " With n ≥ 300 every test rejects trivial departures — read the shape, not the p-values." else ""),
statistics = list(list(key = "n_reject", label = "Tests rejecting", value = rows[[1]]$n_reject), list(key = "n_tests", label = "Tests run", value = rows[[1]]$n_tests),
list(key = "n_departing", label = "Departing", value = length(departing)), list(key = "n_parts", label = "Groups", value = length(rows))),
tables = list(
list(key = "tests", title = "Normality tests", columns = c(group_col, list(
list(key = "test", label = "Test", type = "string"), list(key = "statistic", label = "Statistic", type = "number"),
list(key = "p", label = "p", type = "pvalue"), list(key = "reject", label = "Rejects at .05", type = "string"))), rows = tests),
list(key = "shape", title = "Shape and verdict", columns = c(group_col, list(
list(key = "n", label = "n", type = "integer"), list(key = "n_reject", label = "Tests rejecting", type = "integer"),
list(key = "skewness", label = "Skewness (G1)", type = "number"),
list(key = "skewness_z", label = "z", type = "number"), list(key = "kurtosis", label = "Excess kurtosis (G2)", type = "number"),
list(key = "kurtosis_z", label = "z", type = "number"), list(key = "verdict", label = "Verdict", type = "string"))),
rows = lapply(rows, function(r) r[intersect(c("group", "n", "n_reject", "skewness", "skewness_z", "kurtosis", "kurtosis_z", "verdict"), names(r))]))
),
effectSizes = list(),
assumptions = list(),
warnings = warnings,
notes = list(
paste("Verdict: n < 50 → Shapiro–Wilk at α = .05; 50–299 → |z| of skewness or kurtosis > 3.29; n ≥ 300 → |G1| > 2 or excess kurtosis > 4 (Kim 2013).",
"With large samples every test rejects trivial departures, so the magnitudes decide."),
paste("All eleven tests estimate the mean and SD (composite null). Shapiro–Wilk needs 3–5,000 values, Shapiro–Francia 5–5,000,",
"Anderson–Darling, Cramér–von Mises, Pearson χ² and the D'Agostino tests at least 8, Lilliefors at least 5."),
sprintf("Filliben's p compares r with %d normal samples of the same size (seed %d); the tests overlap, so 'k of 11 reject' is a summary of agreement, not a combined test.", reps, as.integer(seed))
),
charts = charts,
values = values
))
0 of 3 groups of weight depart from normality by the n-dependent rule.
- Tests rejecting
- 0
- Tests run
- 11
- Departing
- 0
- Groups
- 3
To keep this page light, the plots are shown once, under the R tab.
Normality tests
| group | Test | Statistic | p | Rejects at .05 |
|---|---|---|---|---|
| ctrl | Shapiro–Wilk | 0.9567 | .747 | no |
| ctrl | Shapiro–Francia | 0.9553 | .694 | no |
| ctrl | Filliben probability-plot correlation | 0.9771 | .657 | no |
| ctrl | Anderson–Darling | 0.2829 | .555 | no |
| ctrl | Lilliefors (Kolmogorov–Smirnov) | 0.1735 | .528 | no |
| ctrl | Cramér–von Mises | 0.0495 | .482 | no |
| ctrl | D'Agostino–Pearson omnibus | 0.2335 | .890 | no |
| ctrl | Jarque–Bera | 0.3120 | .856 | no |
| ctrl | D'Agostino skewness | 0.4831 | .629 | no |
| ctrl | Anscombe–Glynn kurtosis | 0.0104 | .992 | no |
| ctrl | Pearson χ² | 4.400 | .221 | no |
| trt1 | Shapiro–Wilk | 0.9304 | .452 | no |
| trt1 | Shapiro–Francia | 0.9380 | .474 | no |
| trt1 | Filliben probability-plot correlation | 0.9687 | .473 | no |
| trt1 | Anderson–Darling | 0.3298 | .444 | no |
| trt1 | Lilliefors (Kolmogorov–Smirnov) | 0.1865 | .410 | no |
| trt1 | Cramér–von Mises | 0.0490 | .491 | no |
| trt1 | D'Agostino–Pearson omnibus | 0.9677 | .616 | no |
| trt1 | Jarque–Bera | 0.6962 | .706 | no |
| trt1 | D'Agostino skewness | 0.9832 | .326 | no |
| trt1 | Anscombe–Glynn kurtosis | 0.0329 | .974 | no |
| trt1 | Pearson χ² | 3.200 | .362 | no |
| trt2 | Shapiro–Wilk | 0.9410 | .564 | no |
| trt2 | Shapiro–Francia | 0.9467 | .578 | no |
| trt2 | Filliben probability-plot correlation | 0.9730 | .563 | no |
| trt2 | Anderson–Darling | 0.3089 | .503 | no |
| trt2 | Lilliefors (Kolmogorov–Smirnov) | 0.1874 | .403 | no |
| trt2 | Cramér–von Mises | 0.0513 | .456 | no |
| trt2 | D'Agostino–Pearson omnibus | 1.013 | .603 | no |
| trt2 | Jarque–Bera | 0.7585 | .684 | no |
| trt2 | D'Agostino skewness | 1.004 | .315 | no |
| trt2 | Anscombe–Glynn kurtosis | −0.0725 | .942 | no |
| trt2 | Pearson χ² | 2.000 | .572 | no |
Shape and verdict
| group | n | Tests rejecting | Skewness (G1) | z | Excess kurtosis (G2) | z | Verdict |
|---|---|---|---|---|---|---|---|
| ctrl | 10 | 0 | 0.3210 | 0.4672 | −0.2291 | −0.1717 | no evidence against normality |
| trt1 | 10 | 0 | 0.6590 | 0.9591 | −0.2028 | −0.1520 | no evidence against normality |
| trt2 | 10 | 0 | 0.6732 | 0.9799 | −0.3242 | −0.2430 | no evidence against normality |
- Verdict: n < 50 → Shapiro–Wilk at α = .05; 50–299 → |z| of skewness or kurtosis > 3.29; n ≥ 300 → |G1| > 2 or excess kurtosis > 4 (Kim 2013). With large samples every test rejects trivial departures, so the magnitudes decide.
- All eleven tests estimate the mean and SD (composite null). Shapiro–Wilk needs 3–5,000 values, Shapiro–Francia 5–5,000, Anderson–Darling, Cramér–von Mises, Pearson χ² and the D'Agostino tests at least 8, Lilliefors at least 5.
- Filliben's p compares r with 1999 normal samples of the same size (seed 42); the tests overlap, so 'k of 11 reject' is a summary of agreement, not a combined test.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Normality tests (battery)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method normality.battery 1.1.1 · spec 443cb27941ed89ce
# Dataset: plantgrowth (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
from scipy import stats
import codesplash as cs
from codesplash.stats import describe as csd
from codesplash.stats import normality as csn
# %% Data
df = pd.read_parquet("tests/parity/fixtures/plantgrowth.parquet", columns=["weight", "group"])
n_input = len(df)
df["group"] = pd.Categorical(df["group"], categories=["ctrl", "trt1", "trt2"]) # stored level order
df = df.dropna(subset=["weight", "group"]) # listwise deletion over the analysis columns
df["group"] = df["group"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["weight", "group"]) # infinite values stop the run (registry/errors.yaml)
# %% Tests
y = "weight"
g = "group"
parts = [(str(lv), df.loc[df[g] == lv, y].to_numpy(dtype=float)) for lv in df[g].cat.categories]
if len(df) >= 2 and len(np.unique(df[y].to_numpy(dtype=float))) < 2: # no variation: every test and shape measure is undefined
cs.cs_error("CS_E_CONSTANT", column=y)
alpha = 0.05
nan = float("nan")
def verdict(n, sw_p, m, flat=False):
"""n-dependent rule (Kim 2013): tests for small n, standardized shape for moderate n, shape
magnitudes for large n (where any test rejects trivial departures)."""
if n < 8:
return False, "too few values to judge"
if flat: # every value the same: the tests and shape measures are undefined
return False, "no variation to judge"
if n < 50:
bad = np.isfinite(sw_p) and sw_p < alpha
return bool(bad), "departs from normality (Shapiro–Wilk)" if bad else "no evidence against normality"
if n < 300:
bad = abs(m["skewness_z"]) > 3.29 or abs(m["kurtosis_z"]) > 3.29
return bool(bad), "departs from normality (|z| of skewness or kurtosis > 3.29)" if bad else "approximately normal in shape"
bad = abs(m["skewness"]) > 2 or m["kurtosis"] > 4
return bool(bad), "substantially non-normal (|G1| > 2 or G2 > 4)" if bad else "approximately normal in shape (large n: judged by magnitude)"
# Each test: (statistic key, p key) in the published values.
KEYS = {"shapiro_wilk": ("sw_w", "sw_p"), "shapiro_francia": ("sf_w", "sf_p"), "filliben": ("ppcc_r", "ppcc_p"),
"anderson_darling": ("ad_a", "ad_p"), "lilliefors": ("lillie_d", "lillie_p"), "cramer_von_mises": ("cvm_w2", "cvm_p"),
"dagostino_pearson": ("k2", "k2_p"), "jarque_bera": ("jb", "jb_p"), "skewness": ("skew_z", "skew_p"),
"kurtosis": ("kurt_z", "kurt_p"), "pearson_chisq": ("chisq", "chisq_p")}
seed, reps = 42, int(1999) # Filliben's p: normal samples from the shared Wichmann–Hill stream
rows, tests, values = [], [], {"n_total": len(df)}
for level, x in parts:
x = x[~np.isnan(x)]
n = x.size
part = {"n": n}
n_tests = n_reject = 0
for name in csn.TESTS:
r = csn.normality_test(x, name, seed=seed, reps=reps)
sk, pk = KEYS[name]
part[sk], part[pk] = r["statistic"], r["p"]
if name == "pearson_chisq":
part["chisq_df"] = r["df"] if r["df"] else nan
tested = np.isfinite(r["p"])
n_tests += int(tested)
n_reject += int(tested and r["p"] < alpha)
tests.append({"group": level, "test": r["label"], "statistic": r["statistic"], "p": r["p"],
"reject": ("yes" if r["p"] < alpha else "no") if tested else "not computed"})
m = csd.moments(x)
bad, text = verdict(n, part["sw_p"], m, flat=bool(n) and np.ptp(x) == 0)
part.update({"n_tests": n_tests, "n_reject": n_reject, "skewness": m["skewness"], "skewness_z": m["skewness_z"],
"kurtosis": m["kurtosis"], "kurtosis_z": m["kurtosis_z"], "depart": bad, "verdict": text})
values.update({f"{k}[{level}]": v for k, v in part.items()})
rows.append({"group": level, **part})
# %% Result
departing = [r for r in rows if r["depart"]]
values.update({"n_parts": len(rows), "n_departing": len(departing), "lead": rows[0]["group"]})
group_col = [{"key": "group", "label": g, "type": "string"}] if g else []
charts = [
cs.chart(f"qq-{i}", "qq", f"Normal Q–Q: {y}" + (f" ({level})" if g else ""),
{"x": cs.col(y, x[np.unique(np.round(np.linspace(0, x.size - 1, min(x.size, 5000))).astype(int))])})
for i, (level, x) in enumerate(parts[:6]) if x.size >= 3
]
cs.publish({
"method": "normality.battery",
"methodVersion": "1.1.1",
"title": "Normality tests",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": len(df),
"summary": (f"{rows[0]['n_reject']} of {rows[0]['n_tests']} tests reject normality at α = .05 for {y}; by the n-dependent rule it {'departs' if rows[0]['depart'] else 'does not depart'} from normality."
if not g else f"{len(departing)} of {len(rows)} groups of {y} depart from normality by the n-dependent rule.")
+ (" With n ≥ 300 every test rejects trivial departures — read the shape, not the p-values." if any(r["n"] >= 300 for r in rows) else ""),
"statistics": [{"key": "n_reject", "label": "Tests rejecting", "value": rows[0]["n_reject"]}, {"key": "n_tests", "label": "Tests run", "value": rows[0]["n_tests"]},
{"key": "n_departing", "label": "Departing", "value": len(departing)}, {"key": "n_parts", "label": "Groups", "value": len(rows)}],
"tables": [
{"key": "tests", "title": "Normality tests", "columns": group_col + [
{"key": "test", "label": "Test", "type": "string"}, {"key": "statistic", "label": "Statistic", "type": "number"},
{"key": "p", "label": "p", "type": "pvalue"}, {"key": "reject", "label": "Rejects at .05", "type": "string"}],
"rows": [{k: v for k, v in t.items() if g or k != "group"} for t in tests]},
{"key": "shape", "title": "Shape and verdict", "columns": group_col + [
{"key": "n", "label": "n", "type": "integer"}, {"key": "n_reject", "label": "Tests rejecting", "type": "integer"},
{"key": "skewness", "label": "Skewness (G1)", "type": "number"},
{"key": "skewness_z", "label": "z", "type": "number"}, {"key": "kurtosis", "label": "Excess kurtosis (G2)", "type": "number"},
{"key": "kurtosis_z", "label": "z", "type": "number"}, {"key": "verdict", "label": "Verdict", "type": "string"}],
"rows": [{k: r[k] for k in ("group", "n", "n_reject", "skewness", "skewness_z", "kurtosis", "kurtosis_z", "verdict") if g or k != "group"} for r in rows]},
],
"effectSizes": [],
"assumptions": [],
"warnings": warnings,
"notes": [
"Verdict: n < 50 → Shapiro–Wilk at α = .05; 50–299 → |z| of skewness or kurtosis > 3.29; n ≥ 300 → |G1| > 2 or excess kurtosis > 4 (Kim 2013). "
"With large samples every test rejects trivial departures, so the magnitudes decide.",
"All eleven tests estimate the mean and SD (composite null). Shapiro–Wilk needs 3–5,000 values, Shapiro–Francia 5–5,000, "
"Anderson–Darling, Cramér–von Mises, Pearson χ² and the D'Agostino tests at least 8, Lilliefors at least 5.",
f"Filliben's p compares r with {reps} normal samples of the same size (seed {seed}); the tests overlap, so "
"'k of 11 reject' is a summary of agreement, not a combined test.",
],
"charts": charts,
"values": values,
})
MPG in mtcars gives Shapiro–Wilk p = .123, Anderson–Darling p = .121, and Filliben p = .153.
These small samples can't rule out moderate departures, so a large p-value isn't a certificate.
What to do with the result
ReflectUse this order:
- Look at the histogram and the Q–Q plot.
- Ask whether your method is robust at this sample size. A t test or ANOVA with moderate samples usually is.
- Use a test as one clue, especially at small or moderate n.
In Insights (⌘5), a numeric column's page has a Normality panel. Which analysis of yours relied on a test alone?
Check your understanding
CheckpointCheck yourself
With 50,000 rows, Shapiro–Francia gives p < .001, and the Q–Q plot is nearly straight. What do you conclude?
Show the answer
Answer: b
With that much data, tiny departures reach significance. Size matters more than the p-value here.
Check yourself
Which test looks most directly at the tails?
Show the answer
Answer: b
Anderson–Darling weights the tails of the distribution heavily. The skewness test looks at asymmetry, and binning discards detail.
Check yourself
A Q–Q plot's points curve upward at both ends, forming an S. What does that suggest?
Show the answer
Answer: b
Extreme values lie further out than a normal curve predicts at both ends.
Check yourself
Shapiro–Wilk on MPG in mtcars gives what ? Run normality.shapiro on it, or read the example: give three decimals.
Show the answer
Answer: 0.947564726479274
It's close to 1, as expected for a sample that a test doesn't flag.
Check yourself
A test on 8 values gives p = 0.60. What can you say?
Show the answer
Answer: b
Absence of evidence isn't evidence of absence, and at this size the test can't see much. Look at the plot and think about the process that produced the data.
Recap
Recap- Normality tests answer a narrower question than the one you have.
- Large samples flag trivial departures, and small samples miss serious ones.
- Look, ask about robustness, and use a test as one clue.
Concepts in this lesson