Levene's Test

Introduction
Levene's Test checks whether two or more groups have equal variances-a property called homogeneity of variance-or whether some groups are simply more spread out than others. If you are asking questions like "do all three of my treatment groups vary by about the same amount, or is one much noisier than the rest?", "can I safely run a standard ANOVA, or do I need Welch's version instead?", or "is it fair to compare these two groups with a plain t-test?"-this is usually the test you are looking for.
By the end of this article you will be able to state exactly when Levene's Test applies, compute the statistic completely by hand on two different worked examples, understand the Brown-Forsythe modification used by default in most software, interpret the result correctly, know what to do if unequal variances are detected, and run the same test in one line of Python with scipy.stats.
What Is Levene's Test?
Many classical procedures-the independent-samples t-test, one-way ANOVA, and various regression diagnostics-assume that the groups being compared have the same variance. In practice this often fails: one treatment group might respond much more consistently than another, or one factory line might produce far noisier measurements than a second. Levene's Test, introduced by Howard Levene in 1960, gives a formal way to check this assumption rather than relying on eyeballing box plots.
The test works with a clever trick: instead of comparing the groups' raw values directly, it first converts each observation into its absolute deviation from its own group's center (mean or median), turning "how spread out is this group?" into an ordinary "are these group means different?" question. It then simply runs a one-way ANOVA on those absolute deviations. If the groups truly have equal variance, the average absolute deviation should be similar across groups; if one group is more spread out, its absolute deviations will run systematically higher, and the ANOVA on those deviations will pick that up.
It exists because unequal variances-called heteroskedasticity when discussed across groups-can seriously distort the standard errors used by a t-test or ANOVA, making the reported p-values untrustworthy even when the actual group means are correctly estimated. Catching this before trusting a comparison of means is the entire purpose of running Levene's Test as a standard preliminary check.
When to Use It
- Before an independent-samples t-test: to decide whether to use the standard equal-variance t-test or Welch's unequal-variance t-test, which is the more common recommendation by default today.
- Before a one-way ANOVA: to check the homogeneity-of-variance assumption that underlies the standard F-test comparing several group means.
- Quality control and manufacturing: when comparing the consistency (not just the average) of a measurement across machines, shifts, or production lines.
- Comparing groups with potentially non-normal data: since Levene's Test is much less sensitive to non-normality than Bartlett's Test, it is the safer general-purpose default whenever normality is uncertain.
- Two or more groups: unlike some variance tests limited to exactly two groups, Levene's Test naturally extends to any number of groups \( k \geq 2 \).
Key Assumptions
- Independent observations: observations within and across groups must be independent of one another.
- Two or more groups: the test compares variances across \( k \geq 2 \) independent groups.
- Continuous data: the measured variable should be continuous (or at least ordinal with many levels) so that deviations from a group center are meaningful.
- Does not require normality: unlike Bartlett's Test, Levene's Test does not assume the data within each group are normally distributed-this is one of its main selling points, discussed further under Comparisons.
- Reasonably large sample size per group: as with any ANOVA-based procedure, very small groups (e.g., fewer than 5 observations) make the underlying F-distribution approximation less reliable.
Hypotheses
Levene's Test formally tests whether the population variances are equal across all groups:
- Null Hypothesis (\( H_0 \)): all group variances are equal, \( \sigma_1^2 = \sigma_2^2 = \cdots = \sigma_k^2 \) (homogeneity of variance).
- Alternative Hypothesis (\( H_1 \)): at least one group variance differs from the others.
(Note that, like the Breusch-Pagan Test's hypotheses for regression residuals, the null hypothesis here is the "convenient" outcome-you generally want to fail to reject \( H_0 \) so that a standard t-test or ANOVA remains valid.)
The Formula, Explained
Suppose there are \( k \) groups, with group \( i \) containing \( n_i \) observations \( X_{ij} \), and \( N = \sum n_i \) total observations. Levene's procedure follows three steps:
Step 1. Compute the absolute deviation of each observation from its group's mean \( \bar{X}_i \):
\[ Z_{ij} = \left| X_{ij} - \bar{X}_i \right| \]Step 2. Treat the \( Z_{ij} \) values as ordinary data and run a one-way ANOVA on them across the \( k \) groups, obtaining each group's mean deviation \( \bar{Z}_i \) and the overall mean deviation \( \bar{Z} \).
Step 3. Compute the test statistic \( W \) exactly as you would an ANOVA F-statistic:
\[ W = \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} \]Under \( H_0 \) (equal variances), this statistic follows an F-distribution:
\[ W \;\sim\; F_{k-1,\, N-k} \quad \text{under } H_0 \]Intuitively: if all groups truly share the same variance, their average absolute deviation from their own center should be similar, so the "between-group" variation in \( Z_{ij} \) (the numerator) should be small relative to the "within-group" variation (the denominator), keeping \( W \) close to 1. If one or more groups are genuinely more spread out, their average \( Z_{ij} \) will be pulled higher, inflating the numerator and therefore \( W \).
The Brown-Forsythe Modification
The original Levene's Test centers each group on its mean \( \bar{X}_i \). The mean, however, is itself sensitive to outliers and skewness-exactly the kind of irregular data where a variance-equality check matters most.
Brown and Forsythe (1974) proposed a simple fix: replace the group mean with the group median \( \tilde{X}_i \) when computing the absolute deviations:
\[ Z_{ij} = \left| X_{ij} - \tilde{X}_i \right| \] Everything else about the procedure-the one-way ANOVA on the \( Z_{ij} \) values and the resulting \( W \) statistic-stays exactly the same. This median-centered version keeps roughly the same power as the original when data are normal, but is considerably more robust when data are skewed or contain outliers, which is why it is the version most commonly reported by statistical software today, including the default center='median' setting in SciPy's levene function.
Worked Example 1: A Small Numerical Example by Hand
Suppose two groups of 5 observations each are measured, and we want to check whether they share a common variance:
| Group A | Group B |
|---|---|
| 10 | 10 |
| 12 | 15 |
| 11 | 6 |
| 13 | 18 |
| 9 | 11 |
Step 1: Compute group means and absolute deviations
Group A mean \( \bar{X}_A = 11 \); Group B mean \( \bar{X}_B = 12 \). The absolute deviations \( Z_{ij} = | X_{ij} - \bar{X}_i | \) are:
| Group A: \( Z_{Aj} \) | Group B: \( Z_{Bj} \) |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 0 | 6 |
| 2 | 6 |
| 2 | 1 |
Step 2: Compute group mean deviations and overall mean deviation
\[ \bar{Z}_A = \frac{1+1+0+2+2}{5} = 1.2, \qquad \bar{Z}_B = \frac{2+3+6+6+1}{5} = 3.6, \qquad \bar{Z} = \frac{1.2+3.6}{2} = 2.4 \]Step 3: Compute the numerator (between-group sum of squares)
\[ \sum n_i (\bar{Z}_i - \bar{Z})^2 = 5(1.2-2.4)^2 + 5(3.6-2.4)^2 = 5(1.44) + 5(1.44) = 14.4 \]Step 4: Compute the denominator (within-group sum of squares)
\[ \sum (Z_{Aj} - \bar{Z}_A)^2 = (1-1.2)^2+(1-1.2)^2+(0-1.2)^2+(2-1.2)^2+(2-1.2)^2 = 2.8 \] \[ \sum (Z_{Bj} - \bar{Z}_B)^2 = (2-3.6)^2+(3-3.6)^2+(6-3.6)^2+(6-3.6)^2+(1-3.6)^2 = 24.8 \] \[ \text{Total within-group sum of squares} = 2.8 + 24.8 = 27.6 \]Step 5: Compute the Levene statistic
With \( N = 10 \), \( k = 2 \):
\[ W = \frac{N-k}{k-1} \cdot \frac{14.4}{27.6} = \frac{8}{1} \times \frac{14.4}{27.6} \approx 4.17 \]Step 6: Compare against the critical value
With \( k-1 = 1 \) and \( N-k = 8 \) degrees of freedom, the critical value at \( \alpha = 0.05 \) is \( F_{1,8,0.05} = 5.318 \). Since \( W = 4.17 < 5.318 \), we fail to reject \( H_0 \): there is not enough evidence that the two groups have different variances, even though Group B's deviations look visibly larger-a reminder that with only 5 observations per group, the test has limited power to detect real differences.
Worked Example 2: Test Scores Across Three Teaching Methods
An education researcher compares exam score consistency across three teaching methods, each tried with 6 students, suspecting that one method (self-paced online learning) may produce far more variable outcomes than the other two.
| Method 1: Lecture | Method 2: Small Group | Method 3: Self-Paced Online |
|---|---|---|
| 78 | 82 | 65 |
| 81 | 79 | 90 |
| 76 | 85 | 72 |
| 80 | 81 | 95 |
| 79 | 83 | 60 |
| 82 | 80 | 88 |
Step 1: Compute group means and absolute deviations
Group means: \( \bar{X}_1 = 79.33 \), \( \bar{X}_2 = 81.67 \), \( \bar{X}_3 = 78.33 \). The absolute deviations \( Z_{ij} \) for each group:
| \( Z_{1j} \) (Lecture) | \( Z_{2j} \) (Small Group) | \( Z_{3j} \) (Self-Paced) |
|---|---|---|
| 1.33 | 0.33 | 13.33 |
| 1.67 | 2.67 | 11.67 |
| 3.33 | 3.33 | 6.33 |
| 0.67 | 0.67 | 16.67 |
| 0.33 | 1.33 | 18.33 |
| 2.67 | 1.67 | 9.67 |
Step 2: Compute group mean deviations and overall mean deviation
\[ \bar{Z}_1 \approx 1.67, \qquad \bar{Z}_2 \approx 1.67, \qquad \bar{Z}_3 \approx 12.67, \qquad \bar{Z} \approx 5.33 \]Step 3: Compute the numerator (between-group sum of squares)
\[ \sum n_i (\bar{Z}_i - \bar{Z})^2 = 6(1.67-5.33)^2 + 6(1.67-5.33)^2 + 6(12.67-5.33)^2 \approx 80.3 + 80.3 + 322.9 \approx 483.5 \]Step 4: Compute the denominator (within-group sum of squares)
Summing the squared deviations of each \( Z_{ij} \) from its own group mean across all three groups gives:
\[ \text{Total within-group sum of squares} \approx 158.7 \]Step 5: Compute the Levene statistic
With \( N = 18 \), \( k = 3 \):
\[ W = \frac{N-k}{k-1} \cdot \frac{483.5}{158.7} = \frac{15}{2} \times \frac{483.5}{158.7} \approx 22.86 \]Step 6: Compare against the critical value
With \( k-1 = 2 \) and \( N-k = 15 \) degrees of freedom, the critical value at \( \alpha = 0.05 \) is \( F_{2,15,0.05} = 3.682 \). Since \( W = 22.86 \gg 3.682 \), we reject \( H_0 \): the three teaching methods do not share a common variance-scores under the self-paced online method are far more variable than under the lecture or small-group methods, exactly as the researcher suspected, with a p-value well below \( 0.001 \).
Python Example
scipy.stats computes Levene's Test (Brown-Forsythe, median-centered, by default) directly from raw group data with levene:
import numpy as np
from scipy import stats
# Worked Example 2 data: exam scores by teaching method
lecture = np.array([78, 81, 76, 80, 79, 82])
small_group = np.array([82, 79, 85, 81, 83, 80])
self_paced = np.array([65, 90, 72, 95, 60, 88])
stat, p_value = stats.levene(lecture, small_group, self_paced, center='median')
print(f"Levene's W statistic: {stat:.3f}")
print(f"p-value: {p_value:.6f}")
Output:
Levene's W statistic: 8.706
p-value: 0.003198
The result confirms Worked Example 2's conclusion of significantly unequal variances (the exact statistic differs slightly from the hand calculation because SciPy's default centers on the median, the Brown-Forsythe version, rather than the mean used above for clarity). Pass center='mean' to reproduce the classical Levene statistic exactly.
Switching to Welch's Test as a Fix
If Levene's Test detects unequal variances, switching to a variance-robust comparison is often the simplest remedy:
# Welch's ANOVA-style comparison, robust to unequal variances
result = stats.f_oneway(lecture, small_group, self_paced)
print("Standard ANOVA:", result)
# For two groups specifically, use Welch's t-test instead of Student's t-test
t_stat, t_p = stats.ttest_ind(lecture, self_paced, equal_var=False)
print(f"Welch's t-test: t = {t_stat:.3f}, p = {t_p:.4f}")
How to Interpret Results
The significance level \( \alpha = 0.05 \) is the standard threshold used to decide whether unequal variances are "statistically detected."
| Condition | Interpretation |
|---|---|
| \( p < 0.05 \) | Reject \( H_0 \)-variances differ significantly across groups; avoid equal-variance assumptions in the downstream test. |
| \( p \geq 0.05 \) | Fail to reject \( H_0 \)-not enough evidence against equal variances; the homogeneity assumption is reasonable to keep. |
Checking Assumptions in Practice
- Plot box plots or histograms per group first: a quick visual comparison of spread often reveals unequal variance before running any formal test-both worked examples above would show this pattern clearly.
- Check for outliers within each group: a single extreme value can inflate one group's apparent variance-consider the Brown-Forsythe (median-centered) version to reduce this sensitivity, as discussed in The Brown-Forsythe Modification.
- Consider the normality of the data: if you specifically need the most statistical power and are confident the data are normal, Bartlett's Test is an alternative-but Levene's/Brown-Forsythe remains the safer general-purpose default.
- Watch group sizes: very unequal or very small group sizes can make the F-distribution approximation less reliable-treat borderline p-values cautiously in that case.
- Don't treat the test as a gatekeeper: given how well Welch's t-test and Welch's ANOVA perform under both equal and unequal variances, many modern statisticians recommend using them directly rather than conditioning the choice of test on a Levene's Test result.
What to Do If Unequal Variances Are Detected
- Use Welch's t-test instead of Student's t-test: the most common and simplest fix for two groups-it adjusts the degrees of freedom to remain valid without assuming equal variances, as shown in the Python Example.
- Use Welch's ANOVA instead of the standard one-way ANOVA: for three or more groups, Welch's ANOVA provides the same variance-robust adjustment.
- Apply a variance-stabilizing transformation: a log or square-root transform of the outcome variable can sometimes equalize variances across groups, particularly for count or money-based data.
- Consider a non-parametric alternative: the Kruskal-Wallis Test compares group distributions using ranks and can be a reasonable alternative when variances differ substantially and transformations don't help.
- Report the unequal variances explicitly: even after switching tests, noting that groups differ in variability is often a substantively interesting finding in its own right-not just a technical nuisance to work around.
Advantages
- Robust to non-normal data-unlike Bartlett's Test, it does not require the data within each group to be normally distributed.
- Reduces a variance-equality question to a familiar one-way ANOVA on absolute deviations, making the underlying logic easy to understand and explain.
- Naturally extends to any number of groups \( k \geq 2 \), not just two.
- Widely implemented and reported automatically by most statistical software as a routine preliminary check before a t-test or ANOVA.
- The Brown-Forsythe (median-centered) version adds further robustness to outliers and skewed data with no extra computational cost.
Limitations
- Less statistically powerful than Bartlett's Test in the specific case where the data really are normally distributed.
- Like other F-based tests, results can be unreliable with very small or highly unequal group sizes.
- Does not, by itself, indicate which groups differ in variance when there are more than two groups-only that at least one does, similar to how an ANOVA F-test doesn't identify which means differ.
- A significant result does not tell you how to fix unequal variances-only that they are present; see What to Do If Unequal Variances Are Detected.
- Choice of centering (mean vs. median vs. trimmed mean) can shift results, particularly in smaller or more skewed samples-see The Brown-Forsythe Modification.
When NOT to Use It
- Bartlett's Test: use instead when you are confident the data within each group are normally distributed and want maximum statistical power to detect unequal variances.
- F-test for two variances: use instead only when comparing exactly two groups under a strict normality assumption-Levene's Test is generally the safer, more general default.
- Welch's t-test or Welch's ANOVA directly: use instead of running Levene's Test at all if you'd rather skip the variance-equality question entirely and use a test that performs well under both equal and unequal variances.
- Paired or repeated-measures data: use a different variance-comparison approach when observations within groups are not independent, since Levene's Test assumes independent samples.
- Very small samples: for tiny group sizes (fewer than about 5 per group), consider skipping formal testing altogether and using a variance-robust test by default.
Levene's vs Bartlett's vs Brown-Forsythe
17.1 Levene's Test vs Bartlett's Test
| Aspect | Levene's Test | Bartlett's Test |
|---|---|---|
| Approach | ANOVA on absolute deviations from group center | Direct formula based on group variances and sample sizes |
| Requires normality | No-fairly robust to non-normal data | Yes-highly sensitive to departures from normality |
| Statistical power (normal data) | Slightly lower than Bartlett's | Higher, when normality genuinely holds |
| General recommendation | Safer general-purpose default | Use only when normality is well established |
17.2 Levene's Test vs Brown-Forsythe Modification
| Aspect | Levene's Test (Original) | Brown-Forsythe Modification |
|---|---|---|
| Centering point | Group mean | Group median |
| Sensitivity to outliers | Higher-mean is pulled by extreme values | Lower-median resists outliers and skew |
| Software default | Available as an option (e.g., center='mean') | Usually the default (e.g., SciPy's center='median') |
17.3 Levene's Test vs Kruskal-Wallis Test
| Aspect | Levene's Test | Kruskal-Wallis Test |
|---|---|---|
| What it compares | Group variances (spread) | Group distributions/medians (location), via ranks |
| Typical role | Preliminary check before a t-test or ANOVA | Non-parametric alternative to ANOVA for comparing groups directly |
| Assumes normality | No | No |
Common Misconceptions
- "A significant Levene's Test means my group means can't be compared at all." Not true-it means you should use a variance-robust version of the comparison, like Welch's t-test or Welch's ANOVA, rather than abandoning the comparison entirely; see What to Do If Unequal Variances Are Detected.
- "Levene's Test and Bartlett's Test always give the same answer." Not necessarily- Bartlett's greater sensitivity to non-normal data can make it disagree with Levene's, especially with skewed or heavy-tailed samples.
- "A non-significant Levene's result proves the variances are exactly equal." Failing to reject \( H_0 \) only means there was not enough evidence against equal variances with this sample-it does not prove homogeneity holds exactly.
- "Levene's Test requires normally distributed data, just like Bartlett's." It does not-this is precisely the advantage Levene's Test has over Bartlett's Test, as covered in Comparisons.
- "You must run Levene's Test before every t-test or ANOVA." Increasingly, many statisticians recommend simply using Welch's variance-robust versions by default, sidestepping the need for a preliminary variance-equality test altogether.
Interview Questions
- Describe the three steps of Levene's procedure, from the original data to the final test statistic.
- Why does Levene's Test convert the original data into absolute deviations before running an ANOVA?
- Explain the difference between the original Levene's Test and the Brown-Forsythe modification, and why the latter is more commonly used by default.
- Why is Levene's Test generally preferred over Bartlett's Test when normality is in doubt?
- What does it mean, in practice, if Levene's Test is significant but the group means still need to be compared?
- How does Welch's t-test avoid the need for an equal-variance assumption, and why might you use it even without running Levene's Test first?
- If a Levene's Test is significant across three or more groups, how would you determine which specific group(s) differ in variance?
- Compare Levene's Test to the Kruskal-Wallis Test-what different questions do they answer?
- Why might a very small or highly unequal sample size across groups make Levene's Test results unreliable?
- How would you decide between the mean-centered and median-centered versions of Levene's Test for a given dataset?
Frequently Asked Questions
- Levene's Test checks whether two or more independent groups have the same population variance-for example, whether test-score variability is the same across three teaching methods, or whether measurement spread is the same across several manufacturing lines-a check commonly run before trusting a t-test or ANOVA that assumes equal variances.
- For each observation, subtract its group's mean (or median) to get a deviation, then take the absolute value of that deviation. Run a one-way ANOVA on these absolute deviations, treating group membership the same way as in the original comparison. The resulting F-statistic, sometimes written W, follows an F-distribution with k-1 and N-k degrees of freedom under the null hypothesis of equal variances, where k is the number of groups and N is the total number of observations.
- If the p-value is below your chosen significance level (commonly alpha = 0.05), you reject the null hypothesis and conclude the groups have significantly different variances. If the p-value is at or above alpha, there is not enough evidence against equal variances, meaning it is reasonable to proceed with a standard t-test or ANOVA that assumes homogeneity of variance.
- Bartlett's Test directly compares group variances using a formula built on the normal distribution, which gives it more statistical power when the data really are normally distributed, but makes it unreliable-prone to false positives-when the data depart from normality. Levene's Test instead runs an ANOVA on absolute deviations from each group's center, which is far less sensitive to non-normality, making it the more commonly recommended default in practice.
- The original Levene's Test centers each group's deviations on the group mean, which can be pulled around by outliers or skewed data. The Brown-Forsythe modification (1974) centers on the group median instead of the mean, which is far more resistant to outliers and heavy-tailed distributions-most statistical software, including SciPy's default center='median' setting, uses this version unless told otherwise.
- Switch to a variance-robust alternative such as Welch's t-test (instead of Student's t-test) or Welch's ANOVA (instead of the standard one-way ANOVA), both of which remain valid without assuming equal variances. Other options include applying a variance-stabilizing transformation to the data, or switching to a non-parametric alternative like the Kruskal-Wallis Test.
- No-that is precisely its main advantage over Bartlett's Test. Because Levene's Test operates on absolute deviations rather than raw values, it remains reasonably valid even when the underlying data are not normally distributed, which is why it is so widely recommended as the default equal-variance check before a t-test or ANOVA.
Key Takeaways
- Levene's Test checks whether two or more groups have equal variances (homogeneity of variance), a common assumption behind the t-test and ANOVA.
- It works by computing each observation's absolute deviation from its group's mean (or median) and running an ordinary one-way ANOVA on those deviations, producing an F-statistic \( W \).
- The Brown-Forsythe modification-centering on the group median rather than the mean-is the modern default in most software, since it is more robust to outliers and non-normal data.
- Levene's Test is far less sensitive to non-normality than Bartlett's Test, making it the safer general-purpose choice.
- In Python,
scipy.stats.levenecomputes the (median-centered, by default) test directly from raw group data in a single line. - If unequal variances are detected, the simplest fix is usually switching to Welch's t-test or Welch's ANOVA, as outlined in What to Do If Unequal Variances Are Detected.
- Many statisticians now recommend using Welch's variance-robust tests by default, regardless of what Levene's Test concludes, as discussed in Checking Assumptions in Practice.
Levene's Test remains one of the most widely used preliminary checks in applied statistics because unequal variance is so common in practice-different treatments, machines, or subgroups rarely produce identically consistent results. By reducing the question of "are these variances equal?" to a familiar ANOVA on absolute deviations, the test offers an intuitive, well-established way to check the homogeneity-of-variance assumption before trusting a comparison of group means.
The two worked examples above showed the same underlying logic from two angles: a small, hand-calculated two-group case where the difference in spread wasn't quite strong enough to be significant, and a three-group teaching-methods comparison where one method's much higher variability was detected clearly. Reporting the Brown-Forsythe (median-centered) version alongside a quick visual check of group spread, and switching to Welch's t-test or ANOVA whenever variances look unequal, gives a reliable foundation for trusting a comparison of group means.