post分层配额样本如何使用调查包?

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

我正在尝试使用 R 中的调查包来权衡一项调查。我正在努力解决实现这一目标所需的论据。这是一个 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))

此时,我想创建一个 svydesign 对象,我可以将其提供给 survey::rake 函数,但我不确定如何做。假设我的样本是配额被关闭的配额样本,如何正确使用svydesign函数,才能将对象用于rake函数?

我想要的输出是使用上面显示的 census_props 对象的 post 分层样本。

构建 svydesign 对象,就像您的配额是正确的一样,然后对其进行耙整以实际使权重正确。