0

Is there a function in R to calculate the critical value of F-statistic and compare it to the F-statistic to determine if it is significant or not? I have to calculate thousands of linear models and at the end create a dataframe with the r squared values, p-values, f-statistic, coefficients etc. for each linear model.

> summary(mod)

Call:
lm(formula = log2umi ~ Age + Sex, data = df)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.01173 -0.01173 -0.01173 -0.01152  0.98848 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.0115203  0.0018178   6.337 2.47e-10 ***
Age         -0.0002679  0.0006053  -0.443    0.658    
SexM         0.0002059  0.0024710   0.083    0.934    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1071 on 7579 degrees of freedom
Multiple R-squared:  2.644e-05, Adjusted R-squared:  -0.0002374 
F-statistic: 0.1002 on 2 and 7579 DF,  p-value: 0.9047

I am aware of this question: How do I get R to spit out the critical value for F-statistic based on ANOVA?

But is there one function on its own that will compare the two values and spit out True or False?

EDIT:

I wrote this, but just out of curiosity if anyone knows a better way please let me know.

f_sig is a named vector that I will later add to the dataframe

model <- lm(log2umi~Age + Sex, df)
f_crit <- qf(1-0.05, summary(model)$fstatistic[2], summary(model)$fstatistic[3] )
f <- summary(mod)$fstatistic[1]
if (f > f_crit) {
  f_sig[gen] = 0 #True
} else {
  f_sig[gen] = 1 #False
}
Jenny Wang
  • 25
  • 3
  • I have a very basic understanding of statistics. What is the distribution function that pf() outputs? – Jenny Wang Jul 26 '18 at 13:37
  • Use `broom::glance(model)`. Gives a bunch of statistics, including f statistic, p value, degrees of freedom, etc, in a nice data frame. You can use `broom::tidy` to get a similar data frame with the coefficients. – Gregor Thomas Jul 26 '18 at 14:03

0 Answers0