# [R] getting the p-value from lm as a list object

David Winsemius dwinsemius at comcast.net
Sat Nov 1 04:28:01 CET 2008

```In your example, you could have noted that summary had an element
named coefficients which was a 2 x 4 object, with names "(Intercept)"
and "x". Although you could have asked for the values with
coefficients[2,4], the use of names makes the intent more clear.

snipped from the str(summary(fm)) output:
\$ coefficients : num [1:2, 1:4] 1.067 0.588 1.520 0.245 0.702 ...
..- attr(*, "dimnames")=List of 2
.. ..\$ : chr [1:2] "(Intercept)" "x"
.. ..\$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"

So ...

> summary(fm)\$coefficients
Estimate Std. Error   t value   Pr(>|t|)
(Intercept) 1.0666667  1.5196358 0.7019226 0.50263396
x           0.5878788  0.2449115 2.4003725 0.04315164

> summary(fm)\$coefficients["x","Pr(>|t|)"]
[1] 0.04315164

--
David Winsemius, MD
Heritage Labs

On Oct 31, 2008, at 11:59 AM, eric lee wrote:

> Hi,
>
> I'm trying to get the p-value from the 'lm' regression function as a
> list
> object.  For example, I can get r^2 from the following code by
> entering
> summary(fm)\$r.squared.  Is there a way to get the p-value?  If not,
> is there
> a function where I can enter the f-value and degrees of freedom to
> get the
> p-value?  Thanks.
>
> x <- c(1,2,3,4,5,6,7,8,9,10)
> y <- c(1,2,3,4,4,5,6,8,1,9)
>
> fm <- lm(y ~ x)
> str(summary(fm))
>
> 	[[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.

```