# Test for ratio of variances across multiple groups

I am looking for a statistical test for whether the ratio of variances vary significantly among groups. I have 100 groups, each with ~50 A individuals and ~50 B individuals (n varies somewhat between groups). For each individual I have a single measure. A priori, I expect that the A individuals in each group are more variable than the B individuals, and I can test this using an F-test on the ratio of variances. However, I also want to know whether the ratio of variances changes significantly across groups. Does anyone know how to do this? My data are normally distributed etc

• Supposing you computed F statistics on two different groups, $F_1$ and $F_2$, I would adjust them back to the ratios of chi-square variables, then take the difference of their logs. If they have the same rescaling, then the log rescaling part should subtract out to zero. Then I would use the known moments of log chi-square variables to perform testing. In a pinch, the R package sadists has approximate CDF and quantile functions for the products of log chi-square variables. – steveo'america Feb 7 at 1:13

I don't know how to approach this for more than two groups, but for two groups my idea was to compute $$S^2_{i,A} = \sum_{a \in A} \left(x_{i,a} - \mu_{i,A}\right)^2$$ and similarly $$S^2_{i,B}$$ for $$i=1,2$$ where $$\mu_{i,A}$$ is the sample mean of the $$A$$ data for the $$i$$th group. Your $$F$$ statistics are basically $$F_i = \frac{S^2_{i,A}}{n_{i,A}-1} \frac{n_{i,B}-1}{S^2_{i,B}}.$$

Instead compute $$\Delta = \log\left(S^2_{1,A}\right)-\log\left(S^2_{1,B}\right)-\log\left(S^2_{2,A}\right) + \log\left(S^2_{2,B}\right).$$ Now $$\Delta$$ should have known mean and variance under the null hypothesis that the ratios of variances are equal.

A test:

sigrat <- 3
n1s <- c(100,40)
n2s <- c(30,50)
sfunc <- function(x) { sum((x-mean(x))^2) }
set.seed(1234)
pvals <- replicate(1000,{
xa1 <- rnorm(n1s[1],mean=0.1,sd=2*sigrat)
xb1 <- rnorm(n1s[2],mean=0.2,sd=2)
xa2 <- rnorm(n2s[1],mean=0.3,sd=0.157*sigrat)
xb2 <- rnorm(n2s[2],mean=0.4,sd=0.157)
S2_1A <- sfunc(xa1)
S2_1B <- sfunc(xb1)
S2_2A <- sfunc(xa2)
S2_2B <- sfunc(xb2)
stat <- log(S2_1A / S2_1B) - log(S2_2A / S2_2B)
pv <- psumlogchisq(stat,wts=c(1,-1,-1,1),   # the powers essentially
df=c(n1s,n2s)-1,         # the d.f.s of the chi-squares
ncp=0)   # they are central chi squares
})
# do this:
# plot(ecdf(pvals))
# instead, for txt plot I do this:
library(txtplot)
xvs <- ppoints(100)
yvs <- quantile(ecdf(pvals),xvs)
txtplot(xvs,yvs)


I get the following txtplot, confirming uniformity:

    +-+----------+----------+----------+----------+---------+--+
1 +                                                    ****  +
|                                                ****      |
0.8 +                                           *****          +
|                                       *****              |
|                                  *****                   |
0.6 +                              *****                       +
|                         *****                            |
0.4 +                     *****                                +
|                 *****                                    |
|              ****                                        |
0.2 +         *****                                            +
|      ****                                                |
0 +  ****                                                    +
+-+----------+----------+----------+----------+---------+--+
0         0.2        0.4        0.6        0.8        1