- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In general, we can say that the homogeneity of variance test is the type of test that compares the variance of two or more variables and finds the significant difference between or among them if exists. For a two-way anova, one of the most commonly used homogeneity of variance test is Levene’s Test and it can be easily done with the help of leveneTest function of car package in base R.

Consider the below data frame −

set.seed(151) x1<-sample(c("C1","C2","C3"),20,replace=TRUE) x2<-sample(c("S1","S2","S3","S4","S5"),20,replace=TRUE) y<-rnorm(20,5,2) df1<-data.frame(x1,x2,y) df1

x1 x2 y 1 C2 S2 2.255857 2 C3 S5 1.726474 3 C3 S4 4.280697 4 C2 S3 7.402230 5 C2 S3 3.708252 6 C2 S4 3.978782 7 C2 S1 3.801754 8 C3 S3 6.091206 9 C2 S3 4.017412 10 C3 S3 5.383071 11 C3 S1 3.882945 12 C1 S5 6.845399 13 C1 S1 7.307996 14 C3 S4 2.255179 15 C1 S5 7.580363 16 C2 S5 7.309804 17 C2 S4 7.891359 18 C2 S3 5.522026 19 C3 S4 8.858292 20 C1 S1 3.800228

Loading car package and performing Levene’s test on df1 −

library(car) leveneTest(y~x1*x2,data=df1) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 9 1.5987 0.2374 10

Let’s have a look at another example −

Age_group<-sample(c("First","Second"),20,replace=TRUE) Ethnicity<-sample(c("Asian","NorthAmerican","Chinese","Japanese"),20,replace=TRUE) Salary<-sample(20000:50000,20) df2<-data.frame(Age_group,Ethnicity,Salary) df2

Age_group Ethnicity Salary 1 Second NorthAmerican 25678 2 Second Asian 34597 3 Second Chinese 49861 4 Second Chinese 37386 5 First Japanese 38426 6 Second NorthAmerican 45889 7 Second Asian 35033 8 Second NorthAmerican 46098 9 First Japanese 34070 10 Second Japanese 33618 11 First Japanese 35760 12 Second Chinese 33376 13 Second NorthAmerican 30630 14 First Asian 23820 15 Second Asian 40899 16 First Asian 35095 17 Second Chinese 43439 18 First Japanese 35641 19 Second Asian 41754 20 Second NorthAmerican 35337

Performing Levene’s test on df2 −

leveneTest(Salary~Age_group*Ethnicity,data=df2) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 6 0.6593 0.6835 13

- Related Questions & Answers
- How to perform one-way anova with unequal sample sizes in R?
- How to find the critical value of F for one-way ANOVA in R?
- How to perform chi square test for goodness of fit in R?
- How to perform fisher test in R?
- How to perform Friedman test in R?
- How to perform post hoc test for Kruskal-Wallis in R?
- How to perform paired t test for multiple columns in R?
- How to find the critical value of F for regression anova in R?
- How to perform Wilcoxon test for all columns in an R data frame?
- How to perform shapiro test for all columns in an R data frame?
- How to perform cartesian join for two data.table objects in R?
- How to perform one sample Kolmogorov-Smirnov test in R?
- How to test for the difference between two regression coefficients in R?
- How to calculate population variance in R?
- How to test for significant relationship between two categorical columns of an R data frame?

Advertisements