r语言 - 如何将抽样权重纳入李克特量表调查问题的分析中



我正在分析调查数据,其问题以李克特量表的形式出现。我使用辅助人口普查数据来计算样本中不同年龄组的权重。我现在想使用这些权重来校正我的样本数据,然后显示针对每个年龄组区分的每个问题的分布。

任何帮助不胜感激!

在 R 中执行此操作的传统方法是使用 survey 包和/或 srvyr 包,它允许您使用 dplyr 样式语法,同时依靠 survey 包来正确处理权重和复杂的测量设计。

下面是使用 srvyr 包分析 Likert 数据的小示例。

# Create example data ----
  library(survey)
  library(srvyr)
  set.seed(1999)
    ## Data frame of responses and grouping information
    likert_response_options <- c("1 - Strongly Disagree", "2", "3", "4", "5 - Strongly Agree")
      data_df <- data.frame(
        group_vbl = factor(sample(LETTERS[1:4], 20, replace = TRUE), LETTERS[1:4]),
        likert_item = factor(x = sample(likert_response_options, 20, replace = TRUE), 
                             levels = likert_response_options),
        weights = rnorm(20, mean = 1, sd = 0.1)
      )
    ## Create a survey design object from the data frame
      my_survey_design <- as_survey_design(data_df, weights = weights)
# Create weighted summaries ----
      my_survey_design %>% 
        group_by(group_vbl, likert_item) %>%
        summarize(proportion = survey_mean())
#> # A tibble: 20 x 5
#>    group_vbl likert_item           proportion proportion_low proportion_upp
#>    <fct>     <fct>                      <dbl>          <dbl>          <dbl>
#>  1 A         1 - Strongly Disagree      0.300        -0.252           0.851
#>  2 A         2                          0             0               0    
#>  3 A         3                          0.700         0.149           1.25 
#>  4 A         4                          0             0               0    
#>  5 A         5 - Strongly Agree         0             0               0    
#>  6 B         1 - Strongly Disagree      0.127        -0.130           0.384
#>  7 B         2                          0.146        -0.143           0.435
#>  8 B         3                          0.259        -0.0872          0.606
#>  9 B         4                          0.468         0.0577          0.878
#> 10 B         5 - Strongly Agree         0             0               0    
#> 11 C         1 - Strongly Disagree      0             0               0    
#> 12 C         2                          0.241        -0.213           0.696
#> 13 C         3                          0.292        -0.221           0.804
#> 14 C         4                          0.250        -0.216           0.716
#> 15 C         5 - Strongly Agree         0.217        -0.205           0.639
#> 16 D         1 - Strongly Disagree      0             0               0    
#> 17 D         2                          0.529         0.0906          0.967
#> 18 D         3                          0             0               0    
#> 19 D         4                          0.159        -0.156           0.474
#> 20 D         5 - Strongly Agree         0.312        -0.0888          0.713

最新更新