[R] Help please! How to code a mixed-model with 2 within-subject factors using lme or lmer?

Mark Difford mark_difford at yahoo.co.uk
Sun Sep 14 15:36:21 CEST 2008


Hi Roberto,

>> but I can't figure out the /(Lobe*Tissue) part...

This type of nesting is easier to do using lmer(). To do it using lme() you
have to generate the crossed factor yourself. Do something like this:

##
tfac <- with(vslt, interaction(Lobe, Tissue, drop=T))
str(tfac); head(tfac)
mod2<-lme(Volume ~ Val*Lobe*Tissue, random = ~1|Subject/tfac, data = vslt)

Pre-Scriptum: You can also use ?":" but ?interaction is more flexible and
powerful.

Regards, Mark.


roberto toro wrote:
> 
> Hello,
> 
> I'm using aov() to analyse changes in brain volume between males and
> females. For every subject (there are 331 in total) I have 8 volume
> measurements (4 different brain lobes and 2 different tissues
> (grey/white matter)). The data looks like this:
> 
> Subject	Sex	Lobe	Tissue	Volume
> subect1	1	F	g	262374
> subect1	1	F	w	173758
> subect1	1	O	g	67155
> subect1	1	O	w	30067
> subect1	1	P	g	117981
> subect1	1	P	w	85441
> subect1	1	T	g	185241
> subect1	1	T	w	83183
> subect2	1	F	g	255309
> subect2	1	F	w	164335
> subect2	1	O	g	71769
> subect2	1	O	w	31879
> subect2	1	P	g	120518
> subect2	1	P	w	90334
> subect2	1	T	g	168413
> subect2	1	T	w	75790
> subect3	0	F	g	243621
> subect3	0	F	w	167025
> subect3	0	O	g	65998
> subect3	0	O	w	29758
> subect3	0	P	g	118026
> subect3	0	P	w	91903
> subect3	0	T	g	156279
> subect3	0	T	w	82349
> ....
> 
> I'm trying to see if there is an interaction Sex*Lobe*Tissue. This is
> the command I use with aov():
>       
> mod1<-aov(Volume~Sex*Lobe*Tissue+Error(Subject/(Lobe*Tissue)),data.vslt)
> 
> Subject is a random effect, Sex, Lobe and Tissue are fixed effects;
> Sex is an outer factor (between subjects), and Lobe and Tissue are
> inner factors (within-subjects); and there is indeed a significant
> 3-way interaction.
> 
> I was told, however, that the results reported by aov() may depend on
> the order of the factors
> (type I anova), and that is better to use lme() or lmer() with type
> II, but I'm struggling to find the right syntaxis...
> 
> To begin, how should I write the model using lme() or lmer()??
> 
> I tried this with lme():
>        
> gvslt<-groupedData(Volume~1|Subject,outer=~Val,inner=list(~Lobe,~Tissue),data=vslt)
>         mod2<-lme(Volume~Val*Lobe*Tissue,random=~1|Subject,data=gvslt)
> 
> but I have interaction terms for every level of Lobe and Tissue, and 8
> times the number of DF I should have... (around 331*8 instead of
> ~331).
> 
> Using lmer(), the specification of Subject as a random effect is
> straightforward:
> 
>         mod2<-lmer(Volume~Sex*Lobe*Tissue+(1|Subject),data.vslt)
> 
> but I can't figure out the /(Lobe*Tissue) part...
> 
> Thank you very much in advance!
> roberto
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Help-please%21-How-to-code-a-mixed-model-with-2-within-subject-factors-using-lme-or-lmer--tp19479860p19480387.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list