Search code examples
rsurvey

How to use the survey package for a post-stratified quota sample?


I am trying to weigh a survey with the survey package in R. I am struggling with the arguments needed to achieve this. Here is a MWE:

### SURVEY DATA
country <- rep(c("country A", "country B"), 5)
response <- rep(c("J", "K", "L", "M"), 3)[-c(1:2)]
age_group <- c(1,1,2,2,2,2,2,3,3,3)
sex <- rep(c("female", "male"), 5)
survey <- as.data.frame(cbind(country, response, age_group, sex))

### SAMPLE PROPORTIONS BY COUNTRY
library(dplyr)
sample_props <- survey %>%
  group_by(country, age_group, sex) %>%
  count() %>%
  group_by(country) %>%
  mutate(sample_prop = n / sum(n))

### POPULATION PROPORTIONS
country_pop <- c(rep("country A", 6), rep("country B", 6))
age_group_pop <- rep(c(1,1,2,2,3,3), 2)
sex_pop <- rep(c("female", "male"), 6)
pop_prop <- c(.2,.3,.4,.4,.3,.2, #proportions for country A
          .4,.3,.3,.4,.3,.3) #country B
census_props <- as.data.frame(cbind(country_pop, age_group_pop, sex_pop, pop_prop))

At this point, I'd like to create a svydesign object which I can feed into the survey::rake function but I'm not sure how. Assuming that my sample is a quota sample whose quotas are off, how do I correctly use the svydesign function so that I can use the object for the rake function?

My desired output is a post-stratified sample using the census_props object shown above.


Solution

  • Construct the svydesign object as if your quotas were correct, then rake it to actually make the weights correct.