-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalpha.R
44 lines (37 loc) · 1.02 KB
/
alpha.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' Calculates Cronbach's alpha based on HCL-28 model
#'
#' @param data Dataset containing HCL-32 items.
#'
#' @return Cronbach's alpha coefficient calculated based on Pearson's correlation matrix in the full dataset, active factor and risk-taking factor.
#' @export
#'
alpha_hcl28 <- function(data) {
hcl28 <- data %>%
dplyr::select(
y1, y2, y3, y4, y5, y6,
y7, y8, y9, y10, y11, y12,
y13, y14, y15, y18, y19, y20,
y22, y24, y25, y26, y27, y28,
y29, y30, y31, y32
)
active <- data %>%
dplyr::select(
y2, y3, y4, y5, y6,
y10, y11, y12, y13, y14,
y15, y18, y19, y20, y22,
y24, y28
)
risk <- data %>%
dplyr::select(
y1, y7, y8, y9, y25,
y26, y27, y29, y30,
y31, y32
)
sets <- list(hcl28, active, risk) %>%
purrr::set_names("HCL-28", "Active factor", "Risk-taking factor")
alphas <- purrr::map(sets,
~ psych::alpha(.x)) %>%
purrr::map(purrr::pluck(1)) %>%
purrr::map(~ as.numeric(as.vector(.x)[2]))
return(alphas)
}