leveneTest.RdComputes Levene's test for homogeneity of variance across groups.
leveneTest(y, ...)
# S3 method for class 'formula'
leveneTest(y, data, ...)
# S3 method for class 'lm'
leveneTest(y, ...)
# Default S3 method
leveneTest(y, group, center=median, ...)response variable for the default method, or a lm or
formula object. If y is a linear-model object or a formula,
the variables on the right-hand-side of the model must all be factors and
must be completely crossed.
factor defining groups.
The name of a function to compute the center of each group;
mean gives the original Levene's test; the default, median,
provides a more robust test.
a data frame for evaluating the formula.
arguments to be passed down, e.g., data for the
formula and lm methods; can also be used to pass arguments to
the function given by center (e.g., center=mean and
trim=0.1 specify the 10% trimmed mean).
returns an object meant to be printed showing the results of the test.
Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third Edition. Sage.
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.
adapted from a response posted by Brian Ripley to the r-help email list.
with(Moore, leveneTest(conformity, fcategory))
#> Levene's Test for Homogeneity of Variance (center = median)
#> Df F value Pr(>F)
#> group 2 0.046 0.9551
#> 42
with(Moore, leveneTest(conformity, interaction(fcategory, partner.status)))
#> Levene's Test for Homogeneity of Variance (center = median)
#> Df F value Pr(>F)
#> group 5 1.4694 0.2219
#> 39
leveneTest(conformity ~ fcategory*partner.status, data=Moore)
#> Levene's Test for Homogeneity of Variance (center = median)
#> Df F value Pr(>F)
#> group 5 1.4694 0.2219
#> 39
leveneTest(lm(conformity ~ fcategory*partner.status, data=Moore))
#> Levene's Test for Homogeneity of Variance (center = median)
#> Df F value Pr(>F)
#> group 5 1.4694 0.2219
#> 39
leveneTest(conformity ~ fcategory*partner.status, data=Moore, center=mean)
#> Levene's Test for Homogeneity of Variance (center = mean)
#> Df F value Pr(>F)
#> group 5 1.7915 0.1373
#> 39
leveneTest(conformity ~ fcategory*partner.status, data=Moore, center=mean, trim=0.1)
#> Levene's Test for Homogeneity of Variance (center = mean: 0.1)
#> Df F value Pr(>F)
#> group 5 1.7962 0.1363
#> 39