To compare the respective variances of two samples, you may use Fisher’s F test, also known as F-test of equality of variances. This test checks whether the variances of the two samples are equal, assuming that they do not deviate from normality. Note that this particular test is rather sensitive to the assumption of normal distribution. Thus you might want to test for normality prior to performing Fisher’s F test.
In brief, Fisher’s F test calculates the ratio between the larger variance and the smaller variance. The ratio is then compared to a critical value which depends on the degrees of freedom and on the set value for α (usually 0.05). If the ratio is greater than the critical value, then the null hypothesis (H0=the variances are equal) is rejected and you may declare that the variances are different.
The function in R that runs Fisher’s F test is
data2 are the vectors containing data from the two samples. Let’s use an example to illustrate the use of
var.test(). First let’s visualize these two samples in a boxplot:
data1<-c(11.25, 10.00, 9.68, 10.52, 8.77, 9.92, 8.62, 10.21, 9.09, 10.36) data2<-c(10.52, 7.99, 9.20, 5.59, 14.64, 15.50, 16.96, 7.03, 9.36, 4.72) boxplot(data1,data2)
The boxplot shows samples with means rather close to 10, but with dramatically different spreads. Let’s now look at their variance (obtained via
Unsurprisingly the variances differ a lot. But we need to run Fisher’s F test to get it confirmed. Since this test requires that normal distribution of the samples, let’s run the Shapiro-Wilks normality test.
In both cases, the p-value is high. The likelihood for these samples to deviate from normality is low. Thus, we can finally proceed with Fisher’s F test:
The F value (ratio of variances) is displayed, along with a p-value. Here the p-value is very low, thus the null hypothesis H0 (variances are equal) is rejected.
Note that you may reverse the order of the samples in the function.
You thus get a different F value, of course. However, the p-value remains the same, and so does the conclusion: variances are different.
Note: Fisher’s F test is not the only test for equal variance, but it is very commonly used. You could as well use Bartlett’s test or the Fligner-Killeen test of homogeneity of variances, but these are more often used for comparison of more than two groups (like in ANOVA). Bartlett’s test, like Fisher’s F test is rather sensitive to normality; thus, normality of distribution should be checked ahead of time. However, Figner-Killeen test is non-parametric. It is thus a good alternative when normality is challenged. The corresponding functions in R are