[R-sig-eco] aov vs. glm

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri Nov 11 10:42:24 CET 2011


On Thu, 2011-11-10 at 18:22 -0500, Lara R. Appleby 04 wrote:
> I'm trying to basically do a two way ANOVA on the dependent variable (clutchsize)  
> with the two independent variables (treatment and species). It seems that there  
> are three ways I can say this in R:
> 
> 1. glm(clutchsize~treatment*species)
> 2. aov(clutchsize~treatment*species)
> 3. anova(lm(clutchsize~treatment*species)
> 
> Methods 2 and 3 yield equivalent results, but Method 1 is completely different!  

I don't believe you; care to provide supporting evidence?

Here is a counter example that shows that these are

## From Venables and Ripley (2002) p.165.
data(npk, package="MASS")
     
## Set orthogonal contrasts.
op <- options(contrasts=c("contr.helmert", "contr.poly"))

npk.glm <- glm(yield ~ block + N*P*K, data = npk)
npk.aov <- aov(yield ~ block + N*P*K, data = npk)
npk.lm  <- lm(yield ~ block + N*P*K, data = npk)
anova(npk.glm, test = "F")
anova(npk.lm)
summary(npk.aov)
options(op)

All three give the same results:

> anova(npk.glm, test = "F")
Analysis of Deviance Table

Model: gaussian, link: identity

Response: yield

Terms added sequentially (first to last)


      Df Deviance Resid. Df Resid. Dev       F   Pr(>F)   
NULL                     23     876.37                    
block  5   343.30        18     533.07  4.4467 0.015939 * 
N      1   189.28        17     343.79 12.2587 0.004372 **
P      1     8.40        16     335.39  0.5441 0.474904   
K      1    95.20        15     240.19  6.1657 0.028795 * 
N:P    1    21.28        14     218.90  1.3783 0.263165   
N:K    1    33.14        13     185.77  2.1460 0.168648   
P:K    1     0.48        12     185.29  0.0312 0.862752   
N:P:K  0     0.00        12     185.29                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> anova(npk.lm)
Analysis of Variance Table

Response: yield
          Df Sum Sq Mean Sq F value   Pr(>F)   
block      5 343.29  68.659  4.4467 0.015939 * 
N          1 189.28 189.282 12.2587 0.004372 **
P          1   8.40   8.402  0.5441 0.474904   
K          1  95.20  95.202  6.1657 0.028795 * 
N:P        1  21.28  21.282  1.3783 0.263165   
N:K        1  33.14  33.135  2.1460 0.168648   
P:K        1   0.48   0.482  0.0312 0.862752   
Residuals 12 185.29  15.441                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> summary(npk.aov)
            Df Sum Sq Mean Sq F value   Pr(>F)   
block        5 343.29  68.659  4.4467 0.015939 * 
N            1 189.28 189.282 12.2587 0.004372 **
P            1   8.40   8.402  0.5441 0.474904   
K            1  95.20  95.202  6.1657 0.028795 * 
N:P          1  21.28  21.282  1.3783 0.263165   
N:K          1  33.14  33.135  2.1460 0.168648   
P:K          1   0.48   0.482  0.0312 0.862752   
Residuals   12 185.29  15.441                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

HTH

G

> 
> Any idea why?
> 
> Lara Appleby
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list