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.

function in R Programming performs an F-test between 2 normal populations with the hypothesis that variances of the 2 populations are equal.**var.test()**

#### Formula for Fisher’s F-Test

F = Larger Sample Variance / Smaller Sample Variance

#### Implementation in R

- 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 vectors

alternative: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 samples ` `x <- ` `rnorm` `(249, mean = 20) ` `y <- ` `rnorm` `(79, mean = 30) ` `# var test in R ` `var.test` `(x, y, alternative = ` `"two.sided"` `) ` |

*chevron_right*

*filter_none*

**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.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 samples ` `A = ` `c` `(16, 17, 25, 26, 32, ` ` ` `34, 38, 40, 42) ` `B = ` `c` `(600, 590, 590, 630, 610, 630) ` `# var test in R ` `var.test` `(A, B, alternative = ` `"two.sided"` `) ` |

*chevron_right*

*filter_none*

**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.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 samples ` `x = ` `c` `(25, 29, 35, 46, 58, 66, 68) ` `y = ` `c` `(14, 16, 24, 28, 32, 35, ` ` ` `37, 42, 43, 45, 47) ` `# var test in R ` `var.test` `(x, y) ` |

*chevron_right*

*filter_none*

**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.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.