1
$\begingroup$

I have the results from a survey where a geographic area was stratified and power allocation (using the number of households in each stratum) was used to determine the number of surveys to send out to each stratum.

From each household that returned a survey (which has a unique survey ID), I have the weight results from 1 or more people in the household. Thus in some instances a single survey from a single household has 5 responses to the weight question. I convert the weight from each response into one of four weight classes.

I want to obtain a point estimate for the proportion of the population who falls into each weight class along with the associated confidence interval, based on the age group of the respondent (Child versus Adult). To do so, I have placed the data from the surveys into a data.frame with the following columns:

  • SurveyID: the ID of the survey that the response came from
  • Stratum: identifies the Stratum that the survey was returned from
  • PostStratWeights: the post-stratified weight that accounts for survey non-response
  • AgeGroup: the age group that the response belongs to (Child/Adult)
  • WeightClass: the weight class of the respondent (one of four classes)

where each row in the data.frame corresponds to a single response from a survey (so multiple rows will have the same SurveyID if there was more than one weight response from a single survey).

I have specified the survey design as

mydesign = svydesign(ids=~SurveyID,
                        strata=~Stratum,
                        weights=~PostStratWeights,
                        data=survey_response_data)

Do I need to add in fpc for this survey design? I know both the estimated number of households in each stratum and the estimated number of people in each stratum.

Under the assumption that the survey design was correct, I then tried to compute the mean WeightInLbs as follows:

svyby(formula=~WeightClass,
        by=~AgeGroup+Stratum,
        FUN=svymean,
        design=mydesign,
        keep.names=FALSE)
        

However, running this produces the following error:

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

So I suspect something is wrong with the way I have specified my survey design but don't quite know what.

$\endgroup$
3
  • $\begingroup$ Those look correct, so I think we need some information about your data $\endgroup$ May 10 at 1:13
  • $\begingroup$ What information would you like about the data? I will edit the information into the original post. $\endgroup$ May 10 at 1:26
  • $\begingroup$ I have edited the post because I actually break the WeightInLbs into four classes, and so I am using the WeightClass column (a categorical variable) instead of the WeightInLbs column, a continuous variable. I want to get point estimates for the proportion of the population in each weight class. Sorry for having the wrong question in there initially. $\endgroup$ May 10 at 1:34
1
$\begingroup$

Ok. It sounds as if svymean() is converting ~WeightInLbs to a factor variable (maybe it starts as character?), which will happen separately for each combination of the by variables, and that some combination of the by variables has only one weight category present.

If this is what's happening, you can create the factor variable in advance using update

mydesign<-update(mydesign, WeightClassFactor = factor(WeightClass))
svyby(formula=~WeightClassFactor,
        by=~AgeGroup+Stratum,
        FUN=svymean,
        design=mydesign,
        keep.names=FALSE)
$\endgroup$
1
  • $\begingroup$ This must have been what was happening because creating the factor variable in advance solved the issue. I am still a little unsure regarding whether I need to add in the fpc for this design - any thoughts on that? $\endgroup$ May 10 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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