Homogeneity of Variance Test in R: F-test, Bartlett, Levene, Fligner
Check the equal-variance assumption behind the t-test and ANOVA — the F-test for two groups, and Bartlett, Levene and Fligner-Killeen for several — with clear guidance on which to use
Biostatistics
Learn how to test the homogeneity of variance (equal variance) assumption in R — the assumption behind the independent t-test and ANOVA. Covers the F-test for two groups (var.test), and Bartlett’s, Levene’s and Fligner-Killeen’s tests for several groups, with guidance on which test to choose given your data’s normality.
Published
June 23, 2026
Modified
July 7, 2026
TipKey takeaways
Homogeneity of variance (equal variance, homoscedasticity) is the assumption — behind the independent t-test and ANOVA — that the groups share a common variance.
For two groups use the F-test (var.test()); for several groups use Bartlett’s, Levene’s or Fligner-Killeen’s test.
F-test and Bartlett’s assume normal data; Levene’s is a robust alternative less sensitive to non-normality (the most used in practice); Fligner-Killeen’s is non-parametric and most robust.
For all of them, p > 0.05 means equal variance holds (assumption met); p < 0.05 means it is violated — switch to a Welch test or a non-parametric alternative.
The pipe-friendly rstatix::levene_test() wraps car::leveneTest().
Introduction
Several classic tests — the independent-samples t-test and ANOVA — assume the groups have equal variances (homogeneity of variance, or homoscedasticity). Before trusting those tests you should check the assumption, and there are four common tools, differing in what they assume about the data:
Test
Groups
Assumes normality?
F-test (var.test)
exactly 2
yes
Bartlett’s
2 or more
yes
Levene’s
2 or more
no (robust) — most used
Fligner-Killeen’s
2 or more
no (non-parametric, most robust)
For all of them the null hypothesis is equal variances, so a non-significant result (p > 0.05) is what you want — it means the assumption holds. This lesson runs each on the built-in ToothGrowth and PlantGrowth data.
F-test: compare two variances
The F-test (var.test()) compares the variances of two groups by their ratio — the further from 1, the stronger the evidence of unequal variance. It assumes the data are normal, so check normality first. Here we compare tooth-growth len between the two supplement types (supp):
data("ToothGrowth")ToothGrowth$dose <-as.factor(ToothGrowth$dose)var.test(len ~ supp, data = ToothGrowth)
F test to compare two variances
data: len by supp
F = 0.6386, num df = 29, denom df = 29, p-value = 0.2331
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.3039488 1.3416857
sample estimates:
ratio of variances
0.6385951
The p-value (0.23) is greater than 0.05, so there is no significant difference between the two variances — equal variance holds.
Compare several variances
For three or more groups, the null hypothesis is that all group variances are equal; p < 0.05 means at least two differ and the assumption is violated.
Bartlett’s test
Bartlett’s test handles two or more groups but, like the F-test, assumes normality:
data("PlantGrowth")bartlett.test(weight ~ group, data = PlantGrowth)
Bartlett test of homogeneity of variances
data: weight by group
Bartlett's K-squared = 2.8786, df = 2, p-value = 0.2371
The p-value (0.24) is non-significant — plant-weight variance does not differ across the three treatment groups. For two grouping factors, collapse them with interaction():
data("ToothGrowth")ToothGrowth$dose <-as.factor(ToothGrowth$dose)bartlett.test(len ~interaction(supp, dose), data = ToothGrowth)
Bartlett test of homogeneity of variances
data: len by interaction(supp, dose)
Bartlett's K-squared = 6.9273, df = 5, p-value = 0.2261
Levene’s test (recommended)
Levene’s test is a robust alternative — far less sensitive to departures from normality, which is why it is the most used in practice. The pipe-friendly rstatix::levene_test() wraps car::leveneTest():
library(rstatix)data("PlantGrowth")# one grouping factorPlantGrowth %>%levene_test(weight ~ group)
# A tibble: 1 × 4
df1 df2 statistic p
<int> <int> <dbl> <dbl>
1 2 27 1.12 0.341
library(rstatix)data("ToothGrowth")ToothGrowth$dose <-as.factor(ToothGrowth$dose)# two grouping factors and their interactionToothGrowth %>%levene_test(len ~ supp * dose)
# A tibble: 1 × 4
df1 df2 statistic p
<int> <int> <dbl> <dbl>
1 5 54 1.71 0.148
Both are non-significant (p > 0.05) — equal variance holds.
Fligner-Killeen’s test
Fligner-Killeen’s test is non-parametric and the most robust against non-normality — a good choice when the data are clearly not normal:
data("PlantGrowth")fligner.test(weight ~ group, data = PlantGrowth)
Fligner-Killeen test of homogeneity of variances
data: weight by group
Fligner-Killeen:med chi-squared = 2.3499, df = 2, p-value = 0.3088
Again non-significant (p = 0.31) — the three tests agree that the variances are equal.
Which test should you use?
Two groups, normal data → the F-test (var.test()).
Several groups, normal data → Bartlett’s test.
Several groups, normality uncertain → Levene’s test (the default recommendation).
Several groups, clearly non-normal → Fligner-Killeen’s test.
NoteThe math (optional)
Each test builds a statistic that is large when the group variances diverge. Bartlett’s compares the pooled variance to the within-group variances on a log scale (sensitive to normality). Levene’s runs an ANOVA on the absolute deviations from each group’s centre (\(|y_{ij} - \tilde{y}_i|\), using the median in the robust Brown-Forsythe form) — turning a spread question into a means question, which is why it tolerates non-normality. Fligner-Killeen replaces those deviations with ranks, making it fully non-parametric.
Try it live
Test the equal-variance assumption yourself, and see what happens when variances genuinely differ. The sandbox boots on first Run.
🟢 With an AI agent
Ask Prova“check whether my groups have equal variances before I run a t-test or ANOVA, and tell me which variance test fits my data” — it answers with rstatix code you can run on your own data, and helps you decide between Levene, Bartlett and Fligner. The runtime is the judge.Ask Prova →
Common issues
You used Bartlett’s (or the F-test) on non-normal data. Both are sensitive to non-normality and can flag unequal variance that isn’t really there. Prefer Levene’s (or Fligner-Killeen’s) when normality is in doubt.
Levene’s test is significant — what now? The equal-variance assumption is violated. For two groups use the Welch t-test (t.test(..., var.equal = FALSE), the default); for several groups use the Welch ANOVA (welch_anova_test()) with Games-Howell post-hoc, or a non-parametric test.
A factor column is numeric. Make grouping variables factors first (mydata$group <- factor(mydata$group)) or the test treats them as continuous.
Frequently asked questions
NoteWhat is homogeneity of variance?
Homogeneity of variance (equal variance, or homoscedasticity) means the groups being compared share the same variance — the same spread of values. It is a key assumption of the independent-samples t-test and ANOVA; when it fails, those tests can give misleading p-values and you switch to a Welch or non-parametric alternative.
NoteWhich test of equal variance should I use?
For two groups, the F-test (var.test()). For several groups: Bartlett’s if the data are normal, Levene’s if normality is uncertain (the most common choice), and Fligner-Killeen’s if the data are clearly non-normal. Levene’s is the safe default.
NoteHow do I interpret the variance test p-value?
The null hypothesis is equal variances, so a non-significant result (p > 0.05) means the assumption holds and you can proceed. A significant result (p < 0.05) means the variances differ — use a Welch test (two groups) or Welch ANOVA / non-parametric test (several groups).
NoteWhat is the difference between Levene’s and Bartlett’s test?
Both compare variances across two or more groups, but Bartlett’s assumes the data are normal and is sensitive to departures from it, while Levene’s runs on the deviations from each group’s centre, making it robust to non-normality. Levene’s is preferred unless you are confident the data are normal.
Test your understanding
ImportantPractice
Run it. In the live cell, run Levene’s test of weight by group on PlantGrowth. Fill the blank. Is the equal-variance assumption met?
Conceptual. Your data are clearly non-normal and you have four groups. Which variance test should you use, and why not Bartlett’s?
NoteHint
Fill the blank with group. A p > 0.05 means equal variance holds. For question 2, recall which tests assume normality and which do not.
The assumption is met. For question 2: use Fligner-Killeen’s test (or Levene’s) because it is non-parametric and robust to non-normality; Bartlett’s assumes normal data and would be unreliable here, potentially flagging unequal variance that is really just non-normality.
TipWhich test when?
Two groups, normal → F-test (var.test()).
Several groups, normal → Bartlett’s test.
Several groups, normality uncertain → Levene’s test (default).
Several groups, non-normal → Fligner-Killeen’s test.
Conclusion
You can now test the homogeneity of variance assumption in R with all four tools: the F-test for two groups, and Bartlett’s, Levene’s and Fligner-Killeen’s for several — choosing among them by how confident you are in normality. Levene’s (rstatix::levene_test()) is the robust default. When the assumption fails, move to a Welch test or a non-parametric alternative rather than the classic t-test or ANOVA.
Related lessons
Normality test in R — the other key assumption, and the one that decides which variance test to trust. · T-test in R — uses the equal-variance assumption (and the Welch fallback). · One-way ANOVA in R — assumes equal variance across groups, with the Welch ANOVA when it fails.
Every result on this page was produced by the code shown, run at build time against a pinned R environment — edit any block and Run to reproduce it yourself.