Levene’s Test in R Programming - GeeksforGeeks (2024)

Last Updated : 16 Mar, 2023

Comments

Improve

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 hom*oscedasticity. It’s an alternative to Bartlett’s test that is less sensitive to departures from normality.

There are several solutions to test for the hom*ogeneity of variance (or hom*oscedasticity) across groups of samples are as follows:

  • F-Test
  • Bartlett’s test
  • Levene’s test
  • Fligner-Killeen test

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

Levene’s Test in R Programming - GeeksforGeeks (1)

Alternative Hypothesis: At least two of them differ

Levene’s Test in R Programming - GeeksforGeeks (2)

The test statistics for Levene’s test are:

Levene’s Test in R Programming - GeeksforGeeks (3)

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.

R

#import the dplyr library

library("dplyr")

# Print the random 5 sample

print(sample_n(PlantGrowth,5))

 
 

Output:

 weight group1 3.59 trt12 4.17 trt13 4.50 ctrl4 5.14 ctrl5 4.92 trt2

As mentioned above, Levene’s test is an alternative to Bartlett’s test when the data is not normally distributed. So, we consider the null and alternate hypotheses.

  • The Null hypothesis is variances across all samples are equal.
  • The alternative hypothesis is at least one sample has a different variance.
  • We will test the null hypothesis at 0.05 significance level i.e 95% percentile.

Here let’s consider only one independent variable. To perform the test, use the below command:

R

# R program to illustrate

# Levene’s test

# Import required package

library(car)

# Using leveneTest()

result = leveneTest(weight ~ group, PlantGrowth)

# print the result

print(result)

 
 

Output:

Levene's Test for hom*ogeneity of Variance (center = median) Df F value Pr(>F)group 2 1.1192 0.3412 27 

From the above result, we can observe that p-value = 0.34 which is greater than our significance level of 0.05. So, we do have not enough evidence to reject the null hypothesis. So the variance across the samples is equal at 0.05 significance level.

Df

F value

Pr(>F)

<int>

<dbl>

<dbl>

group

2

1.119186

0.3412266

27

NA

NA

Levene’s test with multiple independent variables:

Let’s consider the R’s inbuilt ToothGrowth dataset

R

#import the dplyr library

library("dplyr")

# Print the random 5 sample

print(sample_n(ToothGrowth,5))

 
 

Output:

 len supp dose1 23.6 VC 22 15.5 VC 13 16.5 VC 14 23.0 OJ 25 17.3 VC 1

If one wants to do the test with multiple independent variables then the interaction() function must be used to collapse multiple factors into a single variable containing all combinations of the factors. Here let’s take the R’s inbuilt ToothGrowth data set.

R

# R program to illustrate

# Levene’s test

# Import required package

library(car)

# Using leveneTest()

result = leveneTest(len ~ interaction(supp, dose),

data = ToothGrowth)

# print the result

print(result)

 
 

Output:

Levene's Test for hom*ogeneity of Variance (center = median) Df F value Pr(>F)group 5 1.7086 0.1484 54

From the above result, we can observe that p-value = 0.14 which is greater than our significance level of 0.05. So, we do have not enough evidence to reject the null hypothesis. So the variance across the samples is equal at 0.05 significance level.

Df

F value

Pr(>F)

<int>

<dbl>

<dbl>

group

5

1.708578

0.1483606

54

NA

NA



A

AmiyaRanjanRout

Levene’s Test in R Programming - GeeksforGeeks (4)

Improve

Next Article

Fligner-Killeen Test in R Programming

Please Login to comment...

Levene’s Test in R Programming - GeeksforGeeks (2024)
Top Articles
Pink Runtz Strain: Sweet and Potent Cannabis Delight
Pink Runtz – Weed Strain Information & Review
Varsity Competition Results 2022
Smoothie Operator Ruff Ruffman
Get maximum control with JCB LiveLink | JCB.com
Craigslist The Big Island
Greet In Cheshire Crossword Clue
Royal Bazaar Farmers Market Tuckernuck Drive Richmond Va
Al Horford House Brookline
Discover the Hidden Gems of Greenbush MI: A Charming Lakeside Retreat - 200smichigan.com (UPDATE 👍)
Pga Us Open Leaderboard Espn
Nusl Symplicity Login
Gt7 Roadster Shop Rampage Engine Swap
Ropro Cloud Play
Lesson 10 Homework 5.3
8 Garden Sprayers That Work Hard So You Don't Have To
Martimelons
Lima Crime Stoppers
1800Comcast
Cosmoprof Jobs
Minnesota Gophers Highlights
Tyrone Unblocked Games Bitlife
Tamilyogi. Vip
Simply Gorgeous! — Tecnam Completely Refreshed their Best-Selling Light-Sport Aircraft - ByDanJohnson.com
Gsa Elibary
All Obituaries | Dante Jelks Funeral Home LLC. | Birmingham AL funeral home and cremation Gadsden AL funeral home and cremation
Isaimini 2023: Tamil Movies Download HD Hollywood
What tools do you recommend for emceeing?
E41.Ultipro.com
Gulfport Senior Center Calendar
Danae Marie Supercross Flash
Check Subdomains Of A Domain
Eureka Mt Craigslist
افضل موقع سكسي عربي
Mtvkay21
Jeep Graphics Ideas
Acnh Picnic Table
Walmart Tune Up Near Me
Bridger Elementary Logan
Journal articles: 'State of New York and the Military Society of the War of 1812' – Grafiati
Nycda Login
Spearmint Rhino Coi Roll Call
R/Moissanite
Thotsbay New Site
How To Pause Tamagotchi Gen 2
Ups First And Nees
Alibaba Expands Membership Perks for 88VIP
Riscap Attorney Registration
Crandon Skyward
What to Know About Ophidiophobia (Fear of Snakes)
Roblox Mod Menu Platinmods
Battlenet We Couldn't Verify Your Account With That Information
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6048

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.