Question: How to programmatically retrieve the p-value of the slope of a linear regression using either R or perl
0
3.9 years ago by
moxu470
moxu470 wrote:

In R, you can do "summary(glm(y ~ x))" and it displays the results of the glm including the intercept, slope and the p-values for the intercept and the slope. But how can you programmatically retrieve the p-value for the slope? For instance, I would like to do something like the following:

``````rst <- glm(y ~ x)
rst\$pvalue
``````

Or, alternatively, a perl package with the desired capability. I've checked out Statistics::LineFit, however it can only return rSquared but not p-value

R • 1.9k views
modified 3.9 years ago by rjgrimaila20 • written 3.9 years ago by moxu470
3
3.9 years ago by
karl.stamm3.9k
United States
karl.stamm3.9k wrote:

Save the output of the summary() and the coefficients slot contains the p value in the third column of that matrix.

I would do p<-summary(glm(...))\$coefficients[2,3]

1

``````coefficients(summary(glm(…)))[…]
``````

`p<-summary(glm(...))\$coefficients[2,4]`?

Didn't realize summary(..)\$coefficients returns a matrix.

Thanks a lot!

2
3.9 years ago by
rjgrimaila20
rjgrimaila20 wrote:
``````rst <- glm(y ~ x)
rst\$pvalue
library(broom)
t.rst <- tidy(rst)
t.rst[,"p.value"]
``````
1
3.9 years ago by
moxu470
moxu470 wrote:

Another method is to use perl Statistics::LineFit to get the tStatistics, and use Statistics::Distributions::tprob(dof, t-stat) to get the p-value.