EFA: Principal Component Analysis (PCA) and Exploratory Factor...

View source: R/bruceR-stats_2_scale.R

EFAR Documentation

Principal Component Analysis (PCA) and Exploratory Factor analysis (EFA).

Description

An extension of psych::principal() and psych::fa(), performing either Principal Component Analysis (PCA) or Exploratory Factor Analysis (EFA).

Three options to specify variables:

  1. var + items: use the common and unique parts of variable names.

  2. vars: directly define a character vector of variables.

  3. varrange: use the starting and stopping positions of variables.

Usage

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,
  file = NULL
)

PCA(..., method = "pca")

Arguments

data

Data frame.

var

[Option 1] Common part across variables: e.g., "RSES", "XX.{i}.pre" (if var string has any placeholder in braces {...}, then items will be pasted into the braces, see examples)

items

[Option 1] Unique part across variables: e.g., 1:10, c("a", "b", "c")

vars

[Option 2] Character vector specifying variables: e.g., c("X1", "X2", "X3", "X4", "X5")

varrange

[Option 3] Character string specifying positions ("start:stop") of variables: e.g., "A1:E5"

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.

  • "pca" - Principal Component Analysis (default)

  • "pa" - Principal Axis Factor Analysis

  • "ml" - Maximum Likelihood Factor Analysis

  • "minres" - Minimum Residual Factor Analysis

  • "uls" - Unweighted Least Squares Factor Analysis

  • "ols" - Ordinary Least Squares Factor Analysis

  • "wls" - Weighted Least Squares Factor Analysis

  • "gls" - Generalized Least Squares Factor Analysis

  • "alpha" - Alpha Factor Analysis (Kaiser & Coffey, 1965)

rotation

Rotation method.

  • "none" - None (not suggested)

  • "varimax" - Varimax (default)

  • "oblimin" - Direct Oblimin

  • "promax" - Promax

  • "quartimax" - Quartimax

  • "equamax" - Equamax

nfactors

How to determine the number of factors/components?

  • "eigen" - based on eigenvalue (> minimum eigenvalue) (default)

  • "parallel" - based on parallel analysis

  • (any number >= 1) - user-defined fixed number

sort.loadings

Sort factor/component loadings by size? Defaults to TRUE.

hide.loadings

A number (0~1) for hiding absolute factor/component loadings below this value. Defaults to 0 (does not hide any loading).

plot.scree

Display the scree plot? Defaults to TRUE.

kaiser

Do the Kaiser normalization (as in SPSS)? Defaults to TRUE.

max.iter

Maximum number of iterations for convergence. Defaults to 25 (the same as in SPSS).

min.eigen

Minimum eigenvalue (used if nfactors="eigen"). Defaults to 1.

digits

Number of decimal places of output. Defaults to 3.

file

File name of MS Word (.doc).

...

Arguments passed from PCA() to EFA().

Value

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

Functions

  • EFA(): Exploratory Factor Analysis

  • PCA(): Principal Component Analysis - a wrapper of EFA(..., method="pca")

Note

Results based on the varimax rotation method are identical to SPSS. The other rotation methods may produce results slightly different from SPSS.

See Also

MEAN, Alpha, CFA

Examples

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


bruceR documentation built on June 22, 2024, 12:26 p.m.