I am trying to construct a hypothesis test for the variance of two populations. My test statistic is $F=$${\sigma_b^2}$/${\sigma_A^2}$. I want to implement this as a function in R so I computed: a=function(B,A){ var(B)/var(A) }

Now, I want to compute the p-value using this test statistic in R. How can I do this?


1 Answer 1


Since you are calculating the F-statistic could use the pf function.

As an example, let's take the following data as an example.

x <- rnorm(50, mean = 0, sd = 2)
y <- rnorm(30, mean = 1, sd = 1)
f <- var(x)/var(y)

# make sure to double for two-sided
pf(f, df1=49, df2=29, lower.tail=F)*2
[1] 0.0001897506

As gung noted, I failed to realize you are trying to do Hartley's Fmax test. In which case, you don't even need to calculate the F statistic or even the variances, you can just use var.test.

var.test(x, y)$p.value
[1] 0.0001897506

Also as noted by gung, there is Levene's test (leveneTest) in the car package.

  • $\begingroup$ The OP is attempting to conduct Hartley's $F$-max test, thus the df you give are incorrect (see here, & here). $\endgroup$ Dec 4, 2014 at 18:25
  • $\begingroup$ @gung You are correct, I embarrassingly overlooked that. Updated now. $\endgroup$
    – cdeterman
    Dec 4, 2014 at 18:34
  • $\begingroup$ That's OK, it's an easy thing to overlook. Please correct the df in your answer, though. $\endgroup$ Dec 4, 2014 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.