How to find the critical value of F for regression anova in R?

R ProgrammingServer Side ProgrammingProgramming

To find the critical value of F for regression anova in R, we can follow the below steps −

  • First of all, create a data frame.
  • Then, create the regression model.
  • After that, find the critical value of F statistic using qf function.

Create the data frame

Let's create a data frame as shown below −

 Live Demo

> x<-rpois(20,2)
> y<-rpois(20,5)
> df<-data.frame(x,y)
> df

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

   x y
1  5 5
2  0 9
3  1 3
4  3 5
5  2 5
6  2 4
7  3 6
8  4 6
9  2 5
10 0 6
11 5 8
12 1 7
13 3 2
14 0 4
15 1 4
16 2 4
17 1 7
18 2 8
19 2 6
20 1 4

Create the regression model

Using lm function to create the regression model between y and x and anova function to find the ANOVA table −

 Live Demo

> x<-rpois(20,2)
> y<-rpois(20,5)
> df<-data.frame(x,y)
> RegM<-lm(y~x,data=df)
> RegM_ANOVA<-anova(RegM)
> RegM_ANOVA

Output

Analysis of Variance Table
Response: y
   Df Sum  Sq Mean Sq F value Pr(>F)
x  1  0.024 0.0238 0.0071 0.934
Residuals 18 60.776 3.3765

Find the critical value of F for regression anova

Using qf function to find the critical value of F for regression anova −

 Live Demo

> x<-rpois(20,2)
> y<-rpois(20,5)
> df<-data.frame(x,y)
> RegM<-lm(y~x,data=df)
> RegM_ANOVA<-anova(RegM)
> qf(1-0.05,RegM_ANOVA[1,1],RegM_ANOVA[2,1])

Output

[1] 4.413873
raja
Published on 02-Aug-2021 12:53:08
Advertisements