[R] How do I compute interactions with anova.mlm ?

Schadwinkel, Stefan Stefan.Schadwinkel at med.uni-heidelberg.de
Tue Sep 9 10:18:04 CEST 2008


Hi,

I wish to compute multivariate test statistics for a within-subjects repeated measures design with anova.mlm. 

This works great if I only have two factors, but I don't know how to compute interactions with more than two factors. 
I suspect, I have to create a new "grouping" factor and then test with this factor to get these interactions (as it is hinted in R News 2007/2), 
but I don't really know how to use this approach. 

Here is my current code:

Two Factors: fac1, fac2

mlmfit <- lm(mydata~1)
mlmfit0 <- update(mlmfit, ~0)

% test fac1, works, produces same output as SAS
anova(mlmfit, mlmfit0, M = ~ fac1 + fac2, X = ~ fac2, idata = idata, test = "Wilks")

% test fac1*fac2 interaction, also works, also the same output as SAS
anova(mlmfit, mlmfit0, X = ~ fac1 + fac2, idata = idata, test = "Wilks")



Three Factors: fac1, fac2, fac3 

mlmfit <- lm(mydata~1)
mlmfit0 <- update(mlmfit, ~0)

% test fac1, works, same as SAS
anova(mlmfit, mlmfit0, M = ~ fac1 + fac2 + fac3, X = ~ fac2 + fac3, idata = idata, test = "Wilks")



Now, I try to compute the interactions the same way, but this doesn't work:

% fac1*fac2
anova(mlmfit, mlmfit0, M = ~ fac1 + fac2 + fac3, X = ~ fac3, idata = idata, test = "Wilks") 

% fac1*fac2*fac3
anova(mlmfit, mlmfit0, X = ~ fac1 + fac2 + fac3, idata = idata, test = "Wilks")


Both of these above differ quite much from the SAS output and I suspect, my understanding of X and M is somewhat flawed. 

I would be very happy, if someone could tell me how to compute the two interactions above and an interaction of N factors in general.

I would also be interested in computing linear contrasts using the T matrix and anova.mlm.

Thank you very much,

Stefan 

 

--
Stefan Schadwinkel, Dipl.-Inf.
Neurologische Klinik
Sektion Biomagnetismus
Universität Heidelberg
Im Neuenheimer Feld 400
69120 Heidelberg

Telefon:  06221 - 56 5196
Email:    stefan.schadwinkel at med.uni-heidelberg.de 



More information about the R-help mailing list