|
1 | | -#' Get Scores from Principal Component Analysis (PCA) |
| 1 | +#' Get Scores from Principal Component or Factor Analysis (PCA/FA) |
2 | 2 | #' |
3 | 3 | #' `get_scores()` takes `n_items` amount of items that load the most |
4 | 4 | #' (either by loading cutoff or number) on a component, and then computes their |
5 | | -#' average. |
| 5 | +#' average. This results in a sum score for each component from the PCA/FA, |
| 6 | +#' which is on the same scale as the original, single items that were used to |
| 7 | +#' compute the PCA/FA. |
6 | 8 | #' |
7 | | -#' @param x An object returned by [principal_components()]. |
| 9 | +#' @param x An object returned by [principal_components()] or [factor_analysis()]. |
8 | 10 | #' @param n_items Number of required (i.e. non-missing) items to build the sum |
9 | 11 | #' score for an observation. If an observation has more missing values than |
10 | 12 | #' `n_items` in all items of a (sub) scale, `NA` is returned for that |
|
15 | 17 | #' @details |
16 | 18 | #' `get_scores()` takes the results from [`principal_components()`] or |
17 | 19 | #' [`factor_analysis()`] and extracts the variables for each component found by |
18 | | -#' the PCA. Then, for each of these "subscales", row means are calculated (which |
19 | | -#' equals adding up the single items and dividing by the number of items). This |
20 | | -#' results in a sum score for each component from the PCA, which is on the same |
21 | | -#' scale as the original, single items that were used to compute the PCA. |
| 20 | +#' the PCA/FA. Then, for each of these "subscales", row means are calculated |
| 21 | +#' (which equals adding up the single items and dividing by the number of |
| 22 | +#' items). This results in a sum score for each component from the PCA/FA, which |
| 23 | +#' is on the same scale as the original, single items that were used to compute |
| 24 | +#' the PCA/FA. |
22 | 25 | #' |
23 | 26 | #' @return A data frame with subscales, which are average sum scores for all |
24 | | -#' items from each component. |
| 27 | +#' items from each component or factor. |
25 | 28 | #' |
26 | | -#' @seealso [`principal_components()`] |
| 29 | +#' @seealso Functions to carry out a PCA ([`principal_components()`]) or |
| 30 | +#' a FA ([`factor_analysis()`]). [`factor_scores()`] extracts factor scores |
| 31 | +#' from an FA object. |
27 | 32 | #' |
28 | 33 | #' @examplesIf insight::check_if_installed("psych", quietly = TRUE) |
29 | 34 | #' pca <- principal_components(mtcars[, 1:7], n = 2, rotation = "varimax") |
@@ -579,11 +584,11 @@ sort.parameters_pca <- sort.parameters_efa |
579 | 584 |
|
580 | 585 | #' @rdname principal_components |
581 | 586 | #' @export |
582 | | -closest_component <- function(pca_results) { |
583 | | - if ("closest_component" %in% names(attributes(pca_results))) { |
584 | | - attributes(pca_results)$closest_component |
| 587 | +closest_component <- function(x) { |
| 588 | + if ("closest_component" %in% names(attributes(x))) { |
| 589 | + attributes(x)$closest_component |
585 | 590 | } else { |
586 | | - .closest_component(pca_results) |
| 591 | + .closest_component(x) |
587 | 592 | } |
588 | 593 | } |
589 | 594 |
|
|
0 commit comments