*25*

An **F-test **is used to test whether two population variances are equal. The null and alternative hypotheses for the test are as follows:

**H _{0}:** σ

_{1}

^{2}= σ

_{2}

^{2}(the population variances are equal)

**H _{1}:** σ

_{1}

^{2}≠ σ

_{2}

^{2}(the population variances are

*not*equal)

To perform an F-test in R, we can use the function **var.test() **with one of the following syntaxes:

**Method 1:**var.test(x, y, alternative = “two.sided”)**Method 2:**var.test(values ~ groups, data, alternative = “two.sided”)

Note that *alternative *indicates the alternative hypothesis to use. The default is “two.sided” but you can specify it to be “left” or “right” instead.

This tutorial explains how to perform an F-test in R using both methods.

**Method 1: F-Test in R**

The following code shows how to perform an F-test using the first method:

#define the two groups x #perform an F-test to determine in the variances are equal var.test(x, y) F test to compare two variances data: x and y F = 4.3871, num df = 9, denom df = 9, p-value = 0.03825 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 1.089699 17.662528 sample estimates: ratio of variances 4.387122

The F test statistic is **4.3871 **and the corresponding p-value is **0.03825**. Since this p-value is less than .05, we would reject the null hypothesis. This means we have sufficient evidence to say that the two population variances are *not *equal.

**Method 2: F-Test in R**

The following code shows how to perform an F-test using the first method:

#define the two groups data rep(c('A', 'B'), each=10)) #perform an F-test to determine in the variances are equal var.test(values~group, data=data) F test to compare two variances data: x and y F = 4.3871, num df = 9, denom df = 9, p-value = 0.03825 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 1.089699 17.662528 sample estimates: ratio of variances 4.387122

Once again the F test statistic is **4.3871 **and the corresponding p-value is **0.03825**. Since this p-value is less than .05, we would reject the null hypothesis.

This means we have sufficient evidence to say that the two population variances are *not *equal.

**Related**: Perform an F-test using this free F-Test for Equal Variances Calculator.

**When to Use the F-Test**

The F-test is typically used to answer one of the following questions:

**1.** Do two samples come from populations with equal variances?

**2.** Does a new treatment or process reduce the variability of some current treatment or process?

**Additional Resources**

How to Perform an F-Test in Python

How to Interpret the F-Test of Overall Significance in Regression