[R] repeated measure one way anova
Chris Evans
chrishold at psyctc.org
Wed Oct 29 01:42:04 CET 2008
JohnLi sent the following at 28/10/2008 19:56:
> Thanks a lot ! I learn a lot about R while I solve my problem according to
> those provided informatin.
Me too: thanks all.
This particular question has suddenly become relevant to me as I'm
trying to do a bit of simulating to model power for a repeated measures
ANOVA and I'm caught away from my books and challenged by ageing brain.
... some snipped ...
>>> Use package nlme, function lme. It might be a bit of an overkill for the
>>> simple
>>> case, but always worth the effort when things get more complex
>>>
>>> libary(nlme)
>>> summary(lme(c~time, random=~1|subj,data=mydata)
>> There is also anova.mlm:
>>
>> d <- read.table("clipboard", header=T)
>> Y <- as.matrix(d)
>> fit1 <- lm(Y~1)
>> fit0 <- lm(Y~0)
>> anova(fit0, fit1, X=~1, test="Spherical")
>> anova(fit0, fit1, X=~1, test="Wilks")
OK. Now my stupid question. I want to model a situation in which
people are measured at three points on a scale and in the model I'm
starting with a linear fall in scores with occasion.
I can think of three ways to test this change: nlme for a mixed model,
lm for a classical repeated measures ANOVA and anova.mlm for the MANOVA
approach. So here's some of my code from within my simulation function:
scores <- c(baseline,mid,end) ## simulated data
lm.ID <- rep(1:size,3)
occ <- rep(1:3,each=size)
tmp.lme <- lme(scores ~ occ, random=~1|lm.ID)
names(tmp.lme)
nlme.coeff <- tmp.lme[4]$coefficients$fixed[2]
tmp.sum <- summary(tmp.lme)
nlme.p <- unlist(tmp.sum[19])[10]
mlmfit <- lm(lm.scores ~ 1)
mlmfit0 <- update(mlmfit, ~0)
tmp.man <- anova(mlmfit,mlmfit0,X=~1,test="Wilks")
manova.p <- tmp.man[8][2,1]
Am I right that the above extracts the p value for the nlme test of the
individual slopes of score against occasion and then the MANOVA test ...
of no difference between occasions?
How would I ask for a conventional univariate ANOVA repeated measures lm
model and its test? Sorry, I know I should know but I don't and can't
see it in ?lm, ?formula.
TIA,
Chris
--
Chris Evans <chris at psyctc.org> Skype: chris-psyctc
Professor of Psychotherapy, Nottingham University;
Consultant Psychiatrist in Psychotherapy, Notts PDD network;
Research Programmes Director, Nottinghamshire NHS Trust;
*If I am writing from one of those roles, it will be clear. Otherwise*
*my views are my own and not representative of those institutions *
More information about the R-help
mailing list