F-Test for Equality of Variances
Hypothesis Testing
Testing Whether Groups Differ in Variability
The F-test for variances evaluates whether two populations have equal spread, a critical assumption for many statistical procedures. Understanding variance equality is essential for choosing appropriate analysis methods.
- Quality Control — Comparing consistency of different manufacturing processes
- Finance — Assessing whether investment portfolios have different risk levels
- Agricultural Research — Testing uniformity of crop yields across treatments
The F-test for variances is the prerequisite for comparing means.
What You'll Learn
- 1State the hypotheses and compute the F ratio from two sample variances
- 2Explain why the F-test is strictly tied to normality while other variance tests are not
- 3Compare Levene, Brown-Forsythe, Bartlett and Fligner on assumptions and power
- 4Decide what to do after the test concludes, including when to ignore it entirely
Tests H₀: σ₁² = σ₂² using the ratio of sample variances. The test is built on a single algebraic fact: for a normal sample, the quantity follows a chi-square distribution with degrees of freedom, and a ratio of two independent chi-squares divided by their degrees of freedom follows an F distribution.
Under H₀, F follows an F-distribution with (n₁−1, n₂−1) degrees of freedom.
Setting Up the Test Correctly
The F distribution is asymmetric and bounded below by zero, so the division order matters. Put the larger sample variance on top, giving , and then double the smaller tail probability to obtain a two-sided p-value:
Two common errors follow from forgetting this. Dividing the smaller variance by the larger and then taking the upper tail halves the p-value and doubles your false positive rate. Taking a single tail when the research question is "are the variances different?" answers a different question than the one you asked — a one-sided version is appropriate only when you specified in advance that one particular group must have the larger spread, such as checking that a new process is less variable than the old one.
The test also inherits the normality requirement from the chi-square result. If the underlying distributions are skewed or heavy-tailed, the ratio of sample variances no longer follows the F distribution that the p-value references.
A Worked Example
Two production lines make the same component. Line A produces 20 units with a sample variance of 25; line B produces 20 units with a sample variance of 100.
Step 1 — hypotheses. against .
Step 2 — the ratio. Placing the larger variance on top, with and .
Step 3 — the reference distribution. The 1 percent upper-tail critical value for is approximately 2.95, and 4.00 lies well beyond it, so the two-sided p-value is below 0.01 — around 0.003.
Step 4 — interpretation. Line B's variance is four times line A's, and the difference is too large to attribute to sampling noise. In quality control terms, line B is roughly twice as variable in standard deviation, since against . That is the operationally meaningful statement: a variance ratio of 4 is a standard deviation ratio of 2.
Step 5 — the practical decision. If this comparison preceded a t-test, the unequal variances point to Welch's version. If the goal was process improvement, the four-fold variance gap is itself the finding and calls for investigating line B's inputs, tooling, or operator.
Reversing the division would give with degrees of freedom swapped, and the same conclusion only if the lower tail is doubled — the arithmetic is identical but the bookkeeping is easier to get wrong.
Sensitivity to Non-Normality
The F test is the most powerful variance test available when the normality assumption genuinely holds. That advantage evaporates quickly when it does not. Simulation results that are widely reproduced in textbooks show a nominal 5 percent test rejecting as often as 10 to 15 percent under moderate kurtosis, and above 20 percent under strong skewness combined with unequal sample sizes. The direction of the distortion depends on the shape and on which group is larger, so the error can be either inflation or deflation.
Because real outcomes are rarely exactly normal — income, duration, and count data are all skewed — this fragility is the main reason Levene's test is preferred in applied work. The next table summarises the trade-offs.
| Test | Centring used | Needs normality | Power when normal | Sensitivity to skew |
|---|---|---|---|---|
| F test | Group means | Yes, strictly | Highest | Very high, distorts size |
| Levene | Group means | No | High | Moderate |
| Brown-Forsythe | Group medians | No | High | Low |
| Bartlett | Pooled variance | Approximately | High | High |
| Fligner-Killeen | Ranks | No | Moderate to high | Low |
Levene's test converts the data into absolute deviations from each group centre and runs a one-way ANOVA on those deviations, so it tests whether the typical distance from the centre differs between groups rather than whether the second moments differ. Centering on the median rather than the mean, which defines Brown-Forsythe, makes the test markedly more resistant to skew. Bartlett's test statistics are efficient under normality but inherit the F test's sensitivity, so they are rarely the right default.
What to Do With the Answer
The conclusion feeds one of three decisions, and it is worth naming which one you are in before running anything.
- Choosing the form of a mean comparison. If the variance test rejects, use Welch's t-test. However, the modern recommendation is to skip the pretest entirely and run Welch by default: the two-stage rule has no fixed overall Type I error rate, and Welch loses almost nothing when variances are in fact equal.
- Comparing variability as the research question. In quality control, finance, and reliability, the variance ratio is the result. Report the ratio of standard deviations alongside the p-value, because a variance ratio of 4 sounds dramatic until you note it means a twofold difference in spread.
- Preparing an ANOVA. Classical ANOVA assumes equal variances. If Levene or Brown-Forsythe rejects, prefer Welch's ANOVA, a heteroscedasticity-robust F test, or a transform, rather than trying to rescue the classical test.
Running the Tests in Python and R
import numpy as np
from scipy import stats
rng = np.random.default_rng(42)
line_a = rng.normal(50, 5, 20) # sigma = 5
line_b = rng.normal(52, 10, 20) # sigma = 10
s1, s2 = line_a.var(ddof=1), line_b.var(ddof=1)
df1, df2 = len(line_a) - 1, len(line_b) - 1
# Put the larger variance on top, then double the small tail
if s1 >= s2:
F, df1, df2 = s1 / s2, df1, df2
else:
F, df1, df2 = s2 / s1, df2, df1
p_two = 2 * min(stats.f.cdf(F, df1, df2), stats.f.sf(F, df1, df2))
print(f"s1^2 = {s1:.3f}, s2^2 = {s2:.3f}")
print(f"F({df1}, {df2}) = {F:.4f}, two-sided p = {p_two:.4f}")
print(f"sd ratio = {np.sqrt(F):.3f}")
print(f"critical F at 0.025 upper tail: {stats.f.ppf(0.975, df1, df2):.3f}")
# Robust alternatives - these do not need normality
for name, fn in [("Levene (mean)", stats.levene),
("Levene (median) = Brown-Forsythe",
lambda *a: stats.levene(*a, center='median')),
("Bartlett", stats.bartlett),
("Fligner-Killeen", stats.fligner)]:
stat, p = fn(line_a, line_b)
print(f"{name:36s} stat={stat:8.4f} p={p:.4f}")
# Effect size: log variance ratio with a confidence interval
logvr = np.log(s1 / s2)
se = np.sqrt(2/df1 + 2/df2)
print("95% CI for variance ratio:",
np.round(np.exp([logvr - 1.96*se, logvr + 1.96*se]), 3))
a <- c(48.2, 51.6, 49.9, 55.1, 47.3, 52.8, 50.4, 46.9, 53.7, 49.2,
51.1, 48.8, 54.3, 50.0, 47.6, 52.2, 55.0, 49.5, 50.8, 46.4)
b <- c(61.3, 44.7, 57.9, 38.2, 66.1, 49.5, 55.4, 41.8, 63.0, 50.9,
47.2, 60.1, 52.6, 45.9, 58.4, 39.7, 64.2, 51.5, 48.3, 56.8)
var.test(a, b) # F test, two-sided by default
var.test(a, b, ratio = 1, alternative = "greater")
leveneTest(a, b) # mean-centred, car package
fligner.test(a, b) # rank-based, very robust
bartlett.test(c(a, b) ~ rep(c("A","B"), c(20, 20))) # needs normality
# What follows: Welch's comparison of means
t.test(a, b)
💡Report the ratio, not just the p-value
Common Mistakes
Dividing the smaller variance by the larger and reading the upper tail
Fix: Either place the larger variance on top and double the p-value, or take the smaller tail and double it. Swapping both is what produces a p-value that is half of what it should be.
Using the F test on skewed or heavy-tailed data
Fix: Reach for Levene or Brown-Forsythe, which are built from deviations and do not inherit the normality requirement.
Letting the pretest choose pooled versus Welch automatically
Fix: Run Welch by default. The pretest-plus-conditional-test procedure has no fixed Type I error rate and no meaningful power advantage.
Reporting only the p-value of a variance test
Fix: Give both standard deviations and their ratio; a variance ratio of 4 is a standard deviation ratio of 2, which is the number that matters in practice.
Best Practices
- Use Levene or Brown-Forsythe as the default variance comparison in applied work
- State the division order and whether the p-value was doubled when you report an F test
- Report standard deviations and the variance ratio alongside any significance claim
- If equal variances are in doubt for a mean comparison, choose Welch rather than conditioning on a pretest
Key Takeaways
- The F statistic is the ratio of two sample variances, referenced to an F distribution with n1 minus 1 and n2 minus 1 degrees of freedom
- Place the larger variance on top and double the smaller tail to obtain a two-sided p-value
- The F test is the most powerful under exact normality and the most fragile when normality fails
- Levene and Brown-Forsythe work from absolute deviations and are the practical defaults
- A variance ratio of F corresponds to a standard deviation ratio of the square root of F
Interview Questions
Q1: Why must the F test statistic use the larger variance in the numerator?
The conventional F tables give upper-tail critical values. Putting the larger variance on top guarantees the ratio is at least 1, so you are always in the upper tail; the two-sided p-value is then twice that tail probability. Dividing the other way and reading the upper tail halves the p-value.
Q2: How does the F test behave when the data are not normal?
Badly. The chi-square result underlying the statistic assumes normal samples, so skewness and heavy tails distort the reference distribution. A nominal 5 percent test can reject 10 to 20 percent of the time, and the direction of the distortion depends on the shape and the group sizes.
Q3: What does Levene's test actually test?
It converts each observation to its absolute deviation from its group centre, then runs a one-way ANOVA on those deviations. Rejecting means the typical distance from the group centre differs, which is a robust stand-in for comparing variances.
Q4: Should the F test decide whether you use a pooled or Welch t-test?
Modern practice says no. Pretesting introduces a two-stage procedure with no fixed overall error rate, while Welch is valid under equal variances and loses negligible power. Use Welch by default and reserve variance tests for questions about variability itself.
Frequently Asked Questions
How do I compare more than two variances?
Bartlett's and Levene's tests extend naturally to k groups through a one-way analysis on variances or absolute deviations. Bartlett's test assumes normality, Levene's does not. For pairwise follow-ups, adjust the p-values with Holm or Bonferroni, and remember that variance estimates are themselves noisy, so many comparisons will be inconclusive.
What is the relationship between the F test and the variance confidence interval?
They are the same inference expressed differently. A 95 percent interval for excludes 1 exactly when the two-sided F test rejects at the 5 percent level. Reporting the interval is more informative because it gives the range of variance ratios compatible with the data.
Can I test variances when the two samples are paired?
No. The F test assumes two independent samples. For paired data the relevant quantity is the variance of the within-pair differences, and equality of the two marginal variances is usually not the question of interest. Use a test on the difference scores or a model that allows group-specific residual variances.
Is a large variance ratio always a problem?
Not always. In finance a higher variance is the risk you are measuring, and in quality control it is the defect to be eliminated. It becomes a statistical nuisance only when it interferes with an inference about means, and even then the remedy is a heteroscedasticity-robust method rather than a transformation of the research question.