我有一个大型数据集,我正试图缩小以集中注意力。作为其中的一部分,我有三个变量,测量了五次。我已经把每次都变成了一个平均值,所以我最终得到了五个变量(每次一个),我想找到它们的内部一致性。当我尝试使用计算 Cronbach 的 alpha 时psych::alpha()
出现错误。
25行可重现数据:
structure(list(catme_satis1a = c(4L, 4L, 5L, 5L, 5L, NA, 1L,
4L, 4L, 4L, 4L, 2L, 4L, 4L, 3L, 4L, 4L, 5L, 3L, 4L, 5L, 3L, 4L,
4L, 5L), catme_satis1b = c(4L, 4L, 4L, 5L, 5L, NA, 1L, 4L, 5L,
5L, 4L, 2L, 5L, 4L, 3L, 4L, 4L, 5L, 3L, 4L, 5L, 3L, 4L, 4L, 5L
), catme_satis1c = c(3L, 4L, 5L, 5L, 5L, NA, 1L, 4L, 3L, 4L,
4L, 2L, 4L, 5L, 3L, 4L, 4L, 5L, 3L, 4L, 5L, 3L, 4L, 4L, 5L),
catme_satis2a = c(4L, 4L, 4L, 5L, 5L, NA, 5L, 4L, 5L, NA,
NA, 3L, NA, 4L, 3L, 4L, 4L, 5L, 3L, NA, 5L, 5L, 4L, 4L, 5L
), catme_satis2b = c(4L, 4L, 5L, 5L, 5L, NA, 5L, 4L, 5L,
NA, NA, 3L, NA, 4L, 3L, 4L, 3L, 5L, 2L, NA, 5L, 5L, 4L, 4L,
5L), catme_satis2c = c(4L, 4L, 5L, 5L, 5L, NA, 5L, 4L, 5L,
NA, NA, 3L, NA, 4L, 3L, 4L, 3L, 5L, 3L, NA, 5L, 5L, 4L, 4L,
5L), catme_satis3a = c(4L, 4L, 4L, 5L, 5L, 5L, 4L, 4L, 5L,
5L, 3L, NA, 3L, 4L, 3L, NA, 4L, 5L, 3L, 5L, 5L, 5L, 4L, 5L,
5L), catme_satis3b = c(4L, 4L, 4L, 5L, 5L, 5L, 3L, 4L, 5L,
5L, 3L, NA, 3L, 4L, 3L, NA, 4L, 5L, 3L, 5L, 5L, 5L, 4L, 5L,
5L), catme_satis3c = c(4L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 5L,
5L, 3L, NA, 3L, 4L, 3L, NA, 4L, 5L, 4L, 5L, 5L, 5L, 4L, 4L,
5L), catme_satis4a = c(4L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 5L,
4L, 3L, 3L, 3L, 4L, 3L, 4L, 4L, 4L, 4L, NA, 5L, 5L, 5L, 5L,
5L), catme_satis4b = c(4L, 4L, 5L, 5L, 5L, 4L, 4L, 4L, 5L,
4L, 3L, 3L, 2L, 4L, 3L, 4L, 5L, 5L, 4L, NA, 5L, 5L, 5L, 5L,
5L), catme_satis4c = c(4L, 4L, 5L, 5L, 5L, 4L, 4L, 4L, 5L,
3L, 3L, 3L, 2L, 4L, 3L, 5L, 4L, 4L, 4L, NA, 5L, 5L, 5L, 5L,
5L), catme_satis5a = c(5L, 4L, 5L, 5L, 5L, 5L, 5L, 4L, 5L,
4L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 5L, 5L, 1L, 5L,
5L), catme_satis5b = c(5L, 4L, 5L, 5L, 5L, 5L, 5L, 4L, 5L,
4L, 3L, 3L, 3L, 4L, 4L, 5L, 4L, 5L, 5L, 4L, 5L, 5L, 1L, 5L,
5L), catme_satis5c = c(5L, 4L, 5L, 5L, 5L, 5L, 5L, 4L, 5L,
4L, 3L, 3L, 2L, 4L, 4L, 5L, 4L, 3L, 5L, 4L, 5L, 5L, 1L, 5L,
5L)), class = "data.frame", row.names = c(NA, -25L), .Names = c("catme_satis1a",
"catme_satis1b", "catme_satis1c", "catme_satis2a", "catme_satis2b",
"catme_satis2c", "catme_satis3a", "catme_satis3b", "catme_satis3c",
"catme_satis4a", "catme_satis4b", "catme_satis4c", "catme_satis5a",
"catme_satis5b", "catme_satis5c"))
接下来,我尝试使用此方法来获取 1:3、4:6 等列的平均值(但按名称):
library(dplyr)
df1 <- test %>%
rowwise() %>%
transmute(catme_satis1 = mean(c(catme_satis1a, catme_satis1b, catme_satis1c)),
catme_satis2 = mean(c(catme_satis2a, catme_satis2b, catme_satis2c)),
catme_satis3 = mean(c(catme_satis3a, catme_satis3b, catme_satis3c)),
catme_satis4 = mean(c(catme_satis4a, catme_satis4b, catme_satis4c)),
catme_satis5 = mean(c(catme_satis5a, catme_satis5b, catme_satis5c)))
最后,我想知道这些变量使用psych
包的一致性:
library(psych)
alpha(df1)
这给出了这个错误:
> alpha(df1)
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
当我打印它时,我的数据框似乎是正确的,我应该能够获得这些值的一致性。为什么会r
抛出这个错误?