Luis Borda de Agua
2010-Jul-13 14:35 UTC
[R] how to extract information from anova results
Hi, I have used the instruction aov in the following manner: res <- aov(qwe ~ asd) when I typed "res" I get: _________ Call: aov(formula = qwe ~ asd) Terms: asd Residuals Sum of Squares 0.0708704 0.5255957 Deg. of Freedom 1 8 Residual standard error: 0.2563191 Estimated effects may be unbalanced _________ I need to access the value of the Sum of Squares (i.e. I want another variable to be equal to it, e.g myvar <- Sum.of.Squares) . I tried names(res) to see which values are accessible, but I couldn't find the Sum of Squares. I had a similar problem when I tried to access the p.value which can be readily SEEN using summary(res). In general, is there an easy way to access the values generated by an R function? Thank you, LBA
On Jul 13, 2010, at 10:35 AM, Luis Borda de Agua wrote:> Hi, > > I have used the instruction aov in the following manner: > > res <- aov(qwe ~ asd) > > when I typed "res" I get: > _________ > Call: > aov(formula = qwe ~ asd) > > Terms: > asd Residuals > Sum of Squares 0.0708704 0.5255957 > Deg. of Freedom 1 8 > > Residual standard error: 0.2563191 > Estimated effects may be unbalanced > _________ > > I need to access the value of the Sum of Squares (i.e. I want > another variable to be equal to it, e.g myvar <- Sum.of.Squares) . > I tried names(res) to see which values are accessible, but I > couldn't find the Sum of Squares. I had a similar problem when I > tried to access the p.value which can be readily SEEN using > summary(res). > > In general, is there an easy way to access the values generated by > an R function?When you typed "res", the interpreter determined that it was of type "aov" and dispatched it to the print method for objects of that class. The list of print methods is accessed with: methods(print) and it's a long list. print.aov is asterisked so you either need to look at the function with: getAnywhere(print.aov) ....or perhaps more directly assign summary(res) to an object and access its SS values. -- David.> > > Thank you, > > LBA > > ______________________________________________ > 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
I think the easiest way is from calling anova() on your aov class object. For instance y <- 1:10 x <- runif(10) my.aov <- aov(y ~ x) anova(my.aov)["Residuals", "Sum Sq"] anova(my.aov)["x", "Pr(>F)"] You can also extract these values from a call to summary(my.aov), but that output is a list (even for an ANOVA with a single error stratum), so you'd have to add [[1]] selecting the first (or if there were more than one whichever you wanted) element of the list. summary(my.aov)[[1]]["Residuals", "Sum Sq"] Cheers, Josh On Tue, Jul 13, 2010 at 7:35 AM, Luis Borda de Agua <lbagua at gmail.com> wrote:> Hi, > > I have used the instruction aov in the following manner: > > res <- aov(qwe ~ asd) > > when I typed "res" I get: > _________ > Call: > ? aov(formula = qwe ~ asd) > > Terms: > ? ? ? ? ? ? ? ? ? ? ?asd Residuals > Sum of Squares ?0.0708704 0.5255957 > Deg. of Freedom ? ? ? ? 1 ? ? ? ? 8 > > Residual standard error: 0.2563191 > Estimated effects may be unbalanced > _________ > > I need to access the value of the Sum of Squares (i.e. I want another variable to be equal to it, e.g myvar <- Sum.of.Squares) . > I tried names(res) to see which values are accessible, but I couldn't find the Sum of Squares. I had a similar problem when I tried to access the p.value which can be readily SEEN using summary(res). > > In general, is there an easy way to access the values generated by an R function? > > Thank you, > > LBA > > ______________________________________________ > 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/