πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Levene's Test for Homogeneity of Variances

Hypothesis TestingParametric Tests🟒 Free Lesson

Advertisement

Levene's Test

Hypothesis Testing

The Robust Alternative to the F-Test

Levene's test checks for equal variances across groups without assuming normality, making it more reliable than the F-test in practice. It is the standard method for verifying homoscedasticity before ANOVA.

  • ANOVA Preparation β€” Checking assumptions before running analysis of variance
  • Quality Engineering β€” Assessing process stability across multiple production lines
  • Psychology Research β€” Verifying variance homogeneity in experimental designs

When normality is uncertain, Levene's test provides reliable variance checking.


Levene's test checks whether k groups have equal population variances (homoscedasticity). Unlike the F-test, it doesn't assume normality.

Levene's Test Statistic

W=(Nβˆ’k)(kβˆ’1)β‹…βˆ‘i=1kni(ZΛ‰i.βˆ’ZΛ‰..)2βˆ‘i=1kβˆ‘j=1ni(Zijβˆ’ZΛ‰i.)2W = \frac{(N-k)}{(k-1)} \cdot \frac{\sum_{i=1}^k n_i (\bar{Z}_{i.} - \bar{Z}_{..})^2}{\sum_{i=1}^k \sum_{j=1}^{n_i} (Z_{ij} - \bar{Z}_{i.})^2}

Here,

  • WW=Levene's test statistic
  • NN=Total number of observations
  • kk=Number of groups
  • nin_i=Number of observations in group i
  • ZijZ_{ij}=|Y_{ij} βˆ’ Θ²_{i.}| (absolute deviations from group means)

Python Implementation

Levene's Test in Python

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

np.random.seed(42)

# Compare 3 groups for ANOVA β€” check variance assumption first
group_a = np.random.normal(50, 5, 30)
group_b = np.random.normal(55, 5, 28)
group_c = np.random.normal(48, 8, 32)  # larger variance

# Levene's test
stat, p = stats.levene(group_a, group_b, group_c)
print(f"Levene's Test for 3 Groups:")
print(f"W = {stat:.4f}, p = {p:.4f}")
print(f"Groups have {'equal' if p > 0.05 else 'UNEQUAL'} variances (Ξ±=0.05)")

Visualization

# Visualize variance differences
fig, ax = plt.subplots(figsize=(8, 5))
ax.boxplot([group_a, group_b, group_c], labels=['Group A', 'Group B', 'Group C'],
           patch_artist=True)
ax.set_title(f"Group Variance Comparison\nLevene's: W={stat:.3f}, p={p:.4f}")
ax.set_ylabel('Values')
for i, (g, label) in enumerate(zip([group_a, group_b, group_c], ['A','B','C']), 1):
    ax.text(i, g.max()+0.5, f'SD={g.std(ddof=1):.2f}', ha='center', fontsize=9)
plt.tight_layout()
plt.savefig('levenes_test.png', dpi=150)
plt.show()

What To Do If Variances Are Unequal

If Levene's is Significant (p < 0.05)

  • Use Welch's ANOVA (one-way): stats.f_oneway is not appropriate
  • Or use Kruskal-Wallis nonparametric test

Key Takeaways

Summary: Levene's Test

  • Levene's test uses absolute deviations, making it robust to non-normality
  • Brown-Forsythe uses median deviations β€” even more robust
  • p greater than 0.05 -> fail to reject equal variances -> proceed with standard ANOVA
  • p less than 0.05 -> use Welch's ANOVA or nonparametric alternative
  • ANOVA is fairly robust to moderate variance inequality when group sizes are equal
⭐

Premium Content

Levene's Test for Homogeneity of Variances

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement