library(psych)
library(psychTools)
data(bfi)
# ==============================
# = Score Agreeableness totals =
# ==============================
# Handscore subject 1
# A1(R)+A2+A3+A4+A5 = (6+1)-2 +4+3+4+4 = 20
tmp = umx_score_scale(base = "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
# ====================
# = Request the mean =
# ====================
tmp = umx_score_scale(name = "A", base = "A",
pos = 2:5, rev = 1, max = 6, data= bfi, score="mean")
tmp$A[1] # = 4
# ========================
# = Request factor score =
# ========================
if (FALSE) {
tmp = umx_score_scale(name = "A", base = "A", pos = 2:5, rev = 1,
max = 6, score = "factor", minManifests = 4, data= bfi)
# g
# A2 0.6574826
# A3 0.7581274
# A4 0.4814788
# A5 0.6272332
# A1 0.3736021
# ==================
# = Request alpha =
# ==================
tmp=umx_score_scale(base="A", pos=2:5, rev=1, max=6, data=bfi, alpha=TRUE)
# omega t = 0.72
}
# ==================
# = na.rm = TRUE ! =
# ==================
tmpDF = bfi
tmpDF[1, "A1"] = NA
tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= tmpDF, score="mean")
tmp$A_score[1] # 3.75
tmp= umx_score_scale("A", pos= 2:5, rev= 1, max = 6, data = tmpDF,
score="mean", na.rm=FALSE)
tmp$A_score[1] # NA (reject cases with missing items)
# ===============
# = 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 (reversed) item 1
# Default scale name
tmp = umx_score_scale("E", pos = 3:5, rev = 1:2, max = 6,
data= tmp, score = "mean", na.rm = FALSE)
tmp$E_score[1]
# 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"])
RevelleE == tmp[,"E_score"]
# =======================
# = MapStrings examples =
# =======================
mapStrings = c(
"Very Inaccurate", "Moderately Inaccurate",
"Slightly Inaccurate", "Slightly Accurate",
"Moderately Accurate", "Very Accurate")
bfi$As1 = factor(bfi$A1, levels = 1:6, labels = mapStrings)
bfi$As2 = factor(bfi$A2, levels = 1:6, labels = mapStrings)
bfi$As3 = factor(bfi$A3, levels = 1:6, labels = mapStrings)
bfi$As4 = factor(bfi$A4, levels = 1:6, labels = mapStrings)
bfi$As5 = factor(bfi$A5, levels = 1:6, labels = mapStrings)
bfi= umx_score_scale(name="A" , base="A", pos=2:5, rev=1, max=6, data=bfi)
bfi= umx_score_scale(name="As", base="As", pos=2:5, rev=1, mapStrings = mapStrings, data= bfi)
Run the code above in your browser using DataLab