# F-Test for Equality of Variances with Weighted Survey Data

I would like to use an F-Test for Equality of Variances on a variable to compare two groups. Normally, this would be done with an sdtest command in Stata or a var.test command in R. However, the data come from a multi-stage, stratified random sample with disproportionate selection, and thus, need to be weighted.

Both Stata and R have packages geared at running analyses with complex sampling weights. In Stata it is done via the svyset command and subsequent analyses are ran with the svy prefix (e.g. svy: mean). Likewise, it is done in R via the survey package, which also subsequently conducts analyses with a svy prefix (e.g. svymean).

But, unless I have overlooked something, neither seem able to do an F-test for Equality of Variances (or a similar test) on weighted data. They both can do difference in means t-tests (R via svyttest) and Stata via postestimation commands.

Is there a workaround for this? A different test, perhaps, or a manual override in which the weighted data are converted to appear unweighted? Or is it statistically dubious to test for the equality of variances between two groups using weighted data (given that weighting affects variances), and therefore the reason why such options do not exist in Stata or R? If that's the case, what should one do when he or she wants to compare the variances of two groups that were sampled disproportionately? Certainly running F-tests on unweighted data isn't a better option, and since many surveys feature disproportionate selection methods, there must be some viable solution other than simply saying "you can't do that", right?

You can compare variances from first principles, i.e., by calculating the variance as the difference between value-squared and mean-squared.

webuse nhanes2, clear
gen bpsystol_sq = bpsystol* bpsystol
svy : mean bpsystol*, over( female )
* estimated variance in group 0
nlcom ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0])
* estimated variance in group 1
nlcom ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1])
* equality test
testnl ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1]) ///
= ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0])


In R you can calculate weighted variance for each group using function "wt.var" from the package "SDMTools". As a result you'll have two weighted variances - var1 and var2 F statistic equals var1/var2 And the degrees of freedom for that F value are WEIGHTED n1 - 1 and WEIGHTED n2 - 1. Done

• So then you can use wt.var or wt.sd in the SDMTools package to create a weighted variance or SD, and then, presumably, use the normal F-test in R? – coip Oct 8 '15 at 23:31