Dear all, I would like to ask how to extract the p-value for the whole model from summary(lm). This didn't help a lot summary.lm summary(lm(speed~dist, cars)) Thanks a lot! [[alternative HTML version deleted]]
You should be able to access the p-value using the $coefficients variable, which is part of summary. Try: results <- summary(lm(speed~dist, cars)) results$coefficients and then: results$coefficients[x] where x is the location of particular p-value, or coefficient supplied, you want, from the results$coefficient vector. Hope this helps, ~Michael ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Trafim Vanishek [rdapamoga at gmail.com] Sent: Friday, February 05, 2010 11:54 AM To: r-help at r-project.org Subject: [R] Extract p-value from lm for the whole model Dear all, I would like to ask how to extract the p-value for the whole model from summary(lm). This didn't help a lot summary.lm summary(lm(speed~dist, cars)) Thanks a lot! [[alternative HTML version deleted]] ______________________________________________ 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.
On Feb 5, 2010, at 11:54 AM, Trafim Vanishek wrote:> Dear all, > > I would like to ask how to extract the p-value for the whole model > from > summary(lm). > This didn't help a lot summary.lmI disagree. The help page tells you that "coefficients" has the p- values sogo ahead and get them: > summary.lm(lm(speed~dist, cars))$coefficients Estimate Std. Error t value Pr(>|t|) (Intercept) 8.2839056 0.87438449 9.473985 1.440974e-12 dist 0.1655676 0.01749448 9.463990 1.489836e-12 That is a table or matrix (it doesn't really matter for our purposes) and can be address by either numbers or names. Here is how to do it with names. > summary.lm(lm(speed~dist, cars))$coefficients["dist","Pr(>|t|)"] [1] 1.489836e-12> > summary(lm(speed~dist, cars))-- David Winsemius, MD Heritage Laboratories West Hartford, CT
> I would like to ask how to extract the p-value for the whole model > from > summary(lm).If you mean the p-value given at the end of the summary() printout, it isn;t held in the summary object. But information to get it is. Using the ?lm example: ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2,10,20, labels=c("Ctl","Trt")) weight <- c(ctl, trt) lm.D9 <- lm(weight ~ group) fstat<-summary(lm.D9)$fstatistic pf(fstat[1], fstat[2], fstat[3], lower.tail=FALSE) That's a p-value for a test of weight~1 versus weight~group, so you could also get it from lm.D0<-lm(weight~1) anova(lm.D0, lm.D9) and doubtless lots of other ways. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}