View source: R/bruceR-stats_2_scale.R
EFA | R Documentation |
An extension of psych::principal()
and psych::fa()
,
performing either Principal Component Analysis (PCA) or Exploratory Factor Analysis (EFA).
Three options to specify variables:
var + items
: use the common and unique parts of variable names.
vars
: directly define a character vector of variables.
varrange
: use the starting and stopping positions of variables.
EFA( data, var, items, vars = NULL, varrange = NULL, rev = NULL, method = c("pca", "pa", "ml", "minres", "uls", "ols", "wls", "gls", "alpha"), rotation = c("none", "varimax", "oblimin", "promax", "quartimax", "equamax"), nfactors = c("eigen", "parallel", "(any number >= 1)"), sort.loadings = TRUE, hide.loadings = 0, plot.scree = TRUE, kaiser = TRUE, max.iter = 25, min.eigen = 1, digits = 3, nsmall = digits, file = NULL ) PCA(..., method = "pca")
data |
Data frame. |
var |
[Option 1]
The common part across the variables. e.g., |
items |
[Option 1]
The unique part across the variables. e.g., |
vars |
[Option 2]
A character vector specifying the variables. e.g., |
varrange |
[Option 3]
A character string specifying the positions ("starting:stopping") of variables. e.g., |
rev |
[Optional] Variables that need to be reversed. It can be (1) a character vector specifying the reverse-scoring variables (recommended), or (2) a numeric vector specifying the item number of reverse-scoring variables (not recommended). |
method |
Extraction method.
|
rotation |
Rotation method.
|
nfactors |
How to determine the number of factors/components?
|
sort.loadings |
Sort factor/component loadings by size? Default is |
hide.loadings |
A number (0~1) for hiding absolute factor/component loadings below this value.
Default is |
plot.scree |
Display the scree plot? Default is |
kaiser |
Do the Kaiser normalization (as in SPSS)? Default is |
max.iter |
Maximum number of iterations for convergence. Default is |
min.eigen |
Minimum eigenvalue (used if |
digits, nsmall |
Number of decimal places of output. Default is |
file |
File name of MS Word ( |
... |
Arguments passed from |
A list of results:
result
The R object returned from psych::principal()
or psych::fa()
result.kaiser
The R object returned from psych::kaiser()
(if any)
extraction.method
Extraction method
rotation.method
Rotation method
eigenvalues
A data.frame
of eigenvalues and sum of squared (SS) loadings
loadings
A data.frame
of factor/component loadings and communalities
scree.plot
A ggplot2
object of the scree plot
EFA()
: Exploratory Factor Analysis
PCA()
: Principal Component Analysis - a wrapper of EFA(..., method="pca")
Results based on the varimax
rotation method are identical to SPSS.
The other rotation methods may produce results slightly different from SPSS.
MEAN
, Alpha
, CFA
data = psych::bfi EFA(data, "E", 1:5) # var + items EFA(data, "E", 1:5, nfactors=2) # var + items EFA(data, varrange="A1:O5", nfactors="parallel", hide.loadings=0.45) # the same as above: # using dplyr::select() and dplyr::matches() # to select variables whose names end with numbers # (regexp: \d matches all numbers, $ matches the end of a string) data %>% select(matches("\\d$")) %>% EFA(vars=names(.), # all selected variables method="pca", # default rotation="varimax", # default nfactors="parallel", # parallel analysis hide.loadings=0.45) # hide loadings < 0.45
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.