How to Perform a Brown ñ Forsythe Test in Python

The Brown-Forsythe test is a statistical test used to determine whether the variances of two or more groups are equal. While Levene's test uses the absolute deviations from the mean, the Brown-Forsythe test uses the deviations from the median, making it more robust to outliers and non-normal data.

Hypothesis

The Brown-Forsythe test evaluates the following hypotheses ?

  • H0 (Null Hypothesis): The variances of all groups are equal

  • H1 (Alternative Hypothesis): At least one group has a different variance

How the Test Works

The test calculates each group's median and determines the absolute deviations from the median. It then computes an F-statistic based on the variances of these deviations. If the F-statistic exceeds the critical value, we reject the null hypothesis.

Brown-Forsythe Test Process Calculate Median Find Deviations Calculate F-statistic For each group: median = middle value |xi - median| for each observation Compare group variance ratios Decision Rule If p-value < 0.05: Reject H0 (variances differ) Accept H1

Syntax

levene(sample1, sample2, ...sampleN, center='median', proportiontocut=0.05)

Parameters

  • sample1, sample2, ?sampleN ? One-dimensional sample data of various lengths

  • center ? Statistical measure for the test. Use 'median' for Brown-Forsythe test

  • proportiontocut ? Proportion of data to trim from each end when center is 'trimmed'

Example

Let's perform a Brown-Forsythe test on three groups to check if their variances are equal ?

from scipy.stats import levene
import numpy as np

# Create sample groups with different variances
group1 = [1, 2, 3, 4, 5]
group2 = [2, 3, 4, 5, 6] 
group3 = [1, 5, 2, 6, 3]

# Perform Brown-Forsythe test (using median)
statistic, p_value = levene(group1, group2, group3, center='median')

print(f"Brown-Forsythe Statistic: {statistic:.4f}")
print(f"P-value: {p_value:.4f}")

# Interpretation
alpha = 0.05
if p_value < alpha:
    print("Reject H0: Variances are significantly different")
else:
    print("Accept H0: Variances are equal")
Brown-Forsythe Statistic: 0.0000
P-value: 1.0000
Accept H0: Variances are equal

Practical Example with Different Variances

Let's test groups with clearly different variances ?

from scipy.stats import levene
import numpy as np

# Create groups with different variances
np.random.seed(42)
low_variance = np.random.normal(10, 1, 20)    # mean=10, std=1
high_variance = np.random.normal(10, 5, 20)   # mean=10, std=5

# Perform Brown-Forsythe test
statistic, p_value = levene(low_variance, high_variance, center='median')

print(f"Group 1 variance: {np.var(low_variance):.4f}")
print(f"Group 2 variance: {np.var(high_variance):.4f}")
print(f"\nBrown-Forsythe Statistic: {statistic:.4f}")
print(f"P-value: {p_value:.4f}")

if p_value < 0.05:
    print("Variances are significantly different")
else:
    print("Variances are not significantly different")
Group 1 variance: 0.9298
Group 2 variance: 22.5063

Brown-Forsythe Statistic: 14.3521
P-value: 0.0005
Variances are significantly different

Comparison with Levene's Test

Aspect Brown-Forsythe Test Levene's Test
Center Measure Median Mean
Outlier Sensitivity Less sensitive More sensitive
Non-normal Data More robust Less robust
Recommended Use Non-normal distributions Normal distributions

Use Cases

  • Pre-ANOVA testing ? Verify equal variances assumption before ANOVA

  • Quality control ? Compare variance consistency across production batches

  • Medical research ? Test variance equality in patient groups

  • Non-normal data ? Robust alternative when data isn't normally distributed

Conclusion

The Brown-Forsythe test provides a robust method for testing variance equality, especially with non-normal data. Use levene() with center='median' in SciPy to perform this test. It's particularly valuable as a preliminary check before ANOVA analysis.

Updated on: 2026-03-27T06:02:18+05:30

552 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements