[R] How to obtain the coefficients from a summary of aov ?

David Winsemius dwinsemius at comcast.net
Wed Apr 21 15:20:20 CEST 2010


On Apr 21, 2010, at 8:37 AM, Andrea Bernasconi DG wrote:

> Dear Madame, Dear Sir,
>
> I am able to obtain the coefficients from a 'summary' of 'lm', but  
> NOT from a 'summary' of 'aov'.
> The following example shows my steps.
>
> ## Initialize
> rm(list = ls()) # remove (almost) everything in the working  
> environment

@#$%^&*() DON'T DO THAT.... luckily I left off the "l" when I copied  
and pasted but otherwise this would have trashed my workspace.

> utils::data(npk, package="MASS") # get data
> model <- yield ~ block + N*P*K
>
> ## Using lm
> npk.lm <- lm(model, npk)
> ( s.npk.lm <- summary(npk.lm) )
>
> ...
>            Estimate Std. Error t value Pr(>|t|)
> (Intercept)  54.8750     0.8021  68.415  < 2e-16 ***
> block1        1.7125     1.3893   1.233  0.24131
> block2        1.6792     0.8021   2.093  0.05822 .
> block3       -1.8229     0.5672  -3.214  0.00744 **
> ...
>
> s.npk.lm$coef["block1","Pr(>|t|)"] # this works
> [1] 0.2413061
>
> ## Using aov
> npk.aov <- aov(model, npk)

str(npk.aov)

 > npk.aov$coefficients
(Intercept)      block2      block3      block4      block5       
block6          N1
  51.8250000   3.4250000   6.7500000  -3.9000000  -3.5000000    
2.3250000   9.8500000
          P1          K1       N1:P1       N1:K1       P1:K1    N1:P1:K1
   0.4166667  -1.9166667  -3.7666667  -4.7000000   0.5666667          NA

Or reading the help pages one might have tried, although I will admit  
that the differences in parametrization confounded my efforts at  
describing a linear combination of those results to create the simpler  
result offered above:

?model.tables
 > model.tables(npk.aov, "effects")
Tables of effects

  block
block
      1      2      3      4      5      6
-0.850  2.575  5.900 -4.750 -4.350  1.475

  N
N
       0       1
-2.8083  2.8083

  P
P
       0       1
  0.5917 -0.5917

  K
K
       0       1
  1.9917 -1.9917

  N:P
    P
N   0       1
   0 -0.9417  0.9417
   1  0.9417 -0.9417

  N:K
    K
N   0      1
   0 -1.175  1.175
   1  1.175 -1.175

  P:K
    K
P   0        1
   0  0.14167 -0.14167
   1 -0.14167  0.14167

 >
> ( s.npk.aov <- 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
> ...
>
> s.npk.aov$coef["block","Pr(>F)"] # this does NOT works
>
> ...
> NULL
> ...
>
> How to obtain the coefficients from a 'summary'  of 'aov' ?
>
> In advance, I thank you very much for your eventual answer.
>
> Sincerely, Andrea Bernasconi
>
> mobile: +41 79 621 74 07
> URL: http://web.me.com/andrea.bernasconi.dg/Andrea_Bernasconi_DG_home_page/HOME.html
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list