Skip to content

ADescribe · Guide test 093

Levene test

Tests variance equality using group deviations from their means.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Equal spread tests, choose Test = Levene's original (mean-centered).

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 · Levene test

3
15
0.00

Group i has true mean (i − 1) × spread.

2.20
0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 15 · mean 0.23Group 2 · n = 15 · mean −0.44Group 3 · n = 15 · mean −1.09

If H₀ were true

W = 1.40
  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 = .259).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

W=(N−k)∑jnj(zˉj−zˉ)2(k−1)∑j∑i(zij−zˉj)2,zij=∣xij−xˉj∣W = \dfrac{(N-k)\sum_j n_j(\bar z_j-\bar z)^2}{(k-1)\sum_j\sum_i(z_{ij}-\bar z_j)^2},\quad z_{ij} = |x_{ij}-\bar x_j|

With your numbers

W=1.40,ν1=2, ν2=42W = 1.40,\quad \nu_1 = 2,\ \nu_2 = 42
zijz_{ij}
absolute deviation from the group mean

The verdict

F(2, 42) = 1.40, p = .259

p > α = .050: compatible with H₀

A one-way ANOVA on absolute deviations. The mean-centered version is the original; the median-centered version (Brown–Forsythe) is more robust.

Statistic
1.397
p-value
0.2586
Levene test on Group 1: n = 15; Group 2: n = 15; Group 3: n = 15: F(2, 42) = 1.40, p = .259. The p-value is above α = .050, so the data are compatible with H0.

Levene test on Group 1: n = 15; Group 2: n = 15; Group 3: n = 15: F(2, 42) = 1.40, p = .259. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: groups have equal dispersion as represented by mean absolute centered deviations.

Assumptions

Independent groups; finite absolute deviations. Comparable shapes support interpretation as equal scale/variance. Exact normal ANOVA theory does not generally apply to transformed deviations.

Formula

zij=∣xij−cj∣F=∑jnj(zˉj−zˉ)2/(k−1)∑ij(zij−zˉj)2/(N−k)\begin{gathered}z_{ij}=|x_{ij}-c_j|\\[5pt] F=\frac{\sum_jn_j(\bar z_j-\bar z)^2/(k-1)}{\sum_{ij}(z_{ij}-\bar z_j)^2/(N-k)}\end{gathered}

Parameters and notation

cj is the group mean; k groups,N observations. This is ANOVA on absolute centered deviations.

Structure of the method

Estimate each group mean, convert observations into absolute deviations from that mean, and run a one-way ANOVA contrast on the transformed deviations. The familiar F ratio is computationally an ANOVA statistic, but its usual reference is approximate because centers were estimated from the same data.

Estimated and nuisance parameters

Estimate group means, transformed group means, and within-group variation of absolute deviations. The inferential target is dispersion represented by expected absolute centered deviation; identifying it with variance equality needs an appropriate common-shape model rather than arbitrary distributions with equal variances.

Settings and design choices

Explicitly set center=mean because some software defaults to median centering. Choose group definitions and missing-value rules in advance. If a trimmed variant is wanted, state the trimming fraction and call it a different centering variant rather than silently changing the Levene specification.

Fitting and adaptation

Re-estimate group centers and reconstruct deviations whenever data change. A resampling scheme must reproduce the chosen centering step and be justified for its null; ordinary label permutation requires exchangeability, which is stronger than equal variances with different means. No neural fine-tuning applies.

Sensitivity and robustness

Means remain sensitive to outliers, and small groups produce strongly dependent transformed deviations. Unequal shapes can change expected absolute deviations despite equal variances. Report group sample sizes and dispersion estimates, and avoid claiming that nonsignificance proves a common error variance for every later model.

How to use and calibrate

Use an approximate Fk−1,N−k reference or a justified resampling scheme.

Example application

Compare dispersion across treatment groups.

Interpretation and pitfalls

Watch out

Center choice matters. Brown–Forsythe here is the median-centered variance test, distinct from the means test in entry 15.

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

Variance/scale homogeneity, not a test of equal means. Center choice distinguishes Levene from its median-centered Brown–Forsythe version.

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)
groups = [rng.normal(m,1,20) for m in (0,.4,.8)]
print(stats.levene(*groups,center="mean"))
Output
LeveneResult(statistic=np.float64(3.193284098252484), pvalue=np.float64(0.048474357978205894))
R

Validated — Executed successfully in the validation environment · needs car

set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(car::leveneTest(value~group,d,center=mean))
Output
Levene's Test for Homogeneity of Variance (center = mean)
      Df F value Pr(>F)
group  2  0.0203 0.9799
      57

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 093, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT093.