Levene’s Test in R Programming

Levene’s test is an inferential statistic used to check if the variances of a variable obtained for two or more groups are equal or not when data comes from a non-normal distribution.

Levene’s test is used to check the assumptions that the variances of the populations from different samples drawn are equal or not before running the test like ANOVA. It tests the null hypothesis that the population variances are equal or not, It is known as homoscedasticity. It’s an alternative to Bartlett’s test that is less sensitive to departures from normality.

There are several solutions to test for the homogeneity of variance (or homoscedasticity) across groups of samples are as follows:

It is very much easy to perform these tests in R programming. In this article let’s perform Levene’s test in R.

Statistical Hypotheses for Levene’s test

A hypothesis is a statement about a given problem. Hypothesis testing is a statistical method that is used in making a statistical decision using experimental data. Hypothesis testing is basically an assumption that we make about a population parameter. It evaluates two mutually exclusive statements about a population to determine which statement is best supported by the sample data. To know more about the statistical hypothesis please refer to Understanding Hypothesis Testing. For Levene’s test, the statistical hypotheses are:

Null Hypothesis: All populations variances are equal

H_0 :\sigma_1^2 = \sigma_2^2 = . =\sigma_n^2

Alternative Hypothesis: At least two of them differ

 

The test statistics for Levene’s test are:

W = \frac{\left ( N - k \right )\sum_{i=1}^{K}N_{i} \left ( Z_{i} - Z.. \right )^2}{ \left ( K-1 \right )\sum_{i=1}^{K} \sum_{j=1}^{N_i}\left ( Z_{ij}- Z_i \right )^2}

Levene’s Test in R

R provides a function leveneTest() which is available in the car package that can be used to compute Levene’s test. The syntax for this function is given below:

Syntax: leveneTest(formula, dataset)

Parameters:

formula: a formula of the form values ~ groups

dataset: a matrix or data frame

Example of Lavene’s test

Levene’s test with one independent variable:

Consider the R’s inbuilt PlantGrowth dataset that gives the dried weight of three groups of ten batches of plants, wherever every group of ten batches got a different treatment. The weight variable gives the weight of the batch and the group variable gives the treatment received either ctrl, trt1, or trt2. To view the random 5 rows of the PlantGrowth dataset use the sample_n() function from the dplyr library.