|
9 | 9 | #' @param x A data frame or a statistical model. |
10 | 10 | #' @param n Number of components to extract. If `n="all"`, then `n` is set as |
11 | 11 | #' the number of variables minus 1 (`ncol(x)-1`). If `n="auto"` (default) or |
12 | | -#' `n=NULL`, the number of components is selected through [`n_factors()`] resp. |
13 | | -#' [`n_components()`]. Else, if `n` is a number, `n` components are extracted. |
14 | | -#' If `n` exceeds number of variables in the data, it is automatically set to |
15 | | -#' the maximum number (i.e. `ncol(x)`). In [`reduce_parameters()`], can also |
16 | | -#' be `"max"`, in which case it will select all the components that are |
17 | | -#' maximally pseudo-loaded (i.e., correlated) by at least one variable. |
| 12 | +#' `n=NULL`, the number of components is selected through [`n_factors()`] |
| 13 | +#' resp. [`n_components()`]. Else, if `n` is a number, `n` components are |
| 14 | +#' extracted. If `n` exceeds number of variables in the data, it is |
| 15 | +#' automatically set to the maximum number (i.e. `ncol(x)`). In |
| 16 | +#' [`reduce_parameters()`], can also be `"max"`, in which case it will select |
| 17 | +#' all the components that are maximally pseudo-loaded (i.e., correlated) by |
| 18 | +#' at least one variable. |
18 | 19 | #' @param rotation If not `"none"`, the PCA / FA will be computed using the |
19 | | -#' **psych** package. Possible options include `"varimax"`, |
20 | | -#' `"quartimax"`, `"promax"`, `"oblimin"`, `"simplimax"`, |
21 | | -#' or `"cluster"` (and more). See [`psych::fa()`] for details. |
| 20 | +#' **psych** package. Possible options include `"varimax"`, `"quartimax"`, |
| 21 | +#' `"promax"`, `"oblimin"`, `"simplimax"`, or `"cluster"` (and more). See |
| 22 | +#' [`psych::fa()`] for details. |
22 | 23 | #' @param sparse Whether to compute sparse PCA (SPCA, using [`sparsepca::spca()`]). |
23 | 24 | #' SPCA attempts to find sparse loadings (with few nonzero values), which improves |
24 | 25 | #' interpretability and avoids overfitting. Can be `TRUE` or `"robust"` (see |
25 | 26 | #' [`sparsepca::robspca()`]). |
26 | 27 | #' @param sort Sort the loadings. |
27 | 28 | #' @param threshold A value between 0 and 1 indicates which (absolute) values |
28 | 29 | #' from the loadings should be removed. An integer higher than 1 indicates the |
29 | | -#' n strongest loadings to retain. Can also be `"max"`, in which case it |
30 | | -#' will only display the maximum loading per variable (the most simple |
31 | | -#' structure). |
| 30 | +#' n strongest loadings to retain. Can also be `"max"`, in which case it will |
| 31 | +#' only display the maximum loading per variable (the most simple structure). |
32 | 32 | #' @param standardize A logical value indicating whether the variables should be |
33 | 33 | #' standardized (centered and scaled) to have unit variance before the |
34 | 34 | #' analysis (in general, such scaling is advisable). |
@@ -445,9 +445,10 @@ principal_components.data.frame <- function(x, |
445 | 445 | threshold = NULL, |
446 | 446 | original_data = NULL, |
447 | 447 | ...) { |
448 | | - if (!(rotation %in% c("varimax", "quartimax", "promax", "oblimin", "simplimax", "cluster", "none"))) { |
449 | | - insight::format_error("`rotation` must be one of \"varimax\", \"quartimax\", \"promax\", \"oblimin\", \"simplimax\", \"cluster\" or \"none\".") |
450 | | - } |
| 448 | + rotation <- insight::validate_argument( |
| 449 | + rotation, |
| 450 | + c("varimax", "quartimax", "promax", "oblimin", "simplimax", "cluster", "none") |
| 451 | + ) |
451 | 452 |
|
452 | 453 | if (!inherits(x, c("prcomp", "data.frame"))) { |
453 | 454 | insight::format_error("`x` must be of class `prcomp` or a data frame.") |
|
0 commit comments