【问题标题】:Multiple response analysis in weighted survey data using srvyr使用 srvyr 对加权调查数据进行多重响应分析
【发布时间】:2017-09-22 07:44:34
【问题描述】:

我正在尝试分析加权调查数据集中的多选问题。我喜欢 srvyr 包,因为它允许我使用 dplyr 管道,但我找不到有关如何处理多响应问题的参考资料。

我有一个简单的数据集来查看不同的收入来源。这是数据的外观示例

ID <- c(1,2,3,4,5,6,7,8,9,10)
rent_income <- c("Yes", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "No")
salary_income <- c( "No", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No")
other_income <- c( "No", "Yes", "No", "No", "No", "No", "Yes", "No", "No", "No")
survey_weights <- c(0.6, 1.2 , 1.1 , 0.7 , 2.4 , 1.1 , 0.3 , 0.6 , 1.0 , 0.8)
df<-data.frame(ID, rent_income, salary_income, other_income, survey_weights)

请注意,数据完全是虚构的。使用srvyr 如果首先必须创建一个调查对象

weighted_dataset <- df %>% as_survey_design(ids=ID, weights=survey_weights)

现在我想计算具有不同收入类型的样本的加权百分比。关于如何做到这一点的任何想法?在 Stata 中有一个名为 mr_tab 的函数。但是我在R中找不到类似的

【问题讨论】:

    标签: r survey weighted-average


    【解决方案1】:

    您可以使用方便的group_by()dplyrsrvyr R 包提供的变量选择语法。

    weighted_dataset %>%
      # Organize the data into groups defined by each combination of the income variables
        group_by_at(vars(ends_with("_income"))) %>%
      # For categorical variables, this calculates estimates of percentages
        summarize(Percent = survey_mean())
    
    > # A tibble: 6 x 5
    >  rent_income salary_income other_income Percent Percent_se
    >  <fct>       <fct>         <fct>          <dbl>      <dbl>
    > 1 No          No            No             1          0    
    > 2 No          Yes           No             0.769      0.265
    > 3 No          Yes           Yes            0.231      0.265
    > 4 Yes         No            No             1          0    
    > 5 Yes         Yes           No             0.6        0.312
    > 6 Yes         Yes           Yes            0.40       0.312
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2011-08-17
      • 2016-12-05
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 2018-12-24
      相关资源
      最近更新 更多