"David J. Netherway" <david.netherway at adelaide.edu.au> writes:> Hello, > > I am trying to get the P values from the output of a summary for lm. > > lm <- lm(y ~ age + sex) > s <- summary(lm) > > I thought that I might be able to get them using a combination of > scan, grep and sub. > But I got stuck on the first step - being able to process "s" as a > text string. > I could perhaps write it to file than scan it back but there is > probably an easier > way to do the whole thing. > > Help would be welcome, DavidSummaries are (usually) R objects which can be manipulated programmatically. They should be confused with what their print methods print. Consider example(summary.lm) coef(sld90)[,4,drop=F] -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Hello, I am trying to get the P values from the output of a summary for lm. lm <- lm(y ~ age + sex) s <- summary(lm) I thought that I might be able to get them using a combination of scan, grep and sub. But I got stuck on the first step - being able to process "s" as a text string. I could perhaps write it to file than scan it back but there is probably an easier way to do the whole thing. Help would be welcome, David
coef(summary(lmfit))[, 4] See ?summary.lm, and note that summary() methods in general produce an object which the print method then prints. On Wed, 9 Jun 2004, David J. Netherway wrote:> Hello, > > I am trying to get the P values from the output of a summary for lm. > > lm <- lm(y ~ age + sex)Not a good choice of object name!> s <- summary(lm) > > I thought that I might be able to get them using a combination of scan, > grep and sub. > But I got stuck on the first step - being able to process "s" as a text > string. > I could perhaps write it to file than scan it back but there is probably > an easier > way to do the whole thing.You could sink to a textConnection if you really wanted the printed output. -- 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
> Hello, > > I am trying to get the P values from the output of a summary for lm. > > lm <- lm(y ~ age + sex) > s <- summary(lm)s$coefficients gives you a matrix with the P-values in the fourth column Torsten> > I thought that I might be able to get them using a combination of scan, > grep and sub. > But I got stuck on the first step - being able to process "s" as a text > string. > I could perhaps write it to file than scan it back but there is probably > an easier > way to do the whole thing. > > Help would be welcome, David > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
Hi David, To see what is stored in an object, use names(). In your case you could try this:> lm <- lm(y ~ age + sex) > s <- summary(lm) > names(s)[1] "call" "terms" "residuals" "coefficients" [5] "aliased" "sigma" "df" "r.squared" [9] "adj.r.squared" "fstatistic" "cov.unscaled"> s$coefficients > s$coefficients[,4]cheers, JR En respuesta a / Antwort zu / Reply to: ~~Hello, ~~ ~~I am trying to get the P values from the output of a summary for lm. ~~ ~~lm <- lm(y ~ age + sex) ~~s <- summary(lm) ~~ ~~I thought that I might be able to get them using a combination of scan, ~~grep and sub. ~~But I got stuck on the first step - being able to process "s" as a text ~~string. ~~I could perhaps write it to file than scan it back but there is probably ~~an easier ~~way to do the whole thing. ~~ ~~Help would be welcome, David ~~ ~~______________________________________________ ~~R-help at stat.math.ethz.ch mailing list ~~https://www.stat.math.ethz.ch/mailman/listinfo/r-help ~~PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ~~ Dipl.-Biol. J.R. Ferrer Paris ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Laboratorio de Biolog??a de Organismos - Centro de Ecolog??a Instituto Venezolano de Investigaciones Cient??ficas Apartado 21827 - Caracas 1020A REPUBLICA BOLIVARIANA DE VENEZUELA Tel:00-58-212-5041452 --- Fax: 00-58-212-5041088 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jferrer at ivic.ve