Bertolt Meyer
2011-Feb-03 12:30 UTC
[R] how to read the "Sum Sq" - column from summary.aov()
Dear R-Users, I have a trivial problem, but extensive googling and ??'ing did not solve it: I want to obtain the sums of squares from a summary.aov() object for later use. Example:> DV <- rnorm(100) > IV1 <- as.factor(rep(c("male", "female"), times = 50)) > IV2 <- as.factor(rep(c("young", "old"), times = 50)) > > summary(aov(DV ~ IV1 * IV2))Df Sum Sq Mean Sq F value Pr(>F) IV1 1 0.215 0.21499 0.2277 0.6343 Residuals 98 92.523 0.94411 How can I store the sums of squares in a variable for later use? Like this:>some.magic.command()[1] 0.215 92.523 Thank you, Bertolt -- Dr. Bertolt Meyer Senior research and teaching associate Social Psychology, Institute of Psychology, University of Zurich Binzmuehlestrasse 14, Box 15 CH-8050 Zurich Switzerland bmeyer at sozpsy.uzh.ch
Peter Ehlers
2011-Feb-03 12:49 UTC
[R] how to read the "Sum Sq" - column from summary.aov()
On 2011-02-03 04:30, Bertolt Meyer wrote:> Dear R-Users, > > I have a trivial problem, but extensive googling and ??'ing did not solve it: I want to obtain the sums of squares from a summary.aov() object for later use. Example: > >> DV<- rnorm(100) >> IV1<- as.factor(rep(c("male", "female"), times = 50)) >> IV2<- as.factor(rep(c("young", "old"), times = 50)) >> >> summary(aov(DV ~ IV1 * IV2)) > > Df Sum Sq Mean Sq F value Pr(>F) > IV1 1 0.215 0.21499 0.2277 0.6343 > Residuals 98 92.523 0.94411 > > How can I store the sums of squares in a variable for later use? Like this: > >> some.magic.command() > [1] 0.215 92.523str() is your friend. str( summary(aov(DV ~ IV1 * IV2)) ) shows that the summary is a list containing a data.frame. Use summary(aov(DV ~ IV1 * IV2))[[1]] to extract the data.frame and any one of summary(aov(DV ~ IV1 * IV2))[[1]][, 2] summary(aov(DV ~ IV1 * IV2))[[1]][, 'Sum Sq'] summary(aov(DV ~ IV1 * IV2))[[1]]$'Sum Sq' to extract the sum-of-squares vector. Peter Ehlers> > Thank you, > Bertolt >
Ivan Calandra
2011-Feb-03 12:50 UTC
[R] how to read the "Sum Sq" - column from summary.aov()
Hi, If you do test <- summary(aov(DV ~ IV1 * IV2)) str(test) you will see that test[[1]][2] gives you what you want. Reading more on indexing will also probably help you. str() is a very useful function, to use without moderation! HTH, Ivan Le 2/3/2011 13:30, Bertolt Meyer a ?crit :> summary(aov(DV ~ IV1 * IV2))-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php