[R] ANOVA results in R conflicting with results in other software packages

Richard M. Heiberger rmh at temple.edu
Thu Apr 26 04:16:27 CEST 2007


It looks from your tables that you have the same residual
in both programs, suggesting that the arithmetic is correct.
The terms are in a different order.  Since anova() gives
sequential sums of squares (Type I), the numerical values
depend on the order.  Force both programs to use the
same order for the terms.  Here is how in R.

> tmp <- data.frame(y=rnorm(12), 
+                   a=factor(rep(letters[1:2],6)),
+                   b=factor(rep(letters[3:5], each=4)),
+                   d=factor(rep(LETTERS[6:9], each=3)))

> anova(aov(terms(y ~ a*b + d, keep.order=TRUE), data=tmp))
Analysis of Variance Table

Response: y
          Df Sum Sq Mean Sq F value  Pr(>F)  
a          1 4.3786  4.3786 11.5479 0.04252 *
b          2 0.0688  0.0344  0.0907 0.91567  
a:b        2 2.1225  1.0612  2.7988 0.20612  
d          3 3.2254  1.0751  2.8354 0.20741  
Residuals  3 1.1375  0.3792                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

> anova(aov(y ~ a*b + d, data=tmp))
Analysis of Variance Table

Response: y
          Df Sum Sq Mean Sq F value  Pr(>F)  
a          1 4.3786  4.3786 11.5479 0.04252 *
b          2 0.0688  0.0344  0.0907 0.91567  
d          3 3.0020  1.0007  2.6391 0.22327  
a:b        2 2.3458  1.1729  3.0933 0.18661  
Residuals  3 1.1375  0.3792                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
> 


If you need to resend this, please put some spacing in the SYSTAT output
to make it legible.

Rich



More information about the R-help mailing list