[R] Indexing ANOVA table
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Nov 29 12:57:37 CET 2003
On Sat, 29 Nov 2003 Pascal.Niklaus at unibas.ch wrote:
> Hi all,
>
> I'd like to extract a value from an ANOVA table, but experience the following
> problem:
>
> ### This works:
>
> > s.pseudo <- summary(aov(m ~ block + mix*graz,data=split1))
> > s.pseudo
> Df Sum Sq Mean Sq F value Pr(>F)
> block 2 1114.66 557.33 4.4296 0.04192 *
> mix 1 6.14 6.14 0.0488 0.82956
> graz 2 1.45 0.72 0.0057 0.99427
> mix:graz 2 3.82 1.91 0.0152 0.98495
> Residuals 10 1258.19 125.82
> ---
> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> > s.pseudo[[1]]["mix ","Pr(>F)"]
> [1] 0.8295556
>
> ### But this doesn't -- why?
Why should it?
> > s.split <- summary(aov(m ~ block + mix*graz + Error(Plot),data=split1))
> > s.split
>
> Error: Plot
> Df Sum Sq Mean Sq F value Pr(>F)
> block 2 1114.66 557.33 0.8994 0.5265
> mix 1 6.14 6.14 0.0099 0.9298
> Residuals 2 1239.37 619.68
>
> Error: Within
> Df Sum Sq Mean Sq F value Pr(>F)
> graz 2 1.4464 0.7232 0.3073 0.7437
> mix:graz 2 3.8206 1.9103 0.8117 0.4776
> Residuals 8 18.8278 2.3535
> > s.split[["Error: Plot"]] ## extracting first list element works
> Df Sum Sq Mean Sq F value Pr(>F)
> block 2 1114.66 557.33 0.8994 0.5265
> mix 1 6.14 6.14 0.0099 0.9298
> Residuals 2 1239.37 619.68
> > s.split[["Error: Plot"]]["mix ","Pr(>F)"] ### <== FAILS
> Error in s.split[["Error: Plot"]]["mix ", "Pr(>F)"] :
> incorrect number of dimensions
You should have written
s.split[["Error: Plot"]][[1]]["mix ","Pr(>F)"]
> So where is the difference between the two?
One is an "aov" object, the other an "aovlist" object. Take a closer look
at print.summary.aov, for example.
More generally, learn how to look at R objects instead of assuming you
know what you are doing: unclass(s.split[["Error: Plot"]]) would have been
informative.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list