## 15.3 Checking the equal-variance assumption

Some statistical tests, such as the 2-sample *t*-test and ANOVA, assume that the variance (\(\sigma\)) of the numeric response variable is the same among the populations being compared.

For this we use the **Levene’s test**, which we implement using the `leveneTest`

function from the `car`

package:

`?leveneTest`

Like the Shapiro-Wilk test, the Levene’s test can be applied in a hypothesis testing framework, but when it is used to evaluate the equal-variance assumption, it need not be.

Nevertheless, the *implied* null hypothesis is that the variance of the numeric response variable is the same among the populations being compared. So in the case where a numeric variable is being compared among two groups, then the implied null hypothesis is that (\(\sigma\)(1) = \(\sigma\)(2). The usual \(\alpha\) level of 0.05 can be used.

We’ll use the “students” dataset, and check whether `height_cm`

exhibits equal variance among students with different dominant eyes (left or right).

Let’s look at the code, and explain after:

`<- leveneTest(height_cm ~ Dominant_eye, data = students) height.vartest `

If you get a warning about a variable being “coerced to factor”, that’s OK! It is simply telling you that it took the categorical variable and treated it as a ‘factor’ variable.

In the code chunk above we:

- assign the results to a new object called “height.vartest”
- use the
`leveneTest`

function, in which the arguments are:- the numeric response variable (“height_cm”)
- then the “~” symbol
- then the categorical variable “dominant_eye”
- then the “data = students” specifies the data object name

**TIP: **
The argument to the `leveneTest`

function that is in the form \(Y\) ~ \(X\) is one we’ll use several times.

Let’s look at the results:

` height.vartest`

```
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.907 0.3424
## 152
```

The results include:

- the degrees of freedom for the test
- the value of the test statistic “F”
- the
*P*-value associated with the test statistic

For the student height example, the *P*-value is greater than the standard \(\alpha\) of 0.05, so there’s no evidence against the assumption of equal variance.

A reasonable statement would be:

“A Levene’s test showed no evidence against the assumption of equal variance (

F= 0.91;P-value = 0.342).”

**TIP: **
As part of your main statistical test, such as a two-sample *t*-test or an ANOVA, you would typically provide a graph such as a stripchart or violin plot to visualize how the numeric response variable varies among the groups of the categorical explanatory variable. Such plots may often reveal that the spread of values of the response variable varies considerably among the groups, underscoring the need to check the equal variance assumption.