F-Test for Equality of Variances

Hypothesis TestingParametric TestsFree Lesson

Advertisement

F-Test for Equality of Variances

Tests H₀: σ₁² = σ₂² using the ratio of sample variances.

F=s12s22,df1=n11,df2=n21F = \frac{s_1^2}{s_2^2}, \quad df_1 = n_1-1, \quad df_2 = n_2-1

Under H₀, F follows an F-distribution with (n₁−1, n₂−1) degrees of freedom.

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"
Levene'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

TestNormality RequiredRobustUse When
F-test✅ Yes (strictly)❌ NoPerfect normality
Levene's❌ No✅ YesDefault choice
Bartlett's✅ Yes (approximately)ModerateLarge samples, near-normal
Brown-Forsythe❌ No✅ YesHeavy tails

Key Takeaways

  1. Use Levene's test as the default — it doesn't require normality
  2. F-test is sensitive to non-normality — type I error inflates severely
  3. Variance tests matter before ANOVA — need to confirm homogeneity of variances
  4. Large variance ratio (F >> 1 or F << 1) suggests unequal population variances
  5. Follow-up with Welch's t-test if variances are unequal

Advertisement

Need Expert Statistics Help?

Get personalized tutoring, dissertation support, or statistical consulting.

Advertisement