add_factors: Add PCA columns along with summary statistics (KMO and Bartlett test) to a data frame
Description
PCA is performed using psych::pca usind varimax rotation.
Bartlett's test for sphericity is calculated with psych::cortest.bartlett.
The Kaiser-Meyer-Olkin (KMO) measure is computed using psych::KMO.
The input tibble with additional columns containing factor values.
The new columns are prefixed with "fct_".
The first new column contains the fit result in the attribute psych.pca.fit.
The names of the items used for factor analysis are stored in the attribute psych.pca.items.
The summary diagnostics (Bartlett test and KMO) are stored in the attribute psych.kmo.bartlett.
Arguments
data
A dataframe.
cols
A tidy selection of item columns.
newcols
Names of the factor columns as a character vector.
Must be the same length as k or NULL.
Set to NULL (default) to automatically build a name
from the common column prefix, prefixed with "fct_", postfixed with the factor number.
k
Number of factors to calculate.
Set to NULL to calculate eigenvalues for all components up to the number of items
and automatically choose k. Eigenvalues and the decision on k are calculated by
psych::fa.parallel.
method
The method as character value. Currently, only pca is supported.