Example 9.36: Levene’s test for equal variances

June 25, 2012

(This article was first published on SAS and R, and kindly contributed to R-bloggers)

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.

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

data help;
set "C:\book\help.sas7bdat";

proc glm data = help;
class substance;
model cesd = substance;
means substance / hovtest=levene(type=abs) hovtest=bf;

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.

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")
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 his blog: SAS and R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.