Hi, dear R-users, I am computing a liner regression by rating category using the 'by' function as stated below: tmp <- by(projet, rating, function(x) lm(defaults ~ CGDP+CSAVE+SP500, data x)) I would like to get not only the coefficients but also their p-values. I can't find the command in the help pages to get them. Does anyone have a suggestion ? Thank you, Benoit. [[alternative HTML version deleted]]
On 7/12/07, Benoit Chemineau <benoitchemineau at gmail.com> wrote:> Hi, dear R-users, > > I am computing a liner regression by rating category using the 'by' function > as stated below: > > tmp <- by(projet, rating, function(x) lm(defaults ~ CGDP+CSAVE+SP500, data > x)) > > I would like to get not only the coefficients but also their p-values. I > can't find the command in the help pages to get them. > > Does anyone have a suggestion ?Hi Benoit, A general approach to find p-values: m <- lm(wt ~ mpg, data=mtcars) First figure out how to display them on screen: m # nope coef(m) # nope summary(m) # got it # Then use str to look at the components str(summary(m)) # And pick out the one want summary(m)$coef coef(summary(m)) # slighty better style, but won't work in general # In general, you may also need to try str(print(summary(m))) # as sometimes the print method calculates the data you're looking for Hadley
Dimitris Rizopoulos
2007-Jul-12 09:17 UTC
[R] how to get the p-values from an lm function ?
try the following: tmp <- by(projet, rating, function (x) Thursday, 12.July.2007{ fit <- lm(defaults ~ CGDP + CSAVE + SP500, data = x) summary(fit)$coefficients }) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Benoit Chemineau" <benoitchemineau at gmail.com> To: <r-help at stat.math.ethz.ch> Sent: Thursday, July 12, 2007 10:51 AM Subject: [R] how to get the p-values from an lm function ?> Hi, dear R-users, > > I am computing a liner regression by rating category using the 'by' > function > as stated below: > > tmp <- by(projet, rating, function(x) lm(defaults ~ > CGDP+CSAVE+SP500, data > x)) > > I would like to get not only the coefficients but also their > p-values. I > can't find the command in the help pages to get them. > > Does anyone have a suggestion ? > > Thank you, > > Benoit. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm