Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting t-stat p values from lm in R

Tags:

r

regression

I have run a regression model in R using the lm function. The resulting ANOVA table gives me the F-value for each coefficient (which doesnt really make sense to me). What I would like to know is the t-stat for each coefficient and its corresponding p-value. How do I get this? Is it stored by the function or does it require additional computation?

Here is the code and output:

library(lubridate)
library(RCurl)
library(plyr)

[in] fit <- lm(btc_close ~ vix_close + gold_close + eth_close, data = all_dat)

# Other useful functions 
coefficients(fit) # model coefficients
confint(fit, level=0.95) # CIs for model parameters 
anova(fit) # anova table 

[out]
Analysis of Variance Table

Response: btc_close
           Df   Sum Sq  Mean Sq  F value Pr(>F)    
vix_close   1 20911897 20911897 280.1788 <2e-16 ***
gold_close  1    91902    91902   1.2313 0.2698    
eth_close   1 42716393 42716393 572.3168 <2e-16 ***
Residuals  99  7389130    74638                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

If my statistics knowledge serves me correctly, these f-values are meaningless. Theoretically, I should receive an F-value for the model and a T-value for each coefficient.

like image 203
zsad512 Avatar asked Aug 29 '17 16:08

zsad512


2 Answers

You could try this:

   summary(fit)
like image 155
Bechir Barkallah Avatar answered Oct 02 '22 21:10

Bechir Barkallah


summary(fit)$coefficients[,4] for p-values

summary(fit)$coefficients[,3] for t-values

like image 36
Mayank Agrawal Avatar answered Oct 02 '22 22:10

Mayank Agrawal