Three independent samples may have similar centers yet different spreads. The Brown–Forsythe test offers one way to compare dispersion: replace each observation by its absolute distance to its group median, then compare how those distances vary between and within groups. This article discusses the median-centered form of Levene’s test for homogeneity of variances.[1]

Its null hypothesis is that the population variances are equal across groups. The median here locates each group’s reference position; the test’s target is neither whether the group medians are equal nor whether the group means are equal.[1]

First look at three groups

SciPy’s documentation gives example groups a, b, and c with 10 numbers each. The three medians are 9.005, 9.100, and 8.965; the sample variances are about 0.00705, 0.13074, and 0.00889. Group b’s sample variance is clearly larger; the test below measures how large that between-group difference is relative to within-group variation.[1]

Left and right panels show three groups’ raw observations with medians, then absolute distances with their means

Recalculation from SciPy’s official three-group example. Left: original values and group medians; right: absolute distances to each group’s median and their means; between- and within-group variation among these distances yields the Brown–Forsythe statistic. Documentation-example recalculation; no invented measurement units are attached to the numbers.[1]

From raw values to distances

Write the j-th observation in group i as Yᵢⱼ and that group’s sample median as Mᵢ. For each observation compute Zᵢⱼ = |Yᵢⱼ − Mᵢ|. For example, 8.88 in group a is 0.125 from its median 9.005; 8.36 in group b is 0.740 from its median 9.100. Larger distances mean the point lies farther from its group center.

The three group means of Z are 0.061, 0.273, and 0.073. They describe each group’s average absolute distance to its median: here group b has the largest average distance. The test then treats Z as the response and computes the usual one-way ANOVA ratio of between-group mean square to within-group mean square.

In this example the between-group sum of squares of Z is 0.2836267 and the within-group sum of squares is 0.5048100. With 30 observations in three groups, the between- and within-group degrees of freedom are 2 and 27, so the statistic is W = (0.2836267 / 2) / (0.5048100 / 27) ≈ 7.585. Using F(2, 27) as an approximate reference distribution yields p ≈ 0.00243.

Recalculation and check

The code below first computes distances, sums of squares, and the upper-tail F probability independently, then checks against SciPy’s median version.[1]

import numpy as np
from scipy import stats

a = [8.88, 9.12, 9.04, 8.98, 9.00, 9.08, 9.01, 8.85, 9.06, 8.99]
b = [8.88, 8.95, 9.29, 9.44, 9.15, 9.58, 8.36, 9.18, 8.67, 9.05]
c = [8.95, 9.12, 8.95, 8.85, 9.03, 8.84, 9.07, 8.98, 8.86, 8.98]
groups = [np.array(g) for g in (a, b, c)]
z = [np.abs(g - np.median(g)) for g in groups]
means = [g.mean() for g in z]
grand = np.concatenate(z).mean()
ss_between = sum(len(g) * (g.mean() - grand)**2 for g in z)
ss_within = sum(((g - g.mean())**2).sum() for g in z)
df_between = len(z) - 1
df_within = sum(len(g) for g in z) - len(z)
w = (ss_between / df_between) / (ss_within / df_within)
p = stats.f.sf(w, df_between, df_within)
print('distance means:', means)
print('sums of squares:', ss_between, ss_within)
print('independent calculation:', w, p)
print('SciPy:', stats.levene(*groups, center='median'))

In the output the distance means are about [0.061, 0.273, 0.073]; both the independent calculation and SciPy give a statistic of about 7.58495 and a p-value of about 0.00243151.

What the result can answer

At a 0.05 significance level, p ≈ 0.00243 supports rejecting equal population variances across the three groups. In the sample, group b’s larger distance mean and sample variance help make sense of the result; but this overall test itself does not identify which pair of population variances differs, nor does it test which group means differ.

In use, grouping and independence should match the study design, and one should consider how the sample was drawn from the target population. Median centering makes this version suitable when skewed distributions are a concern, but it does not remove the need for independent observations and sensible sampling.[1] A nonsignificant result only means the data are insufficient to reject equal variances at the chosen level; it does not prove the population variances are equal.

Comparing dispersion and comparing means are different questions. Clarify the research goal first, then choose the analysis; a variance-homogeneity test need not be a mandatory gate for every mean comparison.

References

  1. [1] SciPy. scipy.stats.levene. SciPy Manual.