# NOT RUN {
library(psych)
data(bfi)
# ==============================
# = Score Agreeableness totals =
# ==============================
# Handscore subject 1
# A1(Reversed) + A2 + A3 + A4 + A5
# (6+1)-2 + 4 + 3 + 4 + 4 = 20
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= bfi, name = "A")
tmp[1, namez(tmp, "A",ignore.case=FALSE)]
# A1 A2 A3 A4 A5 A
# 2 4 3 4 4 20
# =================================================================================
# = Note: (as of a fix in 2020-05-08) items not reversed in the returned data set =
# =================================================================================
tmp = umx_score_scale("A", pos = 1, rev = 2:5, max = 6, data= bfi, name = "A")
tmp[1, namez(tmp, "A",ignore.case=FALSE)]
# A1 A2 A3 A4 A5 A
# 2 4 3 4 4 = 15
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= bfi, name = "A", score="mean")
tmp$A[1] # subject 1 mean = 4
# ===========================================
# = How does mean react to a missing value? =
# ===========================================
tmpDF = bfi
tmpDF[1, "A1"] = NA
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= tmpDF, name = "A", score="mean")
tmp$A[1] # NA: (na.rm defaults to FALSE)
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= tmpDF,
name = "A", score="mean", na.rm=TRUE)
tmp$A[1] # 3.75
# ===============
# = Score = max =
# ===============
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= bfi, name = "A", score="max")
tmp$A[1] # subject 1 max = 5 (the reversed item 1)
tmp = umx_score_scale("E", pos = c(3,4,5), rev = c(1,2), max = 6, data= tmp)
tmp$E_score[1] # default scale name
# Using @BillRevelle's psych package: More diagnostics, including alpha
scores= psych::scoreItems(items = bfi, min = 1, max = 6, keys = list(
E = c("-E1","-E2", "E3", "E4", "E5"),
A = c("-A1", "A2", "A3", "A4", "A5")
))
summary(scores)
scores$scores[1,]
# E A
# 3.8 4.0
# Compare output
# (note, by default psych::scoreItems replaces NAs with the sample median...)
RevelleE = as.numeric(scores$scores[,"E"]) * 5
all(RevelleE == tmp[,"E_score"], na.rm = TRUE)
# }
Run the code above in your browser using DataLab