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.
What runs in CodeSplash
- STAT090Chi square test for one variance Runs in CodeSplash
- STAT091F test for two variances Runs in CodeSplash
- STAT092Bartlett homogeneity of variance test Runs in CodeSplash
- STAT093Levene test Runs in CodeSplash
- STAT094Brown–Forsythe variance test Runs in CodeSplash
- STAT101Pitman–Morgan test Runs in CodeSplash
- STAT102Cochran C test Runs in CodeSplash
- STAT103Hartley F max test Runs in CodeSplash
- Equal spread tests Verified in Python and R
- One-sample variance test Verified in Python and R
- Paired variance test Verified in Python and R
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
When spread is the question
ReadConsistency 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 , the chi-square test uses:
Ten readings against = 1 give = 3.40, p = .107.
Predict the danger
PredictPredict 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?
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.
Two or more groups, assuming normality
ReadThese tests are efficient if normality holds, and fragile if it doesn't:
| Test | Statistic | Note |
|---|---|---|
| F test | Two groups, with a ratio interval | |
| Bartlett | Weighted log-variance gap | Several groups; sizes may differ |
| Hartley F-max | Largest ÷ smallest variance | Equal sizes |
| Cochran's C | Largest variance's share of the total | Finds 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.
Tests that travel
ReadLevene'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:
- 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.
Paired spreads
ReflectIf 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?
Check your understanding
CheckpointCheck 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 and is , 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.
Do it in CodeSplash
In the appEqual 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.
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))# install.packages("car")
car::leveneTest(weight ~ group, data = PlantGrowth, center = median)
bartlett.test(weight ~ group, data = PlantGrowth)
var.test(extra ~ group, data = sleep)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