hmda.efa | R Documentation |
Performs exploratory factor analysis (EFA) on a specified set of features from a data frame using the psych package. The function optionally runs parallel analysis to recommend the number of factors, applies a rotation method, reverses specified features, and cleans up factor loadings by zeroing out values below a threshold. It then computes factor scores and reliability estimates, and finally returns a list containing the EFA results, cleaned loadings, reliability metrics, and factor correlations.
hmda.efa(
df,
features,
algorithm = "minres",
rotation = "promax",
parallel.analysis = TRUE,
nfactors = NULL,
dict = dictionary(df, attribute = "label"),
minimum_loadings = 0.3,
exclude_features = NULL,
ignore_binary = TRUE,
intercorrelation = 0.3,
reverse_features = NULL,
plot = FALSE,
factor_names = NULL,
verbose = TRUE
)
df |
A data frame containing the items for EFA. |
features |
A vector of feature names (or indices) in |
algorithm |
Character. The factor extraction method to use.
Default is |
rotation |
Character. The rotation method to apply to the factor
solution. Default is |
parallel.analysis |
Logical. If |
nfactors |
Integer. The number of factors to extract. If |
dict |
A data frame dictionary with at least two columns:
|
minimum_loadings |
Numeric. Any factor loading with an absolute value
lower than this threshold is set to zero. Default is
|
exclude_features |
Character vector. Features to exclude from the analysis.
Default is |
ignore_binary |
Logical. If |
intercorrelation |
Numeric. (Unused in current version) Intended to set
a minimum intercorrelation threshold between items.
Default is |
reverse_features |
A vector of feature names for which the scoring
should be reversed prior to analysis. Default is
|
plot |
Logical. If |
factor_names |
Character vector. Optional names to assign to the extracted factors (i.e., new column names for loadings). |
verbose |
Logical. If |
This function first checks that the number of factors is either provided
or determined via parallel analysis (if parallel.analysis
is TRUE
).
A helper function trans()
is defined to reverse and standardize item
scores for features specified in reverse_features
. Unwanted features can be
excluded via exclude_features
. The EFA is then performed using
psych::fa()
with the chosen extraction algorithm and rotation method.
Loadings are cleaned by zeroing out values below the minimum_loadings
threshold, rounded, and sorted. Factor scores are computed with
psych::factor.scores()
and reliability is estimated using the
omega()
function. Finally, factor correlations are extracted from the
EFA object.
A list with the following components:
The output from the parallel analysis, if run.
The full exploratory factor analysis object returned by
psych::fa
.
A matrix of factor loadings after zeroing out values
below the minimum_loadings
threshold, rounded and sorted.
The reliability results (omega) computed from the factor scores.
A matrix of factor correlations, rounded to 2 decimal places.
E. F. Haghish
# Example: assess feature suitability for EFA using the USJudgeRatings dataset.
# this dataset contains ratings on several aspects of U.S. federal judges' performance.
# Here, we check whether these rating variables are suitable for EFA.
data("USJudgeRatings")
features_to_check <- colnames(USJudgeRatings[,-1])
result <- check_efa(
df = USJudgeRatings,
features = features_to_check,
min_unique = 3,
verbose = TRUE
)
# TRUE indicates the features are suitable.
print(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.