[R] within-subject factors in lme

Gang Chen gangchen at mail.nih.gov
Mon Aug 20 19:51:05 CEST 2007


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:

 > lme(Beta ~ Trust*Sex*Freq, random = pdBlocked(list(pdCompSymm 
(~Trust-1), pdCompSymm(~Sex-1), pdCompSymm(~Freq-1), pdIdent(~1))),  
Model)
 > lme(Beta ~ Trust*Sex*Freq, random = pdBlocked(list(pdCompSymm(~ 
(Trust*Sex*Freq-Trust:Sex:Freq-1)), pdIdent(~1))), Model)
 > lme(Beta ~ Trust*Sex*Freq, random = pdBlocked(list(pdCompSymm(~ 
(Trust*Sex*Freq-1)), pdIdent(~1))), Model)
 > lme(Beta ~ Trust*Sex*Freq, random = pdBlocked(list(pdCompSymm 
(~Trust-1), pdCompSymm(~Sex-1), pdCompSymm(~Freq-1), pdCompSymm(~ 
(Trust-1)*(Sex-1)), pdCompSymm(~(Trust-1)*(Freq-1)), pdCompSymm(~ 
(Sex-1)*(Freq-1)), pdIdent(~1))), Model)

but all failed with the same error message:

Error in getGroups.data.frame(dataMix, groups) :
         Invalid formula for groups

What am I missing?

Saw a similar situation in the archives, but I'm still clueless about  
the solution:

http://tolstoy.newcastle.edu.au/R/e2/help/07/01/8431.html

Any help would be highly appreciated.

Gang



More information about the R-help mailing list