2

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 Answers1

6

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

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

set.seed(123)
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.

cdeterman
  • 5,101