[R] within-subject factors in lme

lorenz.gygax at art.admin.ch lorenz.gygax at art.admin.ch
Wed Aug 22 12:52:40 CEST 2007


I don't think, this has been answered:

> I'm trying to run a 3-way within-subject anova in lme with 3
> fixed factors (Trust, Sex, and Freq), but get stuck with handling
> the  random effects. As I want to include all the possible random
> effects in the model, it would be something more or less
> equivalent to using aov
> 
>  > fit.aov <- aov(Beta ~ 
> Trust*Sex*Freq+Error(Subj/(Trust*Sex*Freq)),  
> Model)
> 
> However I'm not so sure what I should do in lme. Sure
> 
>  > lme(Beta ~ Trust*Sex*Freq, random = ~1|Subj, Model)
> 
> works fine, but it only models the random effect of the
> intercept. I tried the following 4 possibilities:

If I understand correctly, you want to include the interactions between the random and fixed terms? This is done like:

model.lme <- lme(Beta ~ Trust*Sex*Freq,
                 random = ~Trust*Sex*Freq|Subj, Model)

But this needs a lot of observations as quite a few parameters need to be estimated! Possibly, you can not include the variable Sex in this, because I assume that Subj is nested within Sex. If you just refer to within and between subject effects and their corresponding degrees of freedom: you should see this being handled automatically and correctly by lme e.g. in the output of anova (model.lme)

Lorenz
- 
Lorenz Gygax
Centre for proper housing of ruminants and pigs
Agroscope Reckenholz-Tänikon Research Station ART
Tänikon, CH-8356 Ettenhausen / Switzerland



More information about the R-help mailing list