F-Test for Equality of Variances
Hypothesis Testing
Testing Whether Groups Differ in Variability
The F-test for variances evaluates whether two populations have equal spread, a critical assumption for many statistical procedures. Understanding variance equality is essential for choosing appropriate analysis methods.
- Quality Control β Comparing consistency of different manufacturing processes
- Finance β Assessing whether investment portfolios have different risk levels
- Agricultural Research β Testing uniformity of crop yields across treatments
The F-test for variances is the prerequisite for comparing means.
Tests Hβ: ΟβΒ² = ΟβΒ² using the ratio of sample variances.
F-Test Statistic
Here,
- =The F-test statistic
- =Sample variance of group 1
- =Sample variance of group 2
- =Degrees of freedom for each group
Under Hβ, F follows an F-distribution with (nββ1, nββ1) degrees of freedom.
Python Implementation
F-Test and Alternatives
import numpy as np
from scipy import stats
np.random.seed(42)
group1 = np.random.normal(50, 8, 25) # Ο=8
group2 = np.random.normal(52, 12, 30) # Ο=12
# F-test
F = group1.var(ddof=1) / group2.var(ddof=1)
df1, df2 = len(group1)-1, len(group2)-1
# Two-tailed p-value
p_upper = stats.f.sf(F, df1, df2)
p_lower = stats.f.cdf(F, df1, df2)
p_value = 2 * min(p_upper, p_lower)
print(f"sβΒ² = {group1.var(ddof=1):.4f}, sβΒ² = {group2.var(ddof=1):.4f}")
print(f"F({df1}, {df2}) = {F:.4f}")
print(f"p-value = {p_value:.4f}")
# Levene's test (more robust β doesn't require normality)
stat_lev, p_lev = stats.levene(group1, group2)
print(f"\nLevene's test: F={stat_lev:.4f}, p={p_lev:.4f}")
print("(Levene's is preferred β robust to non-normality)")
# Bartlett's test (sensitive to normality)
stat_bart, p_bart = stats.bartlett(group1, group2)
print(f"Bartlett's test: ΟΒ²={stat_bart:.4f}, p={p_bart:.4f}")
print("(Bartlett's is more powerful when normality holds)")
Choosing the Right Test
Which Variance Test to Use?
| Test | Normality Required | Robust | Use When |
|---|---|---|---|
| F-test | β Yes (strictly) | β No | Perfect normality |
| Levene's | β No | β Yes | Default choice |
| Bartlett's | β Yes (approximately) | Moderate | Large samples, near-normal |
| Brown-Forsythe | β No | β Yes | Heavy tails |
Key Takeaways
Summary: F-Test for Equality of Variances
- Use Levene's test as the default β it doesn't require normality
- F-test is sensitive to non-normality β type I error inflates severely
- Variance tests matter before ANOVA β need to confirm homogeneity of variances
- Large variance ratio (F greater than 1 or F << 1) suggests unequal population variances
- Follow-up with Welch's t-test if variances are unequal