Fisher’s F-Test in R Programming - GeeksforGeeks

22 Jul, 2020
Fisher’s F test calculates the ratio between the larger variance and the smaller variance. We use the F test when we want to check where means of three or more groups are different or not. F-test is used to assess whether the variances of two populations (A and B) are equal. The method is simple; it consists of taking the ratio between the larger variance and the smaller variance. var.test() function in R Programming performs an F-test between 2 normal populations with the hypothesis that variances of the 2 populations are equal.
F = Larger Sample Variance / Smaller Sample Variance
To test the equality of variances between the two sample use var.test(x, y)
To compare two variance use var.test(x, y, alternative = "two.sided")
Syntax:var.test(x, y, alternative = “two.sided”)
Parameters:x, y: numeric vectorsalternative: a character string specifying the alternative hypothesis.
Example 1:Let we have two samples x, y. The R function var.test() can be used to compare two variances as follow:
# Taking two samplesx <- rnorm(249, mean = 20)y <- rnorm(79, mean = 30)# var test in Rvar.test(x, y, alternative = "two.sided")
Output:
       F test to compare two variances
data:  x and y
F = 0.88707, num df = 248, denom df = 78, p-value = 0.4901
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.6071405 1.2521004
sample estimates:
ratio of variances  
        0.8870677 

It returns the following:
the value of the F test statistic.the degrees of the freedom of the F distribution of the test statistic.the p-value of the test 0.4901a confidence interval for the ratio of the population variances.the ratio of the sample variances 0.8870677
the value of the F test statistic.
the degrees of the freedom of the F distribution of the test statistic.
the p-value of the test 0.4901
a confidence interval for the ratio of the population variances.
the ratio of the sample variances 0.8870677
The p-value of F-test is p = 0.4901 which is greater than the alpha level 0.05. In conclusion, there is no difference between the two sample.
Example 2:Let we have two random samples from two random population. Test whether two population have same variance.
# Taking two random samplesA = c(16, 17, 25, 26, 32,          34, 38, 40, 42)B = c(600, 590, 590, 630, 610, 630)# var test in Rvar.test(A, B, alternative = "two.sided")
Output:
       F test to compare two variances
data:  A and B
F = 0.27252, num df = 8, denom df = 5, p-value = 0.1012
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.04033118 1.31282683
sample estimates:
ratio of variances  
        0.2725248

It returns the following:
the value of the F test statistic.the degrees of the freedom of the F distribution of the test statistic.the p-value of the test 0.101295% confidence interval for the ratio of the population variances.the ratio of the sample variances 0.2725248
the value of the F test statistic.
the degrees of the freedom of the F distribution of the test statistic.
the p-value of the test 0.1012
95% confidence interval for the ratio of the population variances.
the ratio of the sample variances 0.2725248
The p-value of F-test is p = 0.1012 which is greater than the alpha level 0.05. In conclusion, there is no difference between the two samples.
Example 3:Let we have two random sample.
# Taking two random samplesx = c(25, 29, 35, 46, 58, 66, 68)y = c(14, 16, 24, 28, 32, 35,           37, 42, 43, 45, 47)# var test in Rvar.test(x, y)
Output:
       F test to compare two variances
data:  x and y
F = 2.4081, num df = 6, denom df = 10, p-value = 0.2105
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.5913612 13.1514157
sample estimates:
ratio of variances  
           2.4081

It returns the following:
the value of the F test statistic.the degrees of the freedom of the F distribution of the test statistic.the p-value of the test 0.210595% confidence interval for the ratio of the population variances.the ratio of the sample variances 2.4081
the value of the F test statistic.
the degrees of the freedom of the F distribution of the test statistic.
the p-value of the test 0.2105
95% confidence interval for the ratio of the population variances.
the ratio of the sample variances 2.4081
The p-value of F-test is p = 0.2105 which is greater than the alpha level 0.05. In conclusion, there is no difference between the two samples.
Picked
R Machine-Learning
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Change Axis Scales in R Plots?
Group by function in R using Dplyr
How to Split Column Into Multiple Columns in R DataFrame?
How to filter R DataFrame by values in a column?
How to import an Excel File into R ?
How to filter R dataframe by multiple conditions?
Replace Specific Characters in String in R
Time Series Analysis in R
R - if statement