El d?a 21/03/2012 a las 11:27, Marco Tommasi
<marco.tommasi at unich.it> wrote
To whom it may concern I made some analysis with R using the command Anova. However, I found
some problmes with the output obtained by selecting type II o type
III
sum of squares. Briefly, I have to do a 2x3 mixed model anova, wherein the first
factor
is a between factor and the second factor is a within factor. I use
the
command Anova in the list below, because I want to obtain also the
sum
of squares of the linear and quadratic contrast between the levels of
the within factor.
Below I report the list of commands used in R ("fattA" is the
beteween
factor and "fB" is the within factor):
> a1b1<-c(10,9,8,7)
> a1b2<-c(7,6,4,5)
> a1b3<-c(3,2,3,4)
> a2b1<-c(9,9,8,7)
> a2b2<-c(8,7,9,7)
> a2b3<-c(7,8,8,6)
>
> M3<-matrix(0,8,4)
> M3[,1]<-cbind(a1b1,a2b1)
> M3[,2]<-cbind(a1b2,a2b2)
> M3[,3]<-cbind(a1b3,a2b3)
> M3[,4]<-rep(c(1,2),each=4)
>
> colnames(M3)<-c("b1","b2","b3","fattA")
>
> M3<-as.data.frame(M3)
>
> require(car)
Loading required package: car Loading required package: MASS Loading required package: nnet
> f5<-lm(cbind(b1,b2,b3)~fattA,data=M3)
You are missing a couple of important points here. First, fattA is a factor according to your description, but you have coded it as a numeric variable. You must coerce it to factor: M3$fattA <- as.factor(M3$fattA) Now, type III SS with Anova() only provides sensible results, if the factor contrasts are orthogonal, e.g. "contr.sum", "contr.poly", or "contr.helmert". This is not the default in R, so you should make it explicit: f5<-lm(cbind(b1,b2,b3)~fattA,data=M3, contrasts=list(fattA="contr.sum")) Now, Anova() gives the same results regardless of the SS type:
> fB<-factor(c(1:3)) > d2<-data.frame(fB)
Try: summary(Anova(f5,idata=d2,idesign=~fB,type=2),multivariate=FALSE) summary(Anova(f5,idata=d2,idesign=~fB,type=3),multivariate=FALSE) I recommend you read Fox's and Weisberg's book that explain many functions of "car", including ANOVA. See specially pages 193 and following. Type carWeb() to go to its webpage. Helios INSTITUTO DE BIOMEC?NICA DE VALENCIA Universidad Polit?cnica de Valencia ? Edificio 9C Camino de Vera s/n ? 46022 VALENCIA (ESPA?A) Tel. +34 96 387 91 60 ? Fax +34 96 387 91 69 www.ibv.org Antes de imprimir este e-mail piense bien si es necesario hacerlo. En cumplimiento de la Ley Org?nica 15/1999 reguladora de la Protecci?n de Datos de Car?cter Personal, le informamos de que el presente mensaje contiene informaci?n confidencial, siendo para uso exclusivo del destinatario arriba indicado. En caso de no ser usted el destinatario del mismo le informamos que su recepci?n no le autoriza a su divulgaci?n o reproducci?n por cualquier medio, debiendo destruirlo de inmediato, rog?ndole lo notifique al remitente.