# P-value of F-test to compare two variances (var.test in R)

I am trying to understand where the p-value of a F-test comparing two variances comes from. More specifically, the p-value given by R's var.test function does not match p-value assigned to a F-test by the pf function with the same F value and degrees of freedom.

For example, p-value given here:

> d1 <- rnorm(300, sd=1)
> d2 <- rnorm(300, sd=1.2)
> var.test(d1, d2)

F test to compare two variances

data:  d1 and d2
F = 0.78, num df = 299, denom df = 299, p-value = 0.03212
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.62 0.98
sample estimates:
ratio of variances
0.78


Does not match this one:

> pf(0.78, 299, 299, lower.tail=F)
 0.98


Could someone explain where the difference comes from?

• This (why that test uses two-tailed pvalues, rather than one, as in the F-test in ANOVA) is discussed in a number of posts on this site, including this one, and also in the extensive comments under this one – Glen_b Mar 23 '14 at 21:25

set.seed(2);var.test(rnorm(300),rnorm(300,0,1.2)): $F_{(299,299)}=.8148,p=.07706$.
2*(1-pf(.8148,299,299,lower.tail=F)): $p=.07710$. Close enough, right? I just subtracted from 1, and multiplied by 2 to get the two-tailed value.
set.seed(2);2*(1-pf( var.test(rnorm(300),rnorm(300,0,1.2))$statistic ,299,299,lower.tail=F)) $p=.07705506$. Even more digits than the output from var.test! Otherwise identical. • Thanks for your reply but p-value in var.test is 0.03212. In what way is it close to 0.077? – twowo Mar 23 '14 at 19:43 • You randomly generated your data and didn't provide the seed, so I randomly generated some other data. 2*(1-pf(.78,299,299,lower.tail=F))$=.03206452\$. – Nick Stauner Mar 23 '14 at 19:54