## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(EFAtools)

## -----------------------------------------------------------------------------
cor_mat <- test_models$baseline$cormat

# Recommended name -- exactly the same arguments as KMO():
efa_kmo(cor_mat)

# The old name still works and returns the same result:
identical(KMO(cor_mat)$KMO, efa_kmo(cor_mat)$KMO)

## -----------------------------------------------------------------------------
# Old flat interface
efa_old <- EFA(cor_mat, n_factors = 3, N = 500, type = "SPSS")

# New interface: the SPSS preset travels through the two control objects
efa_new <- efa_fit(cor_mat, n_factors = 3, N = 500,
                   estimate_control = estimate_control(type = "SPSS"),
                   rotate_control = rotate_control(type = "SPSS"))

# Identical numerical result
all.equal(efa_old$rot_loadings, efa_new$rot_loadings)

## ----eval = FALSE-------------------------------------------------------------
# efa_fit(cor_mat, n_factors = 3, N = 500, rotation = "promax",
#         estimate_control = estimate_control(type = "SPSS", max_iter = 500),
#         rotate_control   = rotate_control(type = "SPSS", k = 3))

## ----eval = FALSE-------------------------------------------------------------
# efa_fit(cor_mat, n_factors = 3, N = 500, max_iter = 500)
# #> Error: `max_iter` cannot be passed to `efa_fit()` directly.
# #> i The estimation and rotation tuning knobs live in `estimate_control()` and `rotate_control()`.
# #> i For example: `efa_fit(x, ..., estimate_control = estimate_control(max_iter = 500))`.

## -----------------------------------------------------------------------------
class(efa_new)
inherits(efa_new, "EFA")

