1

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

任何帮助表示赞赏!

4

1 回答 1

0

在 R 中执行此操作的常规方法是使用survey包和/或srvyr允许您使用dplyr-style 语法的包,同时依靠survey包来正确处理加权和复杂的调查设计。

srvyr下面是一个使用包分析李克特数据的小例子。

# 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
于 2019-06-26T20:44:27.647 回答