# crosstable and regression for survey data (weighted)

5 messages
Open this post in threaded view
|
Report Content as Inappropriate

## crosstable and regression for survey data (weighted)

 I have survey data that I am working on. I need to make some multi-way tables and regression analyses on the data. After attaching the data, this is the code I use for tables for four variables (sweight is the weight variable): > a <- xtabs(sweight~research.area + gender + a2n2 + age) > tmp <- ftable(a) Is this correct? I don't think I need to use the strata and cluster variables, right?   And, below is the logistic regression code that I use for randomly sampled, or unweighted, data: > logit.1 <- glm(var4 ~ var3 + var2 + var1, family = binomial(link = "logit")) > summary(logit.1) But how can I do the same analyses for the weighted data? Here is some additional info: There are four variables in the dataset that reflect the sampling structure. These are strat: stratum (urban or (sub-county) rural). clust: batch of interviews that were part of the same random walk vill_neigh_code: village or neighbourhood code sweight: weights
Open this post in threaded view
|
Report Content as Inappropriate

## Re: crosstable and regression for survey data (weighted)

Open this post in threaded view
|
Report Content as Inappropriate

## Re: crosstable and regression for survey data (weighted)

 Thanks Pablo for your answer, it was very insightful, but I guess I got something wrong. I formed a survey design as: > library(survey) > mydesign <- svydesign(ids=~vill_neigh_code+clust, strata=~strat, weights=~sweight, data=mydata) where strat: stratum (urban or (sub-county) rural). clust: batch of interviews that were part of the same random walk vill_neigh_code: village or neighbourhood code sweight: probability weights Then, I run a logistic regression as > logit.1 <- svyglm(response~var1+var2+var3+var4+var5+var6, design=mydesign, data=mydata, nest=TRUE, family=quasibinomial()) And I get this error message: Error in svyglm.survey.design(response ~ var1 + var2 + var3 + var4 +  :   all variables must be in design= argument What should I change in the syntax in this case?
Open this post in threaded view
|
Report Content as Inappropriate

## Re: crosstable and regression for survey data (weighted)

 In reply to this post by haps It seems the var names you've put are not the same as in the design object: "all variables must be in design= argument ": that means the object you've assigned in mydesign <- svydesign(ids=~vill_neigh_code+clust, strata=~strat, weights=~sweight, data=mydata) Check the spelling. Note that the "mydesign" is *not* a dataframe. That means that mydesign[,5] or mydesign\$myvar won't work (off course neither will naming the original dataframe "mydata"), you must just use the variable names alone for instance: svyglm(api00~ell+meals+mobility, design=dstrat) is correct, using only the var names, not dstrat[smth]~dstrat[smth]+ dstrat[smth] If you write the names correctly it should work regards pablo         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.