expss 包可以处理带有加权数据的多选题吗?

Can the expss package process multiple answer questions with weighted data?

expss包可以解决这个link中提出的问题吗?是关于数据集中带有权重变量的多选题

How to use the R survey package to analyze multiple response questions in a weighted sample?

假设我们有这个数据集:

demo <- tribble(
~dummy1, ~dummy2, ~dummy3, ~survey_weight,
      1,       0,       0,          1.5,
      1,       1,       0,          1.5,
      1,       1,       1,           .5,
      0,       1,       1,          1.5,
      1,       1,       1,           .5,
      0,       0,       1,           .5,
)

我需要根据回答问题的总受访者而不是总答复来计算百分比

是的,这很容易:

library(expss)
demo = text_to_columns("
    dummy1 dummy2 dummy3 survey_weight
    1        0        0           1.5
    1        1        0           1.5
    1        1        1            .5
    0        1        1           1.5
    1        1        1            .5
    0        0        1            .5
")


demo %>% 
    tab_cells(mdset(dummy1 %to% dummy3)) %>%  # 'mdset' designate that with have multiple dichotomy set
    tab_weight(survey_weight) %>% # weight
    tab_stat_cpct() %>% # statistic
    tab_pivot() 

# |              | #Total |
# | ------------ | ------ |
# |       dummy1 |   66.7 |
# |       dummy2 |   66.7 |
# |       dummy3 |   50.0 |
# | #Total cases |    6.0 |

# shorter notation with the same result
calc_cro_cpct(demo, mdset(dummy1 %to% dummy3), weight = survey_weight)

但请注意,expss 在 SPSS 风格中使用简单的频率权重,而 'survey' 包可以提供更准确的加权方案。