R/correct_attributes.R
Did you create aggregates of items like this
scale <- scale_1 + scale_2R + scale_3R?
If you run this function on a dataset, it will detect these
relationships and set the appropriate attributes. Once they are set,
the codebook package can perform reliability computations for you.
detect_scales(data, quiet = FALSE)
| data | the data frame |
|---|---|
| quiet | defaults to false. Suppresses messages about found items. |
bfi <- data.frame(matrix(data = rnorm(500), ncol = 5)) names(bfi) <- c("bfi_e1", "bfi_e2R", "bfi_e3", "bfi_n1", "bfi_n2") bfi$bfi_e <- rowMeans(bfi[, c("bfi_e1", "bfi_e2R", "bfi_e3")]) bfi <- detect_scales(bfi)#>#> Warning: bfi_n items found, but no aggregatebfi$bfi_e#> [1] -0.7389 0.2768 -1.1883 -0.3578 -1.1938 0.1745 -1.1596 -0.4724 -0.6936 #> [10] 1.1149 -0.6387 -0.3704 1.0366 -1.1144 0.5411 0.1130 0.1538 -0.4405 #> [19] -0.2200 0.3667 0.7229 0.2456 0.0425 0.4295 0.3326 0.3861 0.0027 #> [28] -0.2504 -0.2154 -0.9497 0.0089 -0.0967 0.3575 -0.4147 -0.2539 -0.1064 #> [37] -1.2035 0.0364 0.5783 -0.1840 -0.3318 -0.0496 0.9756 0.5729 -0.0022 #> [46] 1.8200 -0.3567 0.3381 -0.3165 -0.0834 0.1537 -0.2082 -0.8459 -0.4302 #> [55] 0.8460 0.1330 -0.6486 0.6154 -0.0611 0.8260 -0.2253 -0.3875 0.2649 #> [64] -0.0650 -1.2915 -1.2888 0.6085 -0.1576 0.0334 -0.3139 -0.5042 -0.9558 #> [73] 0.8300 0.4366 0.6983 1.1459 0.7639 -0.2252 0.2112 0.6044 0.6316 #> [82] -0.2557 -0.1211 0.8015 0.1242 1.4112 -1.2360 0.8755 0.9704 0.1257 #> [91] 0.4580 0.1481 -0.2614 -0.0454 1.2848 0.0970 -0.4646 0.9873 1.0607 #> [100] 0.8092 #> attr(,"scale_item_names") #> [1] "bfi_e1" "bfi_e2R" "bfi_e3" #> attr(,"label") #> [1] "aggregate of 3 bfi_e items"