Levene Test in R: leveneTest() for Homogeneity of Variance (car Package)

Run leveneTest() from R's car package to check variance equality before ANOVA. Step-by-step syntax, p-value interpretation, and APA write-up.
Author photo
Written by Dr. Zubair, PhD Statistics
Reviewed by Dr Ali

Dr. Zuabir holds a PhD in Statistics and has helped 200+ PhD and Master's students complete their dissertation statistical analysis using R, SPSS, and Minitab.

Install and load the car package, then run leveneTest(y ~ group, data = df). If p > 0.05 — variances are equal, proceed with ANOVA. If p ≤ 0.05 — variances are unequal, switch to Welch's ANOVA using oneway.test(y ~ group, var.equal = FALSE).


Levene Test in R — leveneTest() from the car package for homogeneity of variance

The Levene test in R is the standard pre-ANOVA check that every researcher running group comparisons needs to perform. It tests whether the variance of a continuous variable is equal across two or more groups — the homogeneity of variance assumption required by ANOVA, independent-samples t-tests, and similar parametric analyses. This tutorial walks through the leveneTest() function from the car package, covering syntax, output interpretation, what to do when the test is significant, and how to report the result in APA format.

Before you start: Make sure you have R and RStudio installed (installation guide), know how to install and load packages, and have imported your dataset into R.
Table of Contents
Aspect Details
Purpose Tests the null hypothesis that group variances are equal (homogeneity of variance).
R Function leveneTest(y ~ group, data = df) from the car package
Default center Median (Brown-Forsythe variant — more robust). Use center = mean for the original Levene formulation.
Decision rule p > 0.05 → variances equal, proceed with standard ANOVA. p ≤ 0.05 → use Welch's ANOVA or non-parametric alternative.
Use before One-way ANOVA, two-way ANOVA, independent-samples t-test
Alternative tests Bartlett's test (requires normality), Fligner-Killeen test (non-parametric)

What Is the Levene Test in R?

The Levene test is a statistical hypothesis test for homogeneity of variance — the assumption that multiple groups have equal population variances. It was introduced by Howard Levene in 1960 as a more robust alternative to Bartlett's test, because it performs well even when the data deviate moderately from normality.

Unlike the F-test, which only compares two groups and requires normality, leveneTest() handles two or more groups and is less sensitive to non-normal distributions. This makes it the default choice for checking the ANOVA assumption in applied research.

Statistical hypotheses:

  • H₀: All group variances are equal — σ₁² = σ₂² = … = σₖ²
  • H₁: At least two group variances differ

When to Run Levene's Test

  • Before one-way or two-way ANOVA — variance equality is a core assumption
  • Before an independent-samples t-test — equal variances determine which t-test variant to use
  • In dissertation methodology sections — reviewers expect documented assumption checks
  • When comparing groups with potentially different spreads — clinical trials, educational assessments, survey data by demographic group
When to use Levene test in R — advantages and disadvantages overview

leveneTest() Syntax and Arguments (car Package)

Step 1 — Install and Load the car Package

# Install the car package (run once)
install.packages("car")

# Load the car package
library(car)

leveneTest() Function Syntax

# Formula method (most common)
leveneTest(y ~ group, data = df)

# With center argument (default is median)
leveneTest(y ~ group, data = df, center = median)   # Brown-Forsythe variant
leveneTest(y ~ group, data = df, center = mean)     # Original Levene formulation
Argument What it does Example
y Your continuous dependent variable (numeric vector or formula) mpg, score
group Categorical grouping variable (factor). R will coerce to factor if needed. cyl, treatment
data Data frame containing your variables mtcars, my_data
center median (default — robust) or mean (classical Levene) center = median

Common warning:
You may see: "group coerced to factor." This is not an error. R is automatically converting your grouping variable to a factor, which is required for leveneTest(). The results are valid.

How to Run Levene's Test in R — Step-by-Step Examples

Example 1: Equal Variances (p > 0.05)

Using the built-in PlantGrowth dataset, which compares dried plant weight across three treatment groups:

library(car)

# Run Levene's test — plant weight by treatment group
leveneTest(weight ~ group, data = PlantGrowth)

Output:

Levene's Test for Homogeneity of Variance (center = median)
       Df F value Pr(>F)
group   2  1.1211 0.3412
       27

Interpretation: F(2, 27) = 1.12, p = .341. Since p > 0.05, we fail to reject H₀. Variances are equal across the three plant treatment groups — safe to proceed with standard ANOVA.

Example 2: Unequal Variances (p < 0.05)

Using the mtcars dataset, comparing fuel efficiency (mpg) across cylinder groups (4, 6, and 8 cylinders):

library(car)

# Convert cyl to factor (grouping variable must be categorical)
mtcars$cyl <- as.factor(mtcars$cyl)

# Run Levene's test — mpg by cylinder group
leveneTest(mpg ~ cyl, data = mtcars)

Output:

Levene's Test for Homogeneity of Variance (center = median)
       Df F value   Pr(>F)   
group   2  5.5071 0.009387 **
       29
leveneTest() output in R showing F-statistic and p-value for mpg across cyl groups in mtcars

Interpretation: F(2, 29) = 5.51, p = .009. Since p < 0.05, we reject H₀. Variances are significantly unequal across cylinder groups — do not use standard ANOVA. Use Welch's ANOVA instead (see next section).

Interpreting leveneTest() Output

What Each Number Means

  • Df (group) — Degrees of freedom between groups = k − 1, where k is the number of groups. For 3 groups: Df = 2.
  • F value — The test statistic. Larger F = greater evidence of unequal variances. The test internally runs an ANOVA on the absolute deviations from each group's median.
  • Pr(>F) — The p-value. This is what drives your decision.
  • Second Df row — Degrees of freedom within groups = N − k. For mtcars (32 cars, 3 groups): 32 − 3 = 29.

Decision Table

p-value result Decision What to do next
p > 0.05 Fail to reject H₀ — variances are equal Proceed with standard one-way ANOVA
p ≤ 0.05 Reject H₀ — variances are significantly unequal Use Welch's ANOVA, Kruskal-Wallis, or transform data

Important nuance:
A non-significant Levene test (p > 0.05) does not prove variances are exactly equal — it means there is insufficient evidence to conclude they differ. With small samples, the test has low power and may miss real variance differences. Always complement with a boxplot.

What to Do When Levene's Test Is Significant (p < 0.05)

A significant Levene test means the homogeneity of variance assumption is violated. You have three options, in recommended order:

Option 1 — Welch's ANOVA (Recommended)

Welch's ANOVA does not assume equal variances. It is the direct replacement for one-way ANOVA when Levene's test is significant.

# Welch's one-way ANOVA — does not assume equal variances
oneway.test(mpg ~ cyl, data = mtcars, var.equal = FALSE)

# Output:
# One-way analysis of means (not assuming equal variances)
# F = 36.00, num df = 2, denom df = 14.33, p-value = 1.314e-05

For two-group comparisons, use t.test(y ~ group, var.equal = FALSE) — Welch's t-test.

Option 2 — Kruskal-Wallis Test (Non-Parametric)

If your data also violate normality (confirmed by a Shapiro-Wilk test), use the non-parametric Kruskal-Wallis test instead of ANOVA:

# Non-parametric alternative when both normality and equal variance are violated
kruskal.test(mpg ~ cyl, data = mtcars)

Option 3 — Data Transformation

If theory requires a parametric test, try a log or square-root transformation to stabilize variances, then re-run Levene's test on the transformed variable. Heteroscedasticity in regression models calls for a similar fix.

# Log-transform the dependent variable
mtcars$log_mpg <- log(mtcars$mpg)

# Re-check with leveneTest
leveneTest(log_mpg ~ cyl, data = mtcars)

Levene Test vs Bartlett Test vs Fligner-Killeen Test

Comparison of Levene test, Bartlett test, and Fligner-Killeen test for homogeneity of variance in R
Feature Levene's Test Bartlett's Test Fligner-Killeen Test
R function leveneTest() (car) bartlett.test() (base R) fligner.test() (base R)
Normality required? No — robust to mild non-normality Yes — sensitive to departures No — fully non-parametric
Best for Most real-world datasets (default choice) Normally distributed data only Heavily skewed data or many outliers
Groups supported 2 or more 2 or more 2 or more
Package car (must install) Base R (no install needed) Base R (no install needed)
Used in dissertations Most common citation Less common unless data is normal Rare — used as sensitivity check
# Bartlett's test (assumes normality)
bartlett.test(weight ~ group, data = PlantGrowth)

# Fligner-Killeen test (non-parametric, no normality needed)
fligner.test(weight ~ group, data = PlantGrowth)
Rule of thumb: Use leveneTest() by default. Switch to bartlett.test() only after confirming normality with a Shapiro-Wilk test. Use fligner.test() when data are severely non-normal or contain substantial outliers.

How to Report Levene's Test in APA Format

Dissertation and journal methodology sections require APA-formatted reporting of Levene's test. The format is:

Levene's test [result], F(df₁, df₂) = [F value], p = [p value].

APA Report — When p > 0.05 (Variances Equal)

Using the PlantGrowth example: F(2, 27) = 1.12, p = .341

Levene's test indicated equal variances across the three treatment groups, F(2, 27) = 1.12, p = .341. The homogeneity of variance assumption was met, and a one-way ANOVA was used for subsequent analysis.

APA Report — When p < 0.05 (Variances Unequal)

Using the mtcars example: F(2, 29) = 5.51, p = .009

Levene's test indicated significantly unequal variances across cylinder groups, F(2, 29) = 5.51, p = .009. The homogeneity of variance assumption was violated; therefore, Welch's one-way ANOVA was used.

Formatting notes:
In APA 7th edition: italicize F and p; report p values without a leading zero (write .009, not 0.009); use two decimal places for F; round p to three decimal places. Write exact p values unless p < .001, in which case write p < .001.

leveneTest() with Multiple Independent Variables

When your design has more than one grouping factor, use the interaction() function to combine factors into a single grouping variable:

library(car)

# Levene's test with two independent variables — supp and dose
leveneTest(len ~ interaction(supp, dose), data = ToothGrowth)

# Output:
# Levene's Test for Homogeneity of Variance (center = median)
#        Df F value Pr(>F)
# group   5  1.7086 0.1484
#        54

p = .148 > 0.05 — variances are equal across all six supp × dose combinations. Proceed with two-way ANOVA.

Brown-Forsythe Variation: center = "median"

By default, leveneTest() uses the group median to compute deviations — this is technically the Brown-Forsythe modification. It is more robust to skewed distributions and outliers than the original mean-based Levene formulation.

# Default (Brown-Forsythe — uses median, more robust)
leveneTest(mpg ~ cyl, data = mtcars, center = median)

# Classical Levene (uses mean — original 1960 formulation)
leveneTest(mpg ~ cyl, data = mtcars, center = mean)
Brown-Forsythe variation of Levene test using center=median in R for robust variance testing

For most applied research, the default center = median is recommended. Use center = mean only when matching output to software that implements the original Levene (1960) version — some older SPSS versions use the mean-based form.

Visualizing Variances Before Testing

A boxplot before running Levene's test gives you a visual intuition about whether variances might differ — wide boxes and unequal spreads are the visual signal.

# Boxplot — visually compare spread across groups
boxplot(mpg ~ cyl, data = mtcars,
        main = "MPG by Cylinder Group",
        xlab = "Cylinders",
        ylab = "Miles Per Gallon",
        col = c("lightblue", "pink", "lightgreen"))
Boxplot comparing mpg spread across 4, 6, and 8 cylinder groups in mtcars — visual pre-check before Levene test

The unequal box widths for the 4, 6, and 8-cylinder groups confirm what Levene's test found — variances differ. The 4-cylinder group has a wider spread than the 8-cylinder group.

Handling Outliers Before Levene's Test

Outliers inflate variance estimates. Detect them with a boxplot or IQR-based check before running the test:

# Detect outliers in mpg
outliers <- boxplot.stats(mtcars$mpg)$out
print(outliers)

# If outliers are present and data is not missing at random:
# Consider using center = "median" (already the default) or
# switch to Fligner-Killeen for a fully non-parametric check
Boxplot detecting outliers in mtcars mpg before running Levene test in R

Common Errors and How to Fix Them

Error: could not find function "leveneTest"

You have not loaded the car package. Run library(car) before calling leveneTest(). If the package is not installed, run install.packages("car") first.

Warning: group coerced to factor

Not an error. R is converting your grouping variable to a factor because leveneTest() requires a factor. Results are valid. To suppress the warning, explicitly convert before calling: df$group <- as.factor(df$group).

Error: NA values in response variable

Remove rows with missing data before running the test: df_clean <- na.omit(df). Then run leveneTest() on df_clean.

df_clean <- na.omit(mtcars)
leveneTest(mpg ~ cyl, data = df_clean)
Unexpected p-value — very small despite visually similar boxes

With large sample sizes (n > 200), Levene's test becomes highly sensitive and can flag statistically significant but practically negligible variance differences. Always examine the effect size alongside the p-value. Also check for outliers using boxplot.stats() — a single extreme value can inflate the F-statistic substantially.

Frequently Asked Questions

What does leveneTest() do in R?

leveneTest() from R's car package tests whether the variance of a continuous variable is equal across two or more groups. It is used as a preliminary assumption check before running ANOVA or an independent-samples t-test. A p-value > 0.05 means variances are equal; p ≤ 0.05 means they differ significantly.

What does p < 0.05 mean in Levene's test?

A p-value below 0.05 in Levene's test means you reject the null hypothesis that group variances are equal. The homogeneity of variance assumption is violated. You should switch from standard ANOVA to Welch's ANOVA (oneway.test(y ~ group, var.equal = FALSE)) or a non-parametric test such as Kruskal-Wallis.

What is the difference between leveneTest() and bartlett.test() in R?

leveneTest() is robust to non-normal data because it uses deviations from the group median (Brown-Forsythe variant by default). bartlett.test() assumes normality and becomes unreliable when that assumption is violated. For most applied research datasets, leveneTest() is preferred. Only use bartlett.test() after confirming normality with a Shapiro-Wilk test.

Does Levene's test test for normality?

No. Levene's test only tests for equality of variances across groups — it says nothing about whether the data follow a normal distribution. For normality testing, use the Shapiro-Wilk test (shapiro.test()) or a Q-Q plot.

What is the difference between the Levene test and ANOVA?

ANOVA compares group means to detect statistically significant differences. The Levene test checks whether the variance (spread) is equal across those groups — an assumption ANOVA makes before the means comparison can be trusted. Run Levene's test first; run ANOVA second.

What does the F-statistic mean in Levene's test?

The F-statistic in Levene's test measures the ratio of between-group variance to within-group variance in the absolute deviations from each group's median (or mean). A higher F-value indicates greater disparity in spreads across groups. The p-value attached to F determines whether that disparity is statistically significant.

How do I report Levene's test results in APA format?

APA format for Levene's test: include the F-statistic, degrees of freedom in parentheses, and p-value. Example when variances are equal: "Levene's test indicated homogeneity of variance, F(2, 27) = 1.12, p = .341." Example when variances are unequal: "Levene's test indicated significantly unequal variances, F(2, 29) = 5.51, p = .009; therefore Welch's ANOVA was used." Italicize F and p; omit the leading zero before the decimal in p-values.

Does Levene's test use mean or median?

leveneTest() in R defaults to center = median, which is the Brown-Forsythe modification of the original 1960 Levene test. This makes it more robust to non-normal data and outliers. Set center = mean to reproduce the classical Levene formulation used in some older textbooks and SPSS versions.

Can I use leveneTest() with more than two groups?

Yes. leveneTest() supports any number of groups (k ≥ 2). For two independent variables, use leveneTest(y ~ interaction(group1, group2), data = df) to collapse the factors into a single grouping variable that represents all combinations.

Is leveneTest() from the car package or base R?

leveneTest() is from the car package (Companion to Applied Regression), not base R. You must install it with install.packages("car") and load it with library(car) before use. Base R does include bartlett.test() and fligner.test() without any package installation.

Related Posts

Need help applying the Levene test — or any ANOVA assumption check — in your dissertation methodology? Send your dataset and research question via WhatsApp for a same-day consultation: wa.me/923106367532