R中'scoreItems'功能的问题

时间:2018-03-26 11:19:44

标签: r average reverse

我正在尝试清理需要反编码的数据集,然后计算四个项目的平均值以准确测量一个方面(用于个性问卷)。我的数据被称为'hex_data',这是我到目前为止所得到的,除了我不断收到以下警告代码:

'Error in 1:nkeys : argument of length 0.' 

以下是我尝试运行的以下代码组合:

hex_data_rev <- reverse.code(keys = c(1,1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,-1,-1), items = hex_data, mini = NULL, maxi = NULL)

hsinc_score <- scoreItems(keys = c(1,1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,-1,-1), items = hex_data, totals = FALSE, missing = TRUE, impute = "none", min = rep(1,1351), max = rep(676,1351))
hsinc_score <- scoreItems(keys = rep(1,1351), items = hex_data_rev, totals = FALSE, missing = TRUE, impute = "none", min = rep(1,10), max = rep(6,10))


hscinc_score <- scoreItems(keys = c(1,1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,-1,-1), items = hex_data_rev, totals = FALSE, missing = TRUE, impute = "none", min = NULL, max = NULL)
hscinc_score <- scoreItems(keys = c(1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1), items = hex_data_rev, totals = FALSE, missing = TRUE, impute = "none", min = NULL, max = NULL)
hscinc_score <- scoreItems(keys = c(1,1), items = hex_data_rev[c(1:4)], totals = FALSE, missing = TRUE, impute = "none", min = NULL, max = NULL)
hscinc_score <- scoreItems(keys = rep(1,10), items = hex_data_rev, totals = FALSE, missing = TRUE, impute = "none", min = NULL, max = NULL)

如果没有意义,请帮助我/提问

1 个答案:

答案 0 :(得分:0)

我相信keys参数应该是一个矩阵。您还可以将keys.list参数传递给scoreItems()函数。我提交了一个向量键,而不是指定一个列表,并且得到了与您相同的错误消息。

传递keys.list的列表即可解决该问题。

# vector (wrong)
keys.list <- c(
    is = c("q1", "q2", "q3", "q4"), 
    cm = c("q5", "q6", "q7", "q8"),
    se = c( "q9", "q10", "q11", "q12"),
    tot = c("q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", 
          "q12"))

# list (right)
keys.list <- list(
    is = c("q1", "q2", "q3", "q4"), 
    cm = c("q5", "q6", "q7", "q8"),
    se = c( "q9", "q10", "q11", "q12"),
    tot = c("q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", 
          "q12"))

prescores <- scoreItems(keys.list, pre[,2:13], totals = FALSE)