[R] Two-way ANOVA gives different results using anova(lm()) than doing it by hand
Lars Bergemann
lars.bergemann at hotmail.com
Wed Jul 8 16:34:35 CEST 2009
Hey!
Could you please take a quick look at what I have done? Somehow I get wrong results using the anova(lm()) combination compared to doing a two way ANOVA by hand.
Running:
Data<-read.table("Data.txt");
g<-lm(ExM~S1*S2,Data);
anova(g);
Gives:
Analysis of Variance Table
Response: ExM
Df Sum Sq Mean Sq F value Pr(>F)
S1 1 4.3679 4.3679 167.045 < 2.2e-16 ***
S2 1 0.9427 0.9427 36.053 8.236e-09 ***
S1:S2 1 0.3231 0.3231 12.357 0.0005371 ***
Residuals 212 5.5434 0.0261
I compared it to the work done by hand, ie calculated all the different square sums using sum() and tapply().
So I know that anova(lm()) gets the degrees of freedom equal two 1, 1, 1 and 212 when it should be 5, 5, 25 and 180. Also, the square sums are quite different ... I get 4.xx, 4.xx, 1.xx, 0.xx ... as you see, what anova(lm()) gets is different.
The data: S1 has 6 levels, so has S2. On average, each cell has 6 values, most cells have actually 6 values, and there are two of each: 5, 7, 4, 8 - so average 6.
Could you please help me, why it does not work with anova(lm())? I tried quite a few thinks found with Google, but it all gave me the same result as anova(lm()) ...
Thanks a lot!
Lars
_________________________________________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090708/19a66254/attachment-0002.txt>
More information about the R-help
mailing list