I'm having problems looping through variables using the survey package. Let's say I have a subset of variables I collect into a dataframe together with the survey weight and I want to carry out chi-square tests. Bearing in mind the problems with multiple testing, I would still like to test all unique combinations. This is normally relatively straightforward in R, and there's a good example here.
Unfortunately this become harder in the survey package because items need to be in the design object, and most importantly dataset indexing is not supported (at least as far as I know). I've tried adapting the example mentioned above to svychisq, but all my strategies have failed.
I've noticed that someone has done something similar here, but most of the variables are fixed. Would anyone be able to create a function (something similar to this answer maybe) but using the svychisq function? Unfortunately I don't know of datasets with lots of categorical variables and complex design available online. For the purposes of demonstration I suppose one could use dclus1 in data(api) as shown in the function help file and attempt to loop through the first 10 variables
library(survey)
data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
svychisq(~sch.wide+stype, dclus1)
Any help would be greatly appreciated.
UPDATE: What I'm really trying to do is avoiding specifying the variable names and give a vector of variables combinations instead. e.g.
MyChi2tests <- apply( combn(colnames(apiclus1[,c(2,16:17)]),2), 2, function(z) paste(z, collapse = '+'))