I am trying to predict a binary outcome with a model that includes a random effect using survey data. I've included a description of the sampling design below, so feel free to comment on my survey weighting approach. My primary question is how to include a random effect in the survey weighted model. Here is the code up to this point:

# Libraries
# Make dataframe object where d is the working dataframe
dfobj <- svydesign((id = ~cluster+household, 
   strata = ~interaction(region, urban),  
   weights = ~chweight, strata = ~strata, data = d)

# Run a logit model
formula1 <- stunting ~ modern_toilet + diarrhoea + fever 
   + insurance + sex + age + region_code
model1 <- svyglm(formula=formula1,design=dfobj,family = quasibinomial)

I would like the random effect to be on the region. Thanks,

Sampling Description:

The MICS 2006 used a two-stage stratified sample design. At the first stage of sampling, 300 census enumeration areas (124 urban and 176 rural EAs) were selected. These are a subsample of the 660 EAs (281 urban and 379 rural) selected for the GLSS 5. The clusters in each region were selected using systematic sampling with probability proportional to their size.

  • $\begingroup$ So is the region you want to be the random effect also the first sampling unit - the one with 300 different levels? I don't think I can answer your question (because I don't know how to do this, and think there isn't an out of the box way to do it), but this will have a bearing on it. Conceptually, there is a sort of connection between region in the sampling design and as a possible level of random effect - but these two approaches come from different historical approaches to this sort of data. $\endgroup$ Aug 18, 2012 at 4:11
  • $\begingroup$ To clarify, I would want the random effect to be at the regional level (or perhaps the region-urban, region-suburban level), which is 10 and 20 groups respectively. $\endgroup$
    – mike
    Aug 19, 2012 at 16:49

1 Answer 1


I have been unable to have R perform mixed effect logistic regression with appropriate weights to my liking. By appropriate, I mean with weights scaling as discussed by Pfeffermann et. al. (1998). There's just too much going on for lme4 to bother with the sampling weights.

I know that this sounds like the end of the world to R users (can you believe that something is not implemented in R???), but as of mid 2016, the solutions seem to be gllamm in Stata (written, for goodness sake, back in 2001) -- see http://gllamm.org -- where you can specify anything, at the cost of convoluted data reshaping and management -- and SAS PROC GLIMMIX.

  • $\begingroup$ Just in-case anyone comes across this older poster, the WeMix package has recently been developed in R and it can apply weights for each clustering level, see: cran.r-project.org/web/packages/WeMix/vignettes/… $\endgroup$ May 15, 2023 at 12:10
  • $\begingroup$ I have seen WeMix although it was a few years ago. As far as I remember checking what it did and how it did it, version 2 was matching gllamm results, while version 3 with the same syntax didn't. I have not evaluated version 4. $\endgroup$
    – StasK
    May 15, 2023 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.