Joanne Lenehan
2009-Dec-01 05:52 UTC
[R] Amendment to previous post a minute ago, please amend before posting if possible
Sorry, I just posted the email below but realised I did not give a name or
details, would it be possible to adjust before posting and send what is
below, sorry again, first time user...
From: Joanne Lenehan [mailto:jlenehan@une.edu.au]
Sent: Tuesday, 1 December 2009 3:51 PM
To: 'r-help@r-project.org'
Subject: GLM Repeated measures test of assumptions: e.g. test for sphericity
e.g. Bartletts and Levenes homogenous variances
Hello and thanks in advance
I am running a glm in R the code is as follows with residual diagnostic code
below
model4<-glm(Biomass~(Treatment+Time+Site)^2, data=bobB,
family=quasi(link="log", variance="mu"))
par(mfrow=c(2,2))
plot(model2)
to test the effect of grazing exclusion of feral horses for a Phd with
following factors:
Treatment - 3 levels which are grazed controls (C), ungrazed horse
exclosures (H)with 3 wire strand fence to allow other herbivores but not
horses and ungrazed full netting exclosures to exclude all herbivores (A)
Site - 6 levels for 6 Sites which are considered fixed
Time - 6 levels also for 6 different monitoring or time periods which is
where the repeated measures comes in
In SPSS there is the option for Bartlett's test of sphericity and
Levene's
test for whether the variability is homogenous or not. Is it possible to do
the same in R with glm? If not, what is the equivalent for testing these
assumptions? Also, is it valid to use Tukey's post hocs to test main
effects if necessary? If not, is there another method other than contrasts,
something to do with multicomp?
In a previous model where Site was random I used the following lme model
model2<-lme(Anncov~Treat*Time, random=~1|Site,
data=bob,control=list(opt="optim"))
And checked residuals using:
print(shapiro.test(model1$residuals))
print(qqnorm(model1))
#resids vs fitted
plot(model1,resid(.,type="p")~fitted(.)|Site, abline=0)
#boxplot of resids
plot(model1,Anncov~fitted(.)|Site, abline=c(0,1))
And because you can't use Mauchly sphericity test used instead:
library(ts)
bob$resids<-model1$residuals[,2]
site.level<-levels(bob$Site)
par(mfrow=c(4,4), mar=c(2,4,0,0), oma=c(2,2,4,2))
for (i in seq(along=site.level)){
datain<-bob$Site==site.level[i]
acf(bob[datain,"resids"],xlab="", ylab="",
main=paste("Site", site.level[i]),las=1)
} #end loop
BUT WHEN I TRIED THE ABOVE FOR GLM IT WOULD NOT WORK
And because can't use Tukeys used contrasts but heard recently about
multicomp?
I also checked and compared several variance covariance symmetry's using the
following:
compoundspec<-lme(Anncov~Treat*Time, random=~1|Site,
data=bob,cor=corCompSymm(,form=~1|Site), control=list(opt="optim"))
autoregressivesite<-lme(Anncov~Treat*Time, random=~1|Site,
data=bob,cor=corAR1(,form=~1|Site), control=list(opt="optim"))
autoheterosite<-lme(Anncov~Treat*Time, random=~1|Site,
data=bob,cor=corAR1(,form=~1|Site),weight=varIdent(form=~1|Time),
control=list(opt="optim"))
unstructsite<-lme(Anncov~Treat*Time, random=~1|Site,
data=bob,cor=corSymm(,form=~1|Site),weight=varIdent(form=~1|Time),
control=list(opt="optim"))
And then anova to compare the models
SHOULD I DO THE SAME BUT IS THERE A BETTER WAY?
SO IN SUMMARY - BACK TO ORIGINAL QUESTION HOW TO TEST ASSUMPTIONS OF GLM IN
R?
Many many thanks in advance for anyone who reads or responds.
Kind regards
Joanne Lenehan
PhD Candidate
University of New England Armidale NSW
02 6773 3723
[[alternative HTML version deleted]]
