RexBryan
2002-Dec-09 19:48 UTC
[R] Problem with differences between S+ and R in parsing output tables with $
R-wizards I have successfully run with S+ a statistical power calculation for non-normal distributions as presented in M. Crawley?s new book.? When I tried the newest version of R on the same code, the $ parse statement doesn't seem to retrieve the appropriate number from a table. Note that some of the cosmetic differences in the two tables have to be dealt with by the parser. Any ideas what's happening? REX # Begin R ------------------------------------------------------------- #> summary(aov(model))Df Sum Sq Mean Sq F value Pr(>F) fa 1 11.1 11.1 0.9327 0.3345 Residuals 698 8279.3 11.9 # R: ... trying to parse the table gives a NULL for the probability of F...> (summary(aov(model))$"Pr(>F)")[1]NULL # End R --------------------------------------------------------------- # Begin S+ ------------------------------------------------------------> summary(aov(model))Df Sum of Sq Mean Sq F Value Pr(F) fa 1 11.063 11.06286 0.9326708 0.3345044 Residuals 698 8279.314 11.86148 # S+ ... using $ to parse the table gives the right answer for the probability of F... (summary(aov(model))$"Pr(F)")[1] [1] 0.3345044 # End S+ --------------------------------------------------------------
Douglas Bates
2002-Dec-09 20:25 UTC
[R] Problem with differences between S+ and R in parsing output tables with $
"RexBryan" <rexbryan1 at attbi.com> writes:> R-wizards > > I have successfully run with S+ a statistical power calculation for > non-normal distributions as presented in M. Crawley's new book.? When I > tried the newest version of R on the same code, the $ parse statement > doesn't seem to retrieve the appropriate number from a table. Note that > some of the cosmetic differences in the two tables have to be dealt with > by the parser. Any ideas what's happening? > REX > > # Begin R ------------------------------------------------------------- > # > > summary(aov(model)) > > Df Sum Sq Mean Sq F value Pr(>F) > fa 1 11.1 11.1 0.9327 0.3345 > Residuals 698 8279.3 11.9 > > # R: ... trying to parse the table gives a NULL for the probability of > F... > > > (summary(aov(model))$"Pr(>F)")[1] > NULL > > # End R ---------------------------------------------------------------Hmm - that's a peculiar way of trying to extract the information but if you really want to do it like that you should first use str() to determine the structure of the returned value. It turns out that the value is a list and the first component of the list is a data frame with one column labelled "Pr(>F)".> str(summary(aov(model)))List of 1 $ :Classes anova and `data.frame': 3 obs. of 5 variables: ..$ Df : num [1:3] 3 5 15 ..$ Sum Sq : num [1:3] 13445 1428 781 ..$ Mean Sq: num [1:3] 4482 286 52 ..$ F value: num [1:3] 86.11 5.49 NA ..$ Pr(>F) : num [1:3] 1.11e-09 4.55e-03 NA - attr(*, "class")= chr [1:2] "summary.aov" "listof" This means you would need to put [[1]] before the $> summary(aov(model))[[1]]$"Pr(>F)"[1] 1.110419e-09 4.550074e-03 NA
Ben Bolker
2002-Dec-09 20:38 UTC
[R] Problem with differences between S+ and R in parsing output tables with $
In R, it looks like the "summary.aov" type actually contains the data frame you're trying to extract as the first (and only) element of a list, so summary(aov(model))[[1]] is more or less equivalent to the summary(aov(model)) object in S-PLUS, and summary(aov(model))[[1]]$"Pr(>F)"[1] gets the specific number you're looking for. str() and class() are the tools for disentangling this kind of problem. It is a shame that it's so hard to extract the value in this case, but the authors have to be able to structure things internally however they find convenient, and unless they provide accessor methods for everything anyone could conceivably want, people are going to have to dig at some point ... On Mon, 9 Dec 2002, RexBryan wrote:> R-wizards > > I have successfully run with S+ a statistical power calculation for > non-normal distributions as presented in M. Crawley?s new book.? When I > tried the newest version of R on the same code, the $ parse statement > doesn't seem to retrieve the appropriate number from a table. Note that > some of the cosmetic differences in the two tables have to be dealt with > by the parser. Any ideas what's happening? > REX > > # Begin R ------------------------------------------------------------- > # > > summary(aov(model)) > > Df Sum Sq Mean Sq F value Pr(>F) > fa 1 11.1 11.1 0.9327 0.3345 > Residuals 698 8279.3 11.9 > > # R: ... trying to parse the table gives a NULL for the probability of > F... > > > (summary(aov(model))$"Pr(>F)")[1] > NULL > > # End R --------------------------------------------------------------- > > # Begin S+ ------------------------------------------------------------ > > > summary(aov(model)) > > Df Sum of Sq Mean Sq F Value > Pr(F) > fa 1 11.063 11.06286 0.9326708 > 0.3345044 > Residuals 698 8279.314 11.86148 > > # S+ ... using $ to parse the table gives the right answer for the > probability of F... > > (summary(aov(model))$"Pr(F)")[1] > [1] 0.3345044 > > # End S+ -------------------------------------------------------------- > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704