Skip to content

ADescribe · normality.battery

Normality tests (battery)

Is a numeric variable (or each group of it) plausibly normal — by tests and by shape?

All eleven normality tests of the guide side by side — Shapiro–Wilk, Shapiro–Francia, Filliben's probability-plot correlation, Anderson–Darling, Lilliefors, Cramér–von Mises, D'Agostino–Pearson K², Jarque–Bera, D'Agostino's skewness and Anscombe–Glynn's kurtosis tests and Pearson χ² — with how many reject, skewness and excess kurtosis, Q–Q plots and an n-dependent verdict: tests for small samples, standardized shape for moderate ones, magnitudes for large ones.

Verified in Python and R Python and R agree to 6 decimals Seeded Also called normality battery, normality tests, Shapiro–Francia…

A real result

Example “Plantgrowth groups”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Normality testsRecorded · Python and R agreeRecorded 2026-11-17 · 100 values compared
R

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

Normal Q–Q: weight (ctrl)Is a variable (or a set of residuals) approximately normal, and where does it depart?
View data
weight
4.170
5.580
5.180
6.110
4.500
4.610
5.170
4.530
5.330
5.140
Normal Q–Q: weight (trt1)Is a variable (or a set of residuals) approximately normal, and where does it depart?
View data
weight
4.810
4.170
4.410
3.590
5.870
3.830
6.030
4.890
4.320
4.690
Normal Q–Q: weight (trt2)Is a variable (or a set of residuals) approximately normal, and where does it depart?
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

groupTestStatisticpRejects at .05
ctrlShapiro–Wilk0.9567.747no
ctrlShapiro–Francia0.9553.694no
ctrlFilliben probability-plot correlation0.9771.657no
ctrlAnderson–Darling0.2829.555no
ctrlLilliefors (Kolmogorov–Smirnov)0.1735.528no
ctrlCramér–von Mises0.0495.482no
ctrlD'Agostino–Pearson omnibus0.2335.890no
ctrlJarque–Bera0.3120.856no
ctrlD'Agostino skewness0.4831.629no
ctrlAnscombe–Glynn kurtosis0.0104.992no
ctrlPearson χ²4.400.221no
trt1Shapiro–Wilk0.9304.452no
trt1Shapiro–Francia0.9380.474no
trt1Filliben probability-plot correlation0.9687.473no
trt1Anderson–Darling0.3298.444no
trt1Lilliefors (Kolmogorov–Smirnov)0.1865.410no
trt1Cramér–von Mises0.0490.491no
trt1D'Agostino–Pearson omnibus0.9677.616no
trt1Jarque–Bera0.6962.706no
trt1D'Agostino skewness0.9832.326no
trt1Anscombe–Glynn kurtosis0.0329.974no
trt1Pearson χ²3.200.362no
trt2Shapiro–Wilk0.9410.564no
trt2Shapiro–Francia0.9467.578no
trt2Filliben probability-plot correlation0.9730.563no
trt2Anderson–Darling0.3089.503no
trt2Lilliefors (Kolmogorov–Smirnov)0.1874.403no
trt2Cramér–von Mises0.0513.456no
trt2D'Agostino–Pearson omnibus1.013.603no
trt2Jarque–Bera0.7585.684no
trt2D'Agostino skewness1.004.315no
trt2Anscombe–Glynn kurtosis−0.0725.942no
trt2Pearson χ²2.572no

Shape and verdict

groupnTests rejectingSkewness (G1)zExcess kurtosis (G2)zVerdict
ctrl1000.32100.4672−0.2291−0.1717no evidence against normality
trt11000.65900.9591−0.2028−0.1520no evidence against normality
trt21000.67320.9799−0.3242−0.2430no 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.
Python

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

groupTestStatisticpRejects at .05
ctrlShapiro–Wilk0.9567.747no
ctrlShapiro–Francia0.9553.694no
ctrlFilliben probability-plot correlation0.9771.657no
ctrlAnderson–Darling0.2829.555no
ctrlLilliefors (Kolmogorov–Smirnov)0.1735.528no
ctrlCramér–von Mises0.0495.482no
ctrlD'Agostino–Pearson omnibus0.2335.890no
ctrlJarque–Bera0.3120.856no
ctrlD'Agostino skewness0.4831.629no
ctrlAnscombe–Glynn kurtosis0.0104.992no
ctrlPearson χ²4.400.221no
trt1Shapiro–Wilk0.9304.452no
trt1Shapiro–Francia0.9380.474no
trt1Filliben probability-plot correlation0.9687.473no
trt1Anderson–Darling0.3298.444no
trt1Lilliefors (Kolmogorov–Smirnov)0.1865.410no
trt1Cramér–von Mises0.0490.491no
trt1D'Agostino–Pearson omnibus0.9677.616no
trt1Jarque–Bera0.6962.706no
trt1D'Agostino skewness0.9832.326no
trt1Anscombe–Glynn kurtosis0.0329.974no
trt1Pearson χ²3.200.362no
trt2Shapiro–Wilk0.9410.564no
trt2Shapiro–Francia0.9467.578no
trt2Filliben probability-plot correlation0.9730.563no
trt2Anderson–Darling0.3089.503no
trt2Lilliefors (Kolmogorov–Smirnov)0.1874.403no
trt2Cramér–von Mises0.0513.456no
trt2D'Agostino–Pearson omnibus1.013.603no
trt2Jarque–Bera0.7585.684no
trt2D'Agostino skewness1.004.315no
trt2Anscombe–Glynn kurtosis−0.0725.942no
trt2Pearson χ²2.000.572no

Shape and verdict

groupnTests rejectingSkewness (G1)zExcess kurtosis (G2)zVerdict
ctrl1000.32100.4672−0.2291−0.1717no evidence against normality
trt11000.65900.9591−0.2028−0.1520no evidence against normality
trt21000.67320.9799−0.3242−0.2430no 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.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Plantgrowth groupsplantgrowth · group: group · outcome: weight
  • Ozone skewedairquality · outcome: Ozone
  • Survey height by sexs1_survey · group: sex · outcome: height
  • Pulse spaces1_survey · outcome: pulse rate
  • Degenerate constantplantgrowth · group: group · outcome: weight

In the guides

Tests from the statistics guide this method runs

Where it sits in the decision guides

  • Assess distribution: histogram, Q–Q · Statistics Guide · A — Describe data
  • Normality tests: Shapiro–Wilk · Statistics Guide · A — Describe data
  • Normality tests: Anderson–Darling · Statistics Guide · A — Describe data
  • Normality tests: Kolmogorov–Smirnov / Lilliefors · Statistics Guide · A — Describe data
  • Normality (per group, differences or residuals) · Statistics Guide · Step 2 — Check assumptions
  • EDA (correlation, distributions) · DS & ML Decision Guide · Describe — summarize and visualize

What you need

Variablenumeric · 1 column
The numeric variable to check for normality.
Split bycategorical / boolean · 0–1 column · 1–12 levels
Optional — test each group separately (what t-tests and ANOVA assume).

Choices you make

Advanced

Filliben simulationsdefault 1999

Normal samples simulated for the Filliben probability-plot correlation p-value (shared seeded stream, same in Python and R).

What it reports

n_total
How many independent units the analysis used; it sets precision and power.
n_parts
How many independent units the analysis used; it sets precision and power.
n_departing
How many independent units the analysis used; it sets precision and power.
lead
Which part the summary describes: all when there is no grouping, otherwise the first group level.

Per group, level or term: n[<group> or all], sw_w[…], sw_p[…], sf_w[…], sf_p[…], ppcc_r[…], ppcc_p[…], ad_a[…], ad_p[…], lillie_d[…], lillie_p[…], cvm_w2[…], cvm_p[…], k2[…], k2_p[…], jb[…], jb_p[…], skew_z[…], skew_p[…], kurt_z[…], kurt_p[…], chisq[…], chisq_df[…], chisq_p[…], n_tests[…], n_reject[…], skewness[…], skewness_z[…], kurtosis[…], kurtosis_z[…], depart[…], verdict[…]

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.

Default traps between the two languages

  • Shapiro–Wilk: both engines call library implementations of Royston's AS R94 (P1, as normality.shapiro).
  • Anderson–Darling, Lilliefors, Shapiro–Francia, Cramér–von Mises and Pearson χ² are the shared helpers in both engines, checked against nortest as an outside reference. They are not scipy.stats.anderson or statsmodels' lilliefors, whose p-values differ.
  • Lilliefors p differs from nortest above p = 0.1. At or below 0.1 it is Dallal & Wilkinson's approximation and equals nortest's; above it, it is Molin & Abdi's (1998) curve, kept within [0.1, 1]. On 379 random samples in that range, the new p minus nortest's has mean −0.0015 and range −0.010 to +0.057.
  • Pearson χ² counts a value whose normal probability rounds to exactly 1 in the top class. nortest loses that value, so the statistic differs on such samples (112 of 2,000 random samples).
  • The Anderson–Darling and Cramér–von Mises p-values are held at the curve's own value above A* = 10 and W* = 1.1: 3.765e-24 and 7.370e-10, where nortest prints 3.7e-24 and 7.37e-10.
  • D'Agostino K²: Python calls scipy.stats.skewtest/kurtosistest; codesplashr computes the same formulas.
  • Filliben's p is Monte Carlo from normal samples on the shared Wichmann–Hill stream, so both engines count the same simulations (P0 for the p-value).
Python

The exact script CodeSplash ran for example “Plantgrowth groups” · 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,
})
R

The exact script CodeSplash ran for example “Plantgrowth groups” · 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
))

Sources

  • Shapiro, S. S., & Wilk, M. B. (1965). An analysis of variance test for normality. Biometrika, 52, 591–611.
  • Stephens, M. A. (1986). Tests based on EDF statistics. In D'Agostino & Stephens (Eds.), Goodness-of-fit techniques.
  • Dallal, G. E., & Wilkinson, L. (1986). An analytic approximation to the distribution of Lilliefors's test statistic. The American Statistician, 40, 294–296.
  • D'Agostino, R. B., Belanger, A., & D'Agostino, R. B., Jr. (1990). A suggestion for using powerful and informative tests of normality. The American Statistician, 44, 316–321.
  • Jarque, C. M., & Bera, A. K. (1987). A test for normality of observations and regression residuals. International Statistical Review, 55, 163–172.
  • Royston, P. (1993). A pocket-calculator algorithm for the Shapiro–Francia test for non-normality: an application to medicine. Statistics in Medicine, 12, 181–184.
  • Filliben, J. J. (1975). The probability plot correlation coefficient test for normality. Technometrics, 17, 111–117.
  • Moore, D. S. (1986). Tests of chi-squared type. In D'Agostino & Stephens (Eds.), Goodness-of-fit techniques.
  • Anscombe, F. J., & Glynn, W. J. (1983). Distribution of the kurtosis statistic b2 for normal samples. Biometrika, 70, 227–234.
  • Kim, H.-Y. (2013). Statistical notes for clinical researchers: assessing normal distribution (2) using skewness and kurtosis. Restorative Dentistry & Endodontics, 38, 52–54.

From the CodeSplash method registry · normality.battery v1.1.1.