[R] How to obtain the coefficients from a summary of aov ?
David Winsemius
dwinsemius at comcast.net
Wed Apr 21 18:51:30 CEST 2010
On Apr 21, 2010, at 12:36 PM, David Winsemius wrote:
>
> On Apr 21, 2010, at 12:09 PM, Andrea Bernasconi DG wrote:
>
>> Thank you David,
>>
>> but how to get the value of 0.015939 present in s.npk.aov, and not
>> given by s.npk.aov$coef["block","Pr(>F)"] ?
>
> ??? That's not a coefficient. It's a p-value.
> str(s.npk.aov)
List of 1
$ :Classes ‘anova’ and 'data.frame': 8 obs. of 5 variables:
..$ Df : num [1:8] 5 1 1 1 1 1 1 12
..$ Sum Sq : num [1:8] 343.3 189.3 8.4 95.2 21.3 ...
..$ Mean Sq: num [1:8] 68.7 189.3 8.4 95.2 21.3 ...
..$ F value: num [1:8] 4.447 12.259 0.544 6.166 1.378 ...
..$ Pr(>F) : num [1:8] 0.01594 0.00437 0.4749 0.0288 0.26317 ...
- attr(*, "class")= chr [1:2] "summary.aov" "listof"
So the p-values are the inside the first element
> s.npk.aov[[1]][1,5]
[1] 0.01593879
Or.... experimenting a bit ..
> s.npk.aov[[1]]['Pr(>F)']
Pr(>F)
block 0.01594 *
N 0.00437 **
P 0.47490
K 0.02880 *
N:P 0.26317
N:K 0.16865
P:K 0.86275
Residuals
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> s.npk.aov[[1]]['Pr(>F)'][[1]]
[1] 0.015938790 0.004371812 0.474904093 0.028795054 0.263165283
0.168647879 0.862752086
[8] NA
> s.npk.aov[[1]]['Pr(>F)'][[1]][1]
[1] 0.01593879
>>
>> On the other, the procedure to extract coefficients from a summary
>> of lm or aov should be the same.
>
> I think one generally extracts the coefficients from the model,
> rather than from summary(model):
>
> > coef(npk.aov)
> (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
> 0.4166667 -1.9166667 -3.7666667 -4.7000000 0.5666667
>
> > coef(npk.lm)
> (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
>
>
>
>>
>> Andrea
>>
>> On 21 Apr, 2010, at 3:20 PM, David Winsemius wrote:
>>
>>>
>>> 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
>>>
>>
>> mobile: +41 79 621 74 07
>>
>>
>>
>>
>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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