Skip to Main Content

MASH : Maths and Stats Help

Levene's Test for Homogeneity of Variances


In order to run Levene’s test, you will need to install and load the “rstatix” package.


Levene’s test for homogeneity of variances tests whether the variances of two or more groups or variables are different. It is most commonly used with independent-samples t-tests and between-subjects ANOVAs.

The example data for this guide consists in the English scores of students from 2 different classes:


Test Procedure

Similarly to the t-test, it can be run using a formula method or a variables method.


Formula method

This is used for when the data is structured using a grouping variable. A grouping variable is a categorical variable indicating which scores belong to different groups.

The first argument entered in the levene_test() function is a formula that takes the following structure: dependent variable ~ independent variable. The independent variable should be a grouping variable with two categories (levels).

For the formula method, the levene_test() function needs the grouping variable to be a factor, which is a type of categorical variable (in R) that contains information about the different categories present in the variable along with the values. In the code below, we convert the categorical variable “Class” from numerical to factor using the factor() function.

The second argument is the data frame.

levene_test(English_Score ~ factor(Class), englishdata1)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  1  0.4667 0.5057
##       14


Variables method

Unlike the t-test, this method can only be run when you have a grouping variable to separate the groups (just like with the formula method), instead of having your variables on different columns. Your independent variable should be a grouping/categorical variable, your dependent variable should be a numeric variable.

The first argument of the function needs to be the dependent variable, whilst the second argument should be the independent variable.

If you have your variables stored in a data frame, use the following structure to indicate the variables: data_frame$variable_name

levene_test(englishdata1$English_Score, englishdata1$Class)
## Warning in leveneTest.default(englishdata1$English_Score, englishdata1$Class):
## englishdata1$Class coerced to factor.
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  1  0.4667 0.5057
##       14

Note that for this method, R will automatically convert your independent variable to a factor (see the warning).



R will generate largely the same output for both formula and variables methods.


Variances by group

The test does not actually give you the variances of the two variables. If you need to report them, please check our guide on descriptive statistics.

Levene's Test for Homogeneity of Variances

This table shows thetest results including the F statistic, the degrees of freedom (Df) and the significance or p-value - Pr(>F).


If the results of the Levene's test are significant, it means that the variances are signicantly different. If the test produces non-significant results, the variances are similar or not significantly different. For the assumption of homogeneity of variances to be met (t-test and ANOVA), the Levene's test should be NOT significant.


Reporting the Results in APA Formatting

The variances of English scores of class 1 and class 2 students were compared. A Levene's test of homogeneity of variances indicated that the variances were homogenous, F(1,14) = 0.47, =.506