Question: How to programmatically retrieve the p-value of the slope of a linear regression using either R or perl
0
gravatar for moxu
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
ADD COMMENTlink modified 3.9 years ago by rjgrimaila20 • written 3.9 years ago by moxu470
3
gravatar for karl.stamm
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]

ADD COMMENTlink written 3.9 years ago by karl.stamm3.9k
1

Alternatively (for readability)

coefficients(summary(glm(…)))[…]
ADD REPLYlink modified 3.9 years ago • written 3.9 years ago by Charles Plessy2.7k

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

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

Thanks a lot!

ADD REPLYlink modified 3.9 years ago by WouterDeCoster45k • written 3.9 years ago by moxu470
2
gravatar for rjgrimaila
3.9 years ago by
rjgrimaila20
rjgrimaila20 wrote:
rst <- glm(y ~ x)  
rst$pvalue  
library(broom)  
t.rst <- tidy(rst)  
t.rst[,"p.value"]
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by rjgrimaila20
1
gravatar for moxu
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.

ADD COMMENTlink written 3.9 years ago by moxu470
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2579 users visited in the last hour
_