Please consider the following code to obtain scores from the alpha
function
library(psych)
vars <- c('mpg', 'cyl', 'disp', 'hp')
df <- mtcars[0:10, vars]
alpha_results <- alpha(df, check.keys=TRUE)
df$scores <- alpha_results$scores
print(head(df))
mpg cyl disp hp scores
21.0 6 160 110 154.750
21.0 6 160 110 154.750
22.8 4 108 93 136.550
21.4 6 258 110 179.150
18.7 8 360 175 222.075
18.1 6 225 105 170.475
Item statistics
n raw.r std.r r.cor r.drop mean sd
mpg- 10 0.86 0.94 0.91 0.85 343.6 2.9
cyl 10 0.91 0.96 0.94 0.91 5.8 1.5
disp 10 0.98 0.93 0.90 0.85 208.6 90.4
hp 10 0.94 0.95 0.94 0.85 122.8 51.4
Based on the doc of the function:
Scores are by default simply the average response for all items that a participant took. If cumulative=TRUE, then these are sum scores. Note, this is dangerous if there are lots of missing values
However, for example, the score for the first obs should be
(-21.0 + 6 + 160 + 110)/4 = 63.75
But the result was 154.750 instead.