Redeem results in r

Asked

Viewed 49 times

1

It is possible to rescue only p-value from a simple linear regression in R?

I have the following code:

reg<-lm(abscissa~ordenada)

summary(reg)

the answer is:

Call:
lm(formula = abscissa ~ ordenada)

Residuals:
    Min      1Q  Median      3Q     Max 
-746.77 -308.91  -62.22  285.36 1236.04 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 2163.1769   161.4879  13.395  < 2e-16 ***

ordenada       1.7729     0.2735   6.482 8.95e-09 ***

Signif. codes:  0 *** 0.001 ** 0.01 * 0.05 . 0.1 '' 1

Residual standard error: 452.9 on 74 degrees of freedom
Multiple R-squared:  0.3621,    Adjusted R-squared:  0.3535 
F-statistic: 42.01 on 1 and 74 DF,  p-value: 8.951e-09

i need to call only p-value (8.951e-09)

I tried to use the $ operated but unsuccessfully.

Grateful

  • Is the p-value of statistics F or statistics T?

2 answers

3

The p-value does not exist in the summary object. What the summary object offers are the conditions of calculating the p-value, with the statistic F and the two degrees of freedom.

reg <- lm(mpg ~ wt, mtcars)
sumario <- summary(reg)
estatisticas <- sumario$fstatistic
estatisticas
#    value    numdf    dendf 
# 91.37533  1.00000 30.00000 

With this information in hand we can calculate the p-value used the package stats, which already starts loaded in a standard session of R.

pvalor <- stats::pf(estatisticas[1], estatisticas[2], estatisticas[3], lower.tail = FALSE)
#        value 
# 1.293959e-10

If you want the p-value to be nicely formatted, as when the summary print occurs, you can

format.pval(pvalor, 3)
# [1] "1.29e-10"
  • Perfect Tomás, thanks for the contribution. In fact the other methodology results in error for models with multiple variables.

2


Despite the calculations of answer by Tomás Barcellos are right, the object sumario already has the p-values:

reg <- lm(mpg ~ wt, mtcars)
sumario <- summary(reg)

sumario$coefficients[, 4]
# (Intercept)           wt 
#8.241799e-19 1.293959e-10

To have only the second p-value, run the above command but this time with the line index.

sumario$coefficients[2, 4]
#[1] 1.293959e-10

See what sumario$coefficients has. To see the object sumario complete the best option is to run str(sumario) and then spend some time reading the output of this command. (I never remember exactly where the p-values are.)

  • Good. The way I did it is like the print.summary.lm() ago.

  • See what happens when there is more than one explanatory variable, for example, reg <- lm(mpg ~ wt + disp, mtcars). Your method is different from the result of print. Nor 0.06 nor 0.007 are equal to the p-value which is in the ninth decimal place.

  • The result you give me with options(digits = 15) is c('(Intercept)' = 4.91074607571808e-16, wt = 0.00743072516192677, &#xA;disp = 0.0636198070339208). And with the default value is 4.910746e-16 7.430725e-03 6.361981e-02 but the dput gives the same thing as.

  • We are talking about different p-value. It has a p-value that is unique for each model and another for each model variable. My answer gives the first, yours gives the second. In the case of simple regressions these values are equal. The p-value I’m talking about is the last printed thing in the summary

  • 1

    @Tomásbarcellos Right, I had not realized. I believe then that the question is ambiguous, I should ask clearly what you want. I interpreted it as the p-values of statistics t and that is what my answer gives.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.