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.

## 2 comments:

I note you force SAS to use type=abs, rather than the default type=square (of the residuals). Is there any way to use the squared residuals in the R Levene test?

Not in the function that's provided with the lawstat package, as far as I know. There may well be implementations in other packages, and it's likely that generating the test from scratch would not be too difficult, especially if you begin with the code included in the lawstat package.

Post a Comment