Sub topic 8
Checking whether variances are equal
This chapter assumes you can compute a standard deviation, you have met the p-value decision rule, and you have already checked normality for your groups. It covers how to test whether two or more groups have the same spread, and what to do with the answer.
Why spread matters
Variance is the square of the standard deviation. It measures how widely individual values scatter around their group mean. Two machines can fill bottles to the same average volume while one machine is far less consistent than the other. In the Analyze phase, a difference in spread is often a finding in its own right. It can point to an unstable input, an operator effect, or a worn fixture.
Equal variance also matters for choosing a test. The classic pooled two-sample t-test and one-way ANOVA both combine the groups' variances into a single estimate. That is valid only if the groups share one true variance. When they do not, the pooled estimate misrepresents each group, and the p-value can be wrong. The error is worst when group sizes are unequal.
The hypotheses
Every equal-variance test uses the same pair of hypotheses:
- Null hypothesis (H0): all groups have the same variance.
- Alternative hypothesis (H1): at least one group has a different variance.
A small p-value is evidence of unequal variances. A large p-value means you did not find evidence of a difference. It does not prove the variances are equal. With 8 observations per group, a test has little power to detect even a doubling of the standard deviation.
Which test to use
| Test | Assumes normal data? | Number of groups | Notes |
|---|---|---|---|
| F-test for two variances | Yes, strongly | 2 | Very sensitive to non-normality |
| Bartlett's test | Yes, strongly | 2 or more | Powerful when data are normal, unreliable when they are not |
| Levene's test (mean-centered) | No | 2 or more | Moderately robust |
| Brown-Forsythe (Levene with median) | No | 2 or more | The usual default for real process data |
Bartlett's test and the F-test treat any departure from normality as a variance difference. Skewed or heavy-tailed data can give a small p-value even when the true variances are equal. Levene's test works on each observation's absolute distance from its group center, so it does not depend on normality in the same way.
Statistical packages differ in the default. Minitab labels the median-centered version "Levene's test" in some menus. In SciPy, stats.levene defaults to center="median", which is the Brown-Forsythe variant.
Running the tests
The following example builds three production lines with the same mean and different spread. It prints the sample standard deviations first, because a test result should always be read alongside the numbers.
import numpy as np
from scipy import stats
rng = np.random.default_rng(11)
line_a = rng.normal(100, 2.0, 30)
line_b = rng.normal(100, 4.0, 30)
line_c = rng.normal(100, 2.2, 30)
groups = {"A": line_a, "B": line_b, "C": line_c}
for name, values in groups.items():
print(name, "sd =", round(values.std(ddof=1), 2))
lev = stats.levene(line_a, line_b, line_c, center="median")
bart = stats.bartlett(line_a, line_b, line_c)
print("Levene (median) p =", lev.pvalue)
print("Bartlett p =", bart.pvalue)ddof=1 gives the sample standard deviation. Without it, NumPy divides by n instead of n - 1 and understates the spread.
With data this close to normal, both tests usually agree. They can disagree on skewed data. The next example draws from a skewed distribution, and the two groups have the same underlying scale parameter, so any difference in spread comes only from skew and sampling variation.
import numpy as np
from scipy import stats
rng = np.random.default_rng(3)
cycle_1 = rng.lognormal(mean=3.0, sigma=0.5, size=40)
cycle_2 = rng.lognormal(mean=3.0, sigma=0.5, size=40)
print("Bartlett p =", stats.bartlett(cycle_1, cycle_2).pvalue)
print("Levene p =", stats.levene(cycle_1, cycle_2, center="median").pvalue)Run this with several seeds. Bartlett's test rejects equal variances far more often than the 5% you would expect from two samples of identical distribution, and Levene's test stays closer to 5%. That inflated false-alarm rate is why Bartlett's test is a poor choice for the skewed data common in cycle times and defect counts.
What to do with the result
The test result changes which downstream test you run. The decision depends on whether you are comparing two groups or several.
For two groups, the Welch t-test is a safe default and many practitioners use it every time. It does not assume equal variances, and it loses very little power when the variances are in fact equal. Using it removes the need for a preliminary test and avoids the problems of testing twice.
For three or more groups, standard ANOVA is fairly tolerant of mild variance differences when group sizes are equal or nearly equal. It is much less tolerant when the sizes are unequal, and especially when the group with the smallest sample has the largest variance. In that case use Welch's ANOVA, or a rank-based test such as Kruskal-Wallis. Note that Kruskal-Wallis tests whether the distributions differ in location only if their shapes and spreads are similar.
Edge cases and common mistakes
- Treating a large p-value as proof. A p-value of 0.30 from Levene's test with 10 observations per group does not show that the variances are equal. Look at the ratio of the standard deviations as well. A ratio above about 2 deserves attention regardless of the p-value.
- Large samples flag trivial differences. With thousands of observations, Levene's test can reject for a standard deviation difference of 3%. Judge whether the difference is large enough to change the t-test or ANOVA result. A box plot or an interval plot makes this visible.
- Outliers and one-off events. A single extreme value inflates one group's variance and can trigger a rejection. Check it against the process log before deciding whether to remove it. Do not remove it only because the test fails.
- Testing the wrong thing. Levene's test compares variances across groups defined by the X. It does not check that residuals from a regression have constant variance. For regression, check a residual plot against the fitted values.
- Pre-testing then choosing. Running a variance test and then picking the t-test based on its p-value means your final test has an error rate that is not exactly the one you set. This is a small effect, but it is one more reason to default to Welch.
- Reporting only the p-value. Report the group standard deviations and the test used. A reader cannot judge a p-value for "variance equality" without the numbers behind it.
Summary of the workflow
- Plot each group and compute its sample standard deviation.
- Choose Levene's test with the median unless normality is clearly satisfied.
- Read the p-value against your significance level and look at the ratio of standard deviations.
- If the variances differ, use Welch's t-test or Welch's ANOVA, and report the spread difference as a finding.
- If they do not, either test is acceptable, and Welch remains a safe choice.
Exercise
Two shifts each produce 12 parts. Shift 1 has a standard deviation of 1.0 mm and shift 2 has 2.5 mm. Levene's test gives p = 0.09 at alpha = 0.05. A teammate says "the variances are equal, so we can use the pooled t-test." What would you say, and what test would you run?
Show answer
A p-value of 0.09 only means the test did not find evidence of a difference. With 12 parts per shift the test has low power, and the standard deviation ratio is 2.5, which is large. The variances should not be assumed equal. Run Welch's t-test, which does not require equal variances, and report the standard deviations alongside the result.
Exercise
Why is Levene's test with the median usually preferred to Bartlett's test for cycle-time data?
Show answer
Cycle-time data are typically right-skewed. Bartlett's test is sensitive to non-normality and rejects equal variances too often on skewed data, even when the true variances are equal. Levene's test with the median is much less affected by skew, so its false-alarm rate stays closer to the chosen alpha.