On Mar 21, 2012, at 11:27 , Marco Tommasi 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.
Well, it would primarily concern the maintainer of the "car" package, which is the one containing the (capital-A) Anova() function. The type III SS don't look right to me either. With aov() we get > M3l <- reshape(M3, direction="long", varying=c("b1","b2","b3"),sep="") > summary(aov(b~fattA*factor(time)+ Error(factor(id)), M3l)) Error: factor(id) Df Sum Sq Mean Sq F value Pr(>F) fattA 1 26.042 26.042 16.3 0.00682 ** Residuals 6 9.583 1.597 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Error: Within Df Sum Sq Mean Sq F value Pr(>F) factor(time) 2 42.33 21.167 23.81 6.65e-05 *** fattA:factor(time) 2 20.33 10.167 11.44 0.00166 ** Residuals 12 10.67 0.889 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > 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) >> a5<-Anova(f5) > >> f6<-lm(c(b1,b2,b3)~rep(fattA,3),data=M3) >> >> >> fB<-factor(c(1:3)) >> d2<-data.frame(fB) >> a6<-Anova(f5,idata=d2,idesign=~fB,type=2) > >> summary(a6,multivariate=F) > > Univariate Type II Repeated-Measures ANOVA Assuming Sphericity > > SS num Df Error SS den Df F Pr(>F) > (Intercept) 1080.04 1 9.5833 6 676.200 2.133e-07 *** > fattA 26.04 1 9.5833 6 16.304 0.006819 ** > fB 42.33 2 10.6667 12 23.812 6.645e-05 *** > fattA:fB 20.33 2 10.6667 12 11.438 0.001660 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > Mauchly Tests for Sphericity > > Test statistic p-value > fB 0.87891 0.7242 > fattA:fB 0.87891 0.7242 > > > Greenhouse-Geisser and Huynh-Feldt Corrections > for Departure from Sphericity > > GG eps Pr(>F[GG]) > fB 0.89199 0.0001474 *** > fattA:fB 0.89199 0.0026452 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > HF eps Pr(>F[HF]) > fB 1.2438 6.645e-05 *** > fattA:fB 1.2438 0.00166 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > Warning message: > In summary.Anova.mlm(a6, multivariate = F) : HF eps > 1 treated as 1 > > > I repated the anlysis by setting type III sum of squares and I obtained: > >> a6<-Anova(f5,idata=d2,idesign=~fB,type=3) >> summary(a6,multivariate=F) > > Univariate Type III Repeated-Measures ANOVA Assuming Sphericity > > SS num Df Error SS den Df F Pr(>F) > (Intercept) 30.817 1 9.5833 6 19.294 0.004606 ** > fattA 26.042 1 9.5833 6 16.304 0.006819 ** > fB 40.133 2 10.6667 12 22.575 8.57e-05 *** > fattA:fB 20.333 2 10.6667 12 11.438 0.001660 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > Mauchly Tests for Sphericity > > Test statistic p-value > fB 0.87891 0.7242 > fattA:fB 0.87891 0.7242 > > > Greenhouse-Geisser and Huynh-Feldt Corrections > for Departure from Sphericity > > GG eps Pr(>F[GG]) > fB 0.89199 0.0001851 *** > fattA:fB 0.89199 0.0026452 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > HF eps Pr(>F[HF]) > fB 1.2438 8.57e-05 *** > fattA:fB 1.2438 0.00166 ** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > Warning message: > In summary.Anova.mlm(a6, multivariate = F) : HF eps > 1 treated as 1 > > > As you can see, the sum of squares of the within factor "fB" and of the > intercept obtained by setting type II sum of squares are dofferent form > those obtained by setting type III sum of squares. I repeated the > analysis by using SPPS (type II and III) and i obtained the same sum of > squares for both types., which I report below: > > within factor and interaction > source Sum of squares (type II and III) > fB 42.33333333 > fB * fattA 20.33333333 > Error(fattB) 10.66666667 > > between factor > Source Sum of squares (type II and III) > intercept 1080.041667 > fattA 26.04166667 > Error 9.583333333 > > The most strange thing, for me, is not only that R gives different > outputs both for type II and III sum of squares, but that the output > obtained with type II sum of squares in R coincides with the output > obtained with type III of SPSS. > > As I remember, with balanced design, type II and III sum of squares > should give the same output. > > > Is there anybody that can help me about this point? > > > thank you for your kind attention. > > Marco Tommasi, Ph/D. > > > Department of Neuroscience and Imaging > "G. D'Annunzio" University of Chieti-Pescara > Via dei Vestini 31 > 66100 Chieti > ITALY > > e-mail: marco.tomm...@unich.it </mc/compose?to=marco.tomm...@unich.it> > tel.: +39 0871 3555890 / fax: + 39 0871 3554163 > Web site: www.dni.unich.it > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@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.