Skip to content

Comparing spreads: classical variance tests

Sometimes spread is the question itself. Learn the F, Bartlett, Hartley and Cochran tests, why they fear non-normality, and why Levene-type tests travel better.

Applied ~12 min8 steps

What runs in CodeSplash

You will be able to

  • Test one variance against a target, with the chi-square test and Bonett's test
  • Explain why F, Bartlett and F-max are sensitive to non-normality
  • Use Levene-type tests, and a paired variance test for matched data

Read first

01

When spread is the question

Read

Consistency can matter more than the average: machine tolerances, lab precision, whether a new process narrows variation. Variance tests answer those questions directly.

Against a target σ0\sigma_0, the chi-square test uses:

χ2=(n−1) s2σ02,ν=n−1\chi^2 = \frac{(n-1)\, s^2}{\sigma_0^2}, \quad \nu = n - 1

Ten readings against σ0\sigma_0 = 1 give χ2\chi^2 = 3.40, p = .107.

02

Predict the danger

Predict

Predict first

The t test for means tolerates non-normality well in moderate samples. What happens to the chi-square test for a variance when the data have heavy tails, even with a large n?

It stays accurateIts error rate can be badly offIt only loses a little power
Reveal

Its error rate can be badly off, and more data doesn't fix it: the test's variance depends on the kurtosis. Bonett's test corrects for that. On a skewed sample with kurtosis 6.8, it gives z = 2.91, p = .004.

03

Two or more groups, assuming normality

Read

These tests are efficient if normality holds, and fragile if it doesn't:

TestStatisticNote
F tests12/s22s_1^2 / s_2^2Two groups, with a ratio interval
BartlettWeighted log-variance gapSeveral groups; sizes may differ
Hartley F-maxLargest ÷ smallest varianceEqual sizes
Cochran's CLargest variance's share of the totalFinds one outlying group

An F test on two groups gives a variance ratio of 2.62 (95% CI 0.65 to 10.53), p = .168. With 10 values per group, a ratio that large is compatible with equal spreads, and the interval is wide.

Across three groups with similar spreads, Bartlett gives p = .785, F-max p = .778 and Cochran's C p = .833.

04

Tests that travel

Read

Levene's idea: turn spread into a mean. Take each value's absolute distance from its group's center, and run an ANOVA on those distances:

zij=∣xij−x~j∣z_{ij} = |x_{ij} - \tilde x_j|
  • Center at the median: the Brown–Forsythe test, the robust default.
  • Center at the mean: Levene's original.
  • Center at a trimmed mean: a middle road.

On ToothGrowth, Brown–Forsythe gives F(1, 58) = 1.21, p = .275, with an SD ratio of 1.25.

05

Paired spreads

Reflect

If the same specimens went through two instruments, the variances aren't independent. The Pitman–Morgan test correlates sums with differences; zero correlation means equal variances.

Two instruments with variance ratio 2.62 and pair correlation 0.54 give t(8) = 1.68, p = .132.

Have you ever compared two instruments with an F test? What would pairing have changed?

06

Check your understanding

Checkpoint

Check yourself

A sample of 10 values has variance 8. Against a target variance of 4, what is the chi-square statistic?

Show the answer

Answer: 18

(n − 1) s² / σ0² = 9 × 8 / 4 = 18.

Check yourself

You want to compare the spread of three groups, and you aren't sure the data are normal. Which test is the sound default?

Show the answer

Answer: a

Median-centered Levene holds its error rate under non-normality. Bartlett and F-max can be far off.

Check yourself

Levene's test on two groups gives p = 0.30. May you now assume equal variances and use Student's t?

Show the answer

Answer: b

Use Welch by default. Run a variance test when spread is a question you care about, not as a gate.

Check yourself

How many degrees of freedom does the chi-square test for one variance have with 25 values?

Show the answer

Answer: 24

n − 1 = 24.

Check yourself

You're testing one variance, and your data have heavy tails. Which is the sound choice?

Show the answer

Answer: a

More data doesn't fix the chi-square test here, since its error rate depends on the kurtosis. Bonett's test corrects for that.

Check yourself

The same 20 specimens go through two instruments. Which test compares the instruments' spreads?

Show the answer

Answer: a

The F test and Bartlett's test need independent samples. Paired readings are correlated, and Pitman–Morgan allows for that.

Check yourself

Pitman–Morgan tests a correlation. Which one?

Show the answer

Answer: b

The covariance of x+yx + y and x−yx - y is σx2−σy2\sigma_x^2 - \sigma_y^2, so that correlation is zero exactly when the variances are equal.

Check yourself

Paired instruments have standard deviations of 3 and 2. What is their variance ratio?

Show the answer

Answer: 2.25

9 / 4 = 2.25. Tests of spread compare variances, so square the standard deviations first.

07

Do it in CodeSplash

In the app

Equal spread tests collects these under one Test list, grouped by what they assume. One-sample variance test and Paired variance test are separate methods. Hartley and Cochran use Simulated samples on the shared random stream, so Python and R agree.

Python
import pandas as pd
from scipy import stats

df = pd.read_csv("plantgrowth.csv")
groups = [g["weight"] for _, g in df.groupby("group")]
print(stats.levene(*groups, center="median"))  # Brown-Forsythe
print(stats.bartlett(*groups))
R
# install.packages("car")
car::leveneTest(weight ~ group, data = PlantGrowth, center = median)
bartlett.test(weight ~ group, data = PlantGrowth)
var.test(extra ~ group, data = sleep)
08

Recap

Recap
  • Test spread when spread is the question, not as a gate before a t test.
  • F, Bartlett, F-max and the chi-square test depend heavily on normality. Levene-type tests and Bonett's test don't.
  • Paired measurements need a paired variance test.

Concepts in this lesson