Skip to main content

Bartlett's Test

NIST/SEMATECH Section 1.3.5.7 Bartlett's Test

What It Is

Bartlett's test assesses whether several independent samples have equal variances, a condition known as homoscedasticity. It computes a test statistic based on the difference between the logarithm of the pooled variance and a weighted sum of logarithms of individual group variances, approximately following a chi-square distribution.

When to Use It

Use Bartlett's test before applying ANOVA or pooled t-tests to verify the equal-variance assumption. Violations of this assumption can inflate Type I error rates and produce misleading F-statistics. Bartlett's test is the most powerful test for homogeneity of variances when the data are normally distributed, making it the default choice for well-behaved data.

How to Interpret

If T exceeds the chi-square critical value at (k-1) degrees of freedom, reject the null hypothesis of equal variances. A large test statistic indicates that the group variances differ substantially. When the test is significant, consider using the Welch ANOVA or a non-parametric alternative instead of standard ANOVA. Note that Bartlett's test is highly sensitive to departures from normality -- even if variances are truly equal, non-normal data can produce false positives. For non-normal data, use the Levene test instead.

Assumptions and Limitations

Bartlett's test assumes that each sample is drawn from a normal distribution. It is sensitive to non-normality, which can cause inflated Type I error rates. The test requires at least two groups, each with at least two observations.

Reference: NIST/SEMATECH e-Handbook, Section 1.3.5.7

Formulas

Bartlett Test Statistic

T=(Nk)lnsp2j=1k(nj1)lnsj21+13(k1)(j=1k1nj11Nk)T = \frac{(N-k)\ln s_p^2 - \sum_{j=1}^{k}(n_j - 1)\ln s_j^2}{1 + \frac{1}{3(k-1)}\left(\sum_{j=1}^{k}\frac{1}{n_j - 1} - \frac{1}{N-k}\right)}

Compares the logarithm of the pooled variance to the weighted sum of logarithms of individual group variances. Under H0, T follows a chi-square distribution with k-1 degrees of freedom.

Pooled Variance

sp2=j=1k(nj1)sj2Nks_p^2 = \frac{\sum_{j=1}^{k}(n_j - 1)s_j^2}{N - k}

The combined variance estimate across all groups, weighted by degrees of freedom.

Python Example

import numpy as np
from scipy import stats
# Three groups of measurements
group1 = np.array([23.1, 24.3, 22.8, 23.9, 24.0, 23.5])
group2 = np.array([26.4, 25.9, 27.1, 26.3, 26.8, 25.7])
group3 = np.array([28.2, 27.5, 29.1, 28.0, 28.7, 27.9])
# Bartlett's test for equal variances
stat, p_value = stats.bartlett(group1, group2, group3)
print(f"Bartlett statistic: {stat:.4f}")
print(f"p-value: {p_value:.6f}")
print(f"Equal variances (alpha=0.05): {p_value > 0.05}")