Example 9.36: Levene’s test for equal variances

[This article was first published on SAS and R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
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.07465

with(help, levene.test(cesd, as.factor(substance),location="median"))

 modified robust Brown-Forsythe Levene-type test based on the absolute 
           deviations from the median

data:  cesd 
Test Statistic = 2.462, p-value = 0.08641


An unrelated note about aggregators:We love aggregators! Aggregators collect blogs that have similar coverage for the convenience of readers, and for blog authors they offer a way to reach new audiences. SAS and R is aggregated by R-bloggers, PROC-X, and statsblogs with our permission, and by at least 2 other aggregating services which have never contacted us. If you read this on an aggregator that does not credit the blogs it incorporates, please come visit us at SAS and R. We answer comments there and offer direct subscriptions if you like our content. In addition, no one is allowed to profit by this work under our license; if you see advertisements on this page, the aggregator is violating the terms by which we publish our work.

To leave a comment for the author, please follow the link and comment on their blog: SAS and R.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)