Skip to content

ADescribe · Guide test 092

Bartlett homogeneity of variance test

Tests equality of several variances; strongly affected by departures from normality.

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 = Bartlett's test.

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 · Bartlett homogeneity of variance 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

K² = 5.06
  1. The reference: how K² 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 = .080).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

K2=(N−k)ln⁡sp2−∑j(nj−1)ln⁡sj21+13(k−1)(∑j1nj−1−1N−k)K^2 = \dfrac{(N-k)\ln s_p^2-\sum_j(n_j-1)\ln s_j^2}{1+\frac{1}{3(k-1)}\left(\sum_j\frac{1}{n_j-1}-\frac{1}{N-k}\right)}

With your numbers

K2=5.06,ν=2K^2 = 5.06,\quad \nu = 2
sp2s_p^2
pooled variance
sj2s_j^2
group variances

The verdict

K²(2) = 5.06, p = .080

p > α = .050: compatible with H₀

Most powerful for normal data, badly misleading for non-normal data: a significant Bartlett test often just means heavy tails.

Statistic
5.062
p-value
0.0796
Bartlett homogeneity of variance test on Group 1: n = 15; Group 2: n = 15; Group 3: n = 15: K²(2) = 5.06, p = .080. The p-value is above α = .050, so the data are compatible with H0.

Bartlett homogeneity of variance test on Group 1: n = 15; Group 2: n = 15; Group 3: n = 15: K²(2) = 5.06, p = .080. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: k normal populations have equal variances.

Assumptions

Independent normal samples; sufficient observations in each group.

Formula

B=(N−k)log⁡sp2−∑j(nj−1)log⁡sj21+[∑j1/(nj−1)−1/(N−k)]/[3(k−1)]B=\frac{(N-k)\log s_p^2-\sum_j(n_j-1)\log s_j^2}{1+[\sum_j1/(n_j-1)-1/(N-k)]/[3(k-1)]}

Parameters and notation

sp²=Σ(nj−1)sj²/(N−k), N=Σnj.

Structure of the method

Pool group variances with their residual degrees-of-freedom weights, compare the log pooled variance with the weighted logs of individual variances, and apply Bartlett’s finite-sample correction. The resulting statistic uses an approximate chi-square reference for equality across normal populations.

Estimated and nuisance parameters

Estimate a separate mean and variance per group and a common pooled variance under the null. Group sizes enter both the likelihood contrast and correction. Every included group needs enough observations for a variance; zero within-group variability can make logarithms degenerate.

Settings and design choices

Prespecify the grouping, missing-value exclusions, and significance level. Unequal group sizes are allowed by the formula but can interact with nonnormality. Do not confuse this procedure with a Bartlett test on a correlation matrix or choose it only after a normality pretest passes.

Fitting and adaptation

Recompute all group means, variances, and pooled quantities for a new dataset. A parametric calibration check simulates independent Gaussian groups at the observed sizes under a common variance and repeats the full calculation. Classical refitting replaces neural fine-tuning.

Sensitivity and robustness

Shape departures can trigger rejection even when population variances are equal. Outliers and heavy tails disproportionately affect sample variances and logarithms. A nonsignificant result does not establish equivalence; report group variability estimates and intervals, and consider a robust dispersion analysis suited to the scientific target.

How to use and calibrate

Use χ²k−1 approximately; a large statistic suggests variance heterogeneity.

Example application

Check variance homogeneity in a scientifically defensible normal model.

Interpretation and pitfalls

Watch out

Nonnormality can cause rejection even with equal variances. This is not Bartlett’s correlation matrix sphericity test.

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.bartlett(*groups))
Output
BartlettResult(statistic=np.float64(4.031447844288386), pvalue=np.float64(0.13322392469941502))
R

Validated — Executed successfully in the validation environment · needs Base/standard library

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(bartlett.test(value~group,d))
Output
	Bartlett test of homogeneity of variances

data:  value by group
Bartlett's K-squared = 0.48519, df = 2, p-value = 0.7846

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