BMultivariate · multivariate.normality
Multivariate normality tests
Do several variables jointly follow a multivariate normal distribution?
Seven tests of multivariate normality on the rows or on within-group residuals: Mardia's skewness and kurtosis, Henze–Zirkler, Henze–Wagner, Royston, Doornik–Hansen and the energy test, with a χ² Q–Q plot of squared Mahalanobis distances. Run them all to see which kind of departure (skewness, tails, any shape) is present, or pick one before you look.
A real result
Example “Guide all”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
Henze–Zirkler, HZ = 0.65, p = .424
- HZ
- 0.6532
- p
- .424
- Tests rejecting
- 0
Plots
View data
| Squared Mahalanobis distance |
|---|
| 1.658 |
| 2.969 |
| 1.761 |
| 2.295 |
| 1.541 |
| 7.210 |
| 1.073 |
| 1.608 |
| 2.088 |
| 4.951 |
| 3.613 |
| 2.766 |
| 1.019 |
| 1.082 |
| 10.271 |
| 2.052 |
| 1.708 |
| 0.8458 |
| 1.487 |
| 1.712 |
| 1.608 |
| 0.2861 |
| 2.114 |
| 3.023 |
| 5.855 |
| 4.546 |
| 5.481 |
| 3.421 |
| 1.491 |
| 4.760 |
| 2.642 |
| 1.089 |
| 3.234 |
| 1.379 |
| 1.100 |
| 1.862 |
| 9.210 |
| 1.986 |
| 5.598 |
| 2.608 |
Assumptions
- Independent rows — The tests assume independent, identically distributed rows; clustered or time-ordered rows inflate rejections.
Multivariate normality tests
| Test | Statistic | Value | df | p | Reject at α = 0.05 |
|---|---|---|---|---|---|
| Mardia skewness | χ² | 7.128 | 10 | .713 | no |
| Mardia kurtosis | z | −0.4881 | — | .625 | no |
| Henze–Zirkler | HZ | 0.6532 | — | .424 | no |
| Henze–Wagner | HW | 0.4066 | — | .610 | no |
| Royston | H | 4.932 | 2.993 | .176 | no |
| Doornik–Hansen | E | 9.160 | 6 | .165 | no |
| Energy | E | 0.8039 | — | .550 | no |
- p-values: asymptotic (χ², normal or lognormal); the energy test always uses 199 Monte-Carlo samples (seed 42).
- The tests probe different departures (skewness, tails, any shape); a few rejecting is common with real data and large n.
Henze–Zirkler, HZ = 0.65, p = .424
- HZ
- 0.6532
- p
- .424
- Tests rejecting
- 0
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Independent rows — The tests assume independent, identically distributed rows; clustered or time-ordered rows inflate rejections.
Multivariate normality tests
| Test | Statistic | Value | df | p | Reject at α = 0.05 |
|---|---|---|---|---|---|
| Mardia skewness | χ² | 7.128 | 10 | .713 | no |
| Mardia kurtosis | z | −0.4881 | — | .625 | no |
| Henze–Zirkler | HZ | 0.6532 | — | .424 | no |
| Henze–Wagner | HW | 0.4066 | — | .610 | no |
| Royston | H | 4.932 | 2.993 | .176 | no |
| Doornik–Hansen | E | 9.160 | 6 | .165 | no |
| Energy | E | 0.8039 | — | .550 | no |
- p-values: asymptotic (χ², normal or lognormal); the energy test always uses 199 Monte-Carlo samples (seed 42).
- The tests probe different departures (skewness, tails, any shape); a few rejecting is common with real data and large n.
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
- Guide allmv_guide_one · variables: y1, y2, y3
- Guide mardia twomv_guide_one · variables: y1, y2
- Skewed residuals allmv_sim_skew · group: group · variables: v1, v2, v3
- Skewed roystonmv_sim_skew · variables: v1, v2, v3
- Iris dh bootstrapiris · group: Species · variables: Sepal.Length, Sepal.Width, Petal.Length
- Iris energyiris · group: Species · variables: Sepal.Length, Sepal.Width
- Degenerate constantmv_guide_one · variables: y1, y2, y3
- Degenerate n3mv_guide_one · variables: y1, y2, y3
In the guides
Tests from the statistics guide this method runs
Where it sits in the decision guides
- Factorial designs, covariates, multivariate (ANCOVA, MANOVA) · Statistics Guide · B — Compare groups
- Normality (per group, differences or residuals) · Statistics Guide · Step 2 — Check assumptions
What you need
- Variablesnumeric · 2–30 columns
- The numeric variables tested jointly (need more rows than variables).
- Groups (optional)categorical / boolean · 0–1 column · 2–50 levels
- Test the within-group residuals instead of the raw rows — what MANOVA and Hotelling's T² assume.
Choices you make
hypothesis
- Testdefault all
Which test leads the result; pick it before seeing the data — the tests answer different questions.
- All seven(default) — Every test, with how many reject; the lead p-value is Henze–Zirkler's (consistent against any alternative).
- Mardia skewness — n b₁,p/6 against χ² with p(p+1)(p+2)/6 df; small-sample corrected below n = 20 (Mardia 1970).
- Mardia kurtosis — Standardized b₂,p against the normal; detects heavy or light tails (Mardia 1970).
- Henze–Zirkler — BHEP characteristic-function test with the HZ bandwidth and a lognormal p (Henze & Zirkler 1990).
- Henze–Wagner — The same BHEP statistic with bandwidth b = 1 (Henze & Wagner 1997).
- Royston — Combines marginal Shapiro–Wilk tests (Shapiro–Francia for a column whose kurtosis exceeds 3), allowing for their correlation; 4 ≤ n ≤ 2000 (Royston 1983, 1992).
- Doornik–Hansen — Transformed skewness and kurtosis of decorrelated variables against χ² with 2p df (Doornik & Hansen 2008).
- Energy — Energy distance to the normal with a Monte-Carlo p (Székely & Rizzo 2005).
- p-valuesdefault asymptotic
How the p-values are computed (the energy test always simulates).
- Asymptotic(default) — χ², normal or lognormal approximations — fast and usual for n ≥ 50.
- Parametric bootstrap — Simulate from the fitted normal and recompute each statistic; better for small n (slower).
- Simulationsdefault 999
Monte-Carlo samples for the energy test and the bootstrap; the smallest possible p is 1/(B + 1).
- Significance leveldefault 0.05
Level at which a test is counted as rejecting.
Checks and remedies
CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.
Independent rows
The tests assume independent, identically distributed rows.
Sample size
Asymptotic p-values are rough below about 20–50 rows; use the bootstrap.
What it reports
- Tests: Multivariate normality
- test
- The exact variant that ran (for example Welch vs classic F), shown so the result can be reported and reproduced.
- statistic
- One test of "every component null holds" from several independent tests' p-values.
- p
- How surprising your data would be if the null hypothesis were true, as a probability.
- n_reject
- How many independent units the analysis used; it sets precision and power.
- n_tests
- How many independent units the analysis used; it sets precision and power.
- n
- How many independent units the analysis used; it sets precision and power.
- dims
- How many outcome columns a multivariate test compares at once. More of them need more rows per group.
- calibration
- Each p-value comes from a reference distribution, a simulation of the null, or an exact count: this column says which.
- missing_share
- Values that were not recorded; how they went missing decides which fixes are safe.
Per group, level or term: statistic[<test>], p[<test>]
Python and R
Python and R agree to 6 decimals (relative tolerance 1e-8). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
Default traps between the two languages
- Under multivariate normality (n = 50, three variables) Royston's H rejects 6.75% at the 5% level over 2,000 samples, and Mardia's kurtosis z 1.4% over 1,000. The other tests stay in the band. Asymptotic references; use the bootstrap calibration for a small sample.
- Both engines use the codesplash twins (codesplash.stats.mvdist ↔ codesplashr cs_mvd_*); Monte-Carlo and bootstrap samples come from the shared Wichmann–Hill stream, so simulated p-values match exactly.
- Royston's marginal W uses scipy.stats.shapiro ↔ stats::shapiro.test (both Royston's AS R94) or the shared Shapiro–Francia helper, by kurtosis — agreement to about 1e-11.
- MVN::doornik_hansen's E differs from the paper's (and ours) unless the column means are equal; MVN's Mardia, Henze–Zirkler, Henze–Wagner and Royston match to 1e-11.
The exact script CodeSplash ran for example “Guide all” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Multivariate normality tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.normality 1.0.2 · spec 9ecdfc634024bc2c
# Dataset: mv_guide_one (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
import codesplash as cs
from codesplash.stats import mvdist
# %% Data
df = pd.read_parquet("tests/parity/fixtures/mv_guide_one.parquet", columns=["y1", "y2", "y3"])
n_input = len(df)
df = df.dropna(subset=["y1", "y2", "y3"]) # listwise deletion over the analysis columns
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, ["y1", "y2", "y3"]) # infinite values stop the run (registry/errors.yaml)
# %% Test
# Multivariate normality (guide 161–167): Mardia skewness and kurtosis, Henze–Zirkler, Henze–Wagner,
# Royston, Doornik–Hansen and the energy test, on the rows or — with groups — on within-group residuals.
variables = ["y1", "y2", "y3"]
test = "all" # all or one test
calibration = "asymptotic" # asymptotic | bootstrap
n_sim = int(199)
alpha = 0.05
seed = 42
X = df[variables].to_numpy(dtype=float)
if len(X) <= len(variables) + 1: # the covariance matrix and its tests need more rows than variables + 1
cs.cs_error("CS_E_TOO_FEW_ROWS", what="A multivariate normality test", min=len(variables) + 2, n=len(X))
for j, v in enumerate(variables):
if len(np.unique(X[:, j])) < 2: # a constant variable makes the covariance matrix singular
cs.cs_error("CS_E_CONSTANT", column=v)
where = ", ".join(variables)
n, dims = X.shape
tests = list(mvdist.NORMALITY_TESTS) if test == "all" else [test]
if "royston" in tests and not 4 <= n <= 2000:
if test == "royston":
raise ValueError(f"Royston's test is defined for 4 to 2000 rows; this sample has {n}")
tests.remove("royston")
rows = mvdist.normality(X, tests, calibration, n_sim, seed)
by = {r["test"]: r for r in rows}
lead = by["henze_zirkler"] if test == "all" else by[test]
p = lead["p"]
rejects = [r for r in rows if r["p"] < alpha]
# %% Assumptions
assumptions = [
{"key": "independence", "label": "Independent rows", "status": "info",
"detail": "The tests assume independent, identically distributed rows; clustered or time-ordered rows inflate rejections."},
]
if n < 20 and test in ("all", "mardia_skewness"):
assumptions.append({"key": "small_n", "label": "Small sample", "status": "info",
"detail": f"n = {n} < 20: Mardia's skewness uses the small-sample correction; asymptotic p-values are rough — consider the bootstrap."})
# %% Result
names = ", ".join(r["label"] for r in rejects)
if test == "all":
summary = (f"{len(rejects)} of {len(rows)} multivariate normality tests reject at α = {alpha:g} for {where}"
+ (f" ({names})." if rejects else ".")
+ f" Henze–Zirkler: HZ = {by['henze_zirkler']['statistic']:.3f}, {cs.fmt_p(by['henze_zirkler']['p'])}.")
else:
summary = (f"{lead['label']} test for {where}: {lead['symbol']} = {lead['statistic']:.3f}, {cs.fmt_p(p)} — "
+ ("evidence against multivariate normality." if p < alpha else "no evidence against multivariate normality."))
if n > 500 and rejects:
summary += " With this many rows trivial departures reject; judge the Q–Q plot as much as the p-values."
values = {"test": test, "statistic": lead["statistic"], "p": p, "n_reject": len(rejects), "n_tests": len(rows), "n": n, "dims": dims,
"calibration": calibration}
for r in rows:
values[f"statistic[{r['test']}]"] = r["statistic"]
values[f"p[{r['test']}]"] = r["p"]
values["missing_share"] = n_dropped / n_input if n_input else 0.0
S = np.cov(X, rowvar=False)
R = X - X.mean(axis=0)
d2 = np.einsum("ij,ij->i", R @ np.linalg.inv(S), R)
cs.publish({
"method": "multivariate.normality",
"methodVersion": "1.0.2",
"title": "Multivariate normality tests",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": (f"{lead['label']}, {lead['symbol']} = {cs.fmt_num(lead['statistic'])}"
+ (f" (df = {lead['df']:.2f})" if lead["df"] is not None else "") + f", {cs.fmt_p(p)}"),
"statistics": [{"key": "statistic", "label": lead["symbol"], "value": lead["statistic"]},
{"key": "p", "label": "p", "value": p, "format": "p"},
{"key": "n_reject", "label": "Tests rejecting", "value": len(rejects)}],
"tables": [{"key": "tests", "title": "Multivariate normality tests",
"columns": [{"key": "label", "label": "Test", "type": "string"}, {"key": "symbol", "label": "Statistic", "type": "string"},
{"key": "statistic", "label": "Value", "type": "number"}, {"key": "df", "label": "df", "type": "number"},
{"key": "p", "label": "p", "type": "pvalue"}, {"key": "reject", "label": f"Reject at α = {alpha:g}", "type": "string"}],
"rows": [{"label": r["label"], "symbol": r["symbol"], "statistic": r["statistic"], "df": r["df"], "p": r["p"],
"reject": "yes" if r["p"] < alpha else "no"} for r in rows]}],
"effectSizes": [],
"assumptions": assumptions,
"warnings": warnings,
"notes": [("p-values: " + ("parametric bootstrap from the fitted normal" if calibration == "bootstrap" else "asymptotic (χ², normal or lognormal)")
+ f"; the energy test always uses {n_sim} Monte-Carlo samples (seed {seed})."),
"The tests probe different departures (skewness, tails, any shape); a few rejecting is common with real data and large n."],
"values": values,
"charts": [cs.chart("qq", "mahalanobis-qq", "χ² Q–Q plot of squared Mahalanobis distances", {
"d2": cs.col("Squared Mahalanobis distance", d2)}, controls={"df": dims, "envelope": True})],
})
The exact script CodeSplash ran for example “Guide all” · R version 4.5.1 (2025-06-13)
# Multivariate normality tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.normality 1.0.2 · spec 9ecdfc634024bc2c
# Dataset: mv_guide_one (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/mv_guide_one.parquet", col_select = c("y1", "y2", "y3")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("y1", "y2", "y3")]), , 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("y1", "y2", "y3")) # infinite values stop the run (registry/errors.yaml)
# %% Test
# Multivariate normality (guide 161-167): Mardia skewness and kurtosis, Henze-Zirkler, Henze-Wagner,
# Royston, Doornik-Hansen and the energy test, on the rows or - with groups - on within-group residuals.
variables <- c("y1", "y2", "y3")
test <- "all" # all or one test
calibration <- "asymptotic" # asymptotic | bootstrap
n_sim <- as.integer(199)
alpha <- 0.05
seed <- 42
X <- as.matrix(df[variables])
storage.mode(X) <- "double"
# the covariance matrix and its tests need more rows than variables + 1
if (nrow(X) <= length(variables) + 1) cs_error("CS_E_TOO_FEW_ROWS", what = "A multivariate normality test", min = length(variables) + 2, n = nrow(X))
for (j in seq_along(variables)) {
# a constant variable makes the covariance matrix singular
if (length(unique(X[, j])) < 2) cs_error("CS_E_CONSTANT", column = variables[j])
}
where <- paste(variables, collapse = ", ")
n <- nrow(X)
dims <- ncol(X)
tests <- if (test == "all") c("mardia_skewness", "mardia_kurtosis", "henze_zirkler", "henze_wagner", "royston", "doornik_hansen", "energy") else test
if ("royston" %in% tests && !(n >= 4 && n <= 2000)) {
if (test == "royston") stop(sprintf("Royston's test is defined for 4 to 2000 rows; this sample has %d", n))
tests <- setdiff(tests, "royston")
}
rows <- cs_mvd_normality(X, tests, calibration, n_sim, seed)
names(rows) <- vapply(rows, `[[`, "", "test")
lead <- if (test == "all") rows[["henze_zirkler"]] else rows[[test]]
p <- lead$p
rejects <- Filter(function(r) r$p < alpha, rows)
# %% Assumptions
assumptions <- list(list(key = "independence", label = "Independent rows", status = "info",
detail = "The tests assume independent, identically distributed rows; clustered or time-ordered rows inflate rejections."))
if (n < 20 && test %in% c("all", "mardia_skewness")) {
assumptions[[2]] <- list(key = "small_n", label = "Small sample", status = "info",
detail = sprintf("n = %d < 20: Mardia's skewness uses the small-sample correction; asymptotic p-values are rough — consider the bootstrap.", n))
}
# %% Result
reject_names <- paste(vapply(rejects, `[[`, "", "label"), collapse = ", ")
if (test == "all") {
hz <- rows[["henze_zirkler"]]
summary <- paste0(sprintf("%d of %d multivariate normality tests reject at α = %s for %s", length(rejects), length(rows), format(alpha), where),
if (length(rejects)) sprintf(" (%s).", reject_names) else ".",
sprintf(" Henze–Zirkler: HZ = %.3f, %s.", hz$statistic, cs_fmt_p(hz$p)))
} else {
summary <- paste0(sprintf("%s test for %s: %s = %.3f, %s — ", lead$label, where, lead$symbol, lead$statistic, cs_fmt_p(p)),
if (p < alpha) "evidence against multivariate normality." else "no evidence against multivariate normality.")
}
if (n > 500 && length(rejects)) summary <- paste(summary, "With this many rows trivial departures reject; judge the Q–Q plot as much as the p-values.")
values <- list(test = test, statistic = lead$statistic, p = p, n_reject = length(rejects), n_tests = length(rows), n = n, dims = dims,
calibration = calibration)
for (r in rows) {
values[[sprintf("statistic[%s]", r$test)]] <- r$statistic
values[[sprintf("p[%s]", r$test)]] <- r$p
}
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0
S <- stats::cov(X)
R <- sweep(X, 2, colMeans(X))
d2 <- rowSums((R %*% solve(S)) * R)
cs_publish(list(
method = "multivariate.normality",
methodVersion = "1.0.2",
title = "Multivariate normality tests",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = paste0(sprintf("%s, %s = %s", lead$label, lead$symbol, cs_fmt_num(lead$statistic)),
if (!is.null(lead$df)) sprintf(" (df = %.2f)", lead$df) else "", sprintf(", %s", cs_fmt_p(p))),
statistics = list(list(key = "statistic", label = lead$symbol, value = lead$statistic),
list(key = "p", label = "p", value = p, format = "p"),
list(key = "n_reject", label = "Tests rejecting", value = length(rejects))),
tables = list(list(key = "tests", title = "Multivariate normality tests",
columns = list(list(key = "label", label = "Test", type = "string"), list(key = "symbol", label = "Statistic", type = "string"),
list(key = "statistic", label = "Value", type = "number"), list(key = "df", label = "df", type = "number"),
list(key = "p", label = "p", type = "pvalue"), list(key = "reject", label = sprintf("Reject at α = %s", format(alpha)), type = "string")),
rows = unname(lapply(rows, function(r) list(label = r$label, symbol = r$symbol, statistic = r$statistic, df = r$df, p = r$p,
reject = if (r$p < alpha) "yes" else "no"))))),
effectSizes = list(),
assumptions = assumptions,
warnings = warnings,
notes = list(paste0("p-values: ", if (calibration == "bootstrap") "parametric bootstrap from the fitted normal" else "asymptotic (χ², normal or lognormal)",
sprintf("; the energy test always uses %d Monte-Carlo samples (seed %d).", n_sim, as.integer(seed))),
"The tests probe different departures (skewness, tails, any shape); a few rejecting is common with real data and large n."),
values = values,
charts = list(cs_chart("qq", "mahalanobis-qq", "χ² Q–Q plot of squared Mahalanobis distances", list(
d2 = cs_col("Squared Mahalanobis distance", d2)), controls = list(df = dims, envelope = TRUE)))
))
Sources
- Mardia, K. V. (1970). Measures of multivariate skewness and kurtosis with applications. Biometrika, 57, 519–530.
- Henze, N., & Zirkler, B. (1990). A class of invariant consistent tests for multivariate normality. Communications in Statistics — Theory and Methods, 19, 3595–3617.
- Henze, N., & Wagner, T. (1997). A new approach to the BHEP tests for multivariate normality. Journal of Multivariate Analysis, 62, 1–23.
- Royston, J. P. (1983). Some techniques for assessing multivariate normality based on the Shapiro–Wilk W. Applied Statistics, 32, 121–133.
- Doornik, J. A., & Hansen, H. (2008). An omnibus test for univariate and multivariate normality. Oxford Bulletin of Economics and Statistics, 70, 927–939.
- Székely, G. J., & Rizzo, M. L. (2005). A new test for multivariate normality. Journal of Multivariate Analysis, 93, 58–80.
From the CodeSplash method registry · multivariate.normality v1.0.2.