[R] Help with Bartlett's test on linear model

Emmanuel Charpentier charpent at bacbuc.dyndns.org
Thu Nov 15 00:07:13 CET 2007


Stephanie Bernard a écrit :
> Hi all,
> I would like to test the homoegeneity of variances between several
> linear model for some analysis of covariance. It seems that the
> Bartlett's test is a good test to use but I am having problem using with
> linear model and I cannot find any examples on the internet. There are
> some examples for comparisons of variances but not linear models.
> If I take the hellung data set, which is the example in Dalgaard's book.
> I know var.test works fine but I want to learn how to use the Bartlett's
> test.
>> hellung$glucose <- factor(hellung$glucose, labels=c("Yes","No"))
>> attach(hellung)
>> tethym.gluc <- hellung[glucose=="Yes",]
>> tethym.nogluc <- hellung[glucose=="No",]
>> lm.nogluc <- lm(log10(diameter)~log10(conc), data=tethym.nogluc)
>> lm.gluc <- lm(log10(diameter)~log10(conc), data=tethym.gluc)
> I guess I have two questions. 1) How to use bartlett.test with linear
> model (using the model above)

Please look at ?bartlett.test. This generic has methods both for
formulae (formulas ?) and for objects inheriting from the class "lm".
Therefore you might call :
bartlett.test(nogluc)
and
bartlett.test(gluc)
or (equivalently, I think)
bartlett.test(log10(diameter)~log10(conc), data=tethym.nogluc)
etc ... ad nauseam.

and 2) how to test for homogeneity of
> variances of linear models when there are more than two groups.


As the "?bartlett.test" will tell you, this function "[p]erforms
Bartlett's test of the null that the variances in each of the groups
(samples) are the same", which is exactly what you aim at...

HTH

					Emmanuel Charpentier



More information about the R-help mailing list