# Example 9.36: Levene’s test for equal variances

June 25, 2012
By

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The assumption of equal variances among the groups in analysis of variance is an expression of the assumption of homoscedasticity for linear models more generally. For ANOVA, this assumption can be tested via Levene’s test. The test is a function of the residuals and means within each group, though various modifications are used, including the Brown-Forsythe test. This uses the medians within group, rather than the mean, and is recommended when normality may be suspect.

We illustrate using the HELP data set available here, modeling depressive symptoms (assessed via CESD) as a function of abused substance.

SAS
In SAS, the tests are available as an option to the means statement in proc glm

`data help;set "C:\book\help.sas7bdat";run;proc glm data = help;class substance;model cesd = substance;means substance / hovtest=levene(type=abs) hovtest=bf;run;`

The two requested tests are a version of Levene’s test that is produced in R, below, and the aforementioned Brown-Forsythe test. The relevant results are shown below.

`           Levene's Test for Homogeneity of CESD Variance           ANOVA of Absolute Deviations from Group Means                           Sum of        Mean  Source           DF     Squares      Square    F Value    Pr > F  SUBSTANCE         2       272.4       136.2       2.61    0.0747  Error           450     23480.7     52.1793     Brown and Forsythe's Test for Homogeneity of CESD Variance          ANOVA of Absolute Deviations from Group Medians                           Sum of        Mean  Source           DF     Squares      Square    F Value    Pr > F  SUBSTANCE         2       266.0       133.0       2.46    0.0864  Error           450     24310.9     54.0243`

There’s some suggestion of a lack of homoscedasticity; it might be wise to consider methods robust to violations of this assumption.

R
In R, the test can be found in the levene.test() function in the lawstat package.

`help = read.csv("http://www.math.smith.edu/r/data/help.csv")library(lawstat)with(help, levene.test(cesd, as.factor(substance), location="mean")) classical Levene's test based on the absolute deviations from the mean           ( none not applied because the location is not set to median )data:  cesd Test Statistic = 2.6099, p-value = 0.07465with(help, levene.test(cesd, as.factor(substance),location="median")) modified robust Brown-Forsythe Levene-type test based on the absolute            deviations from the mediandata:  cesd Test Statistic = 2.462, p-value = 0.08641` R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.