- Home
- Appointment Information
- Workshops
- Information for Staff
- Stats ResourcesToggle Dropdown
- Stats with SPSSToggle Dropdown
- Independent-Samples t-Test
- Paired-Samples t-Test
- Mann Whitney U-Test
- Wilcoxon Signed-Ranks Test
- One-Way Between-Subjects ANOVA
- One-Way Repeated-Measures ANOVA
- Two-Way Mixed ANOVA
- One-Way Between-Subjects ANCOVA
- Kruskal Wallis H-Test
- Friedman's ANOVA
- Pearson's 'r' Correlation
- Spearman's Rho Correlation
- Simple Linear Regression
- Multiple Linear Regression
- Chi-Squared (χ2) Test of Association
- Shapiro-Wilk Test of Normality
- Cronbach's Alpha

- Stats with R
- Stats with JamoviToggle Dropdown
- Maths ResourcesToggle Dropdown
- Numeracy ResourcesToggle Dropdown
- Stats/Maths Software
- A-Z of Terminology
- Meet the Team

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:

Similarly to the t-test, it can be run using a formula method or a variables 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
```

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.

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**.

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.

*F*(1,14) = 0.47, *p *=.506

- Last Updated: Jul 31, 2024 2:58 PM
- URL: https://guides.library.lincoln.ac.uk/mash
- Print Page

© University of Lincoln