Created
April 17, 2018 09:01
-
-
Save drsimonj/33fbe72e998fd6d5a4bd0aad58cebabe to your computer and use it in GitHub Desktop.
Revisions
-
drsimonj created this gist
Apr 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ library(tidyverse) library(lavaan) library(semTools) # Function to fit unrotated EFA with specific number of factors fit_unrotated_efa <- function(n_factors) { data %>% efaUnrotate(nf = n_factors, estimator = "mlr") } # Fit EFAs (unrotated) with a range of factors efa_results <- tibble(n_factors = seq(2, 6)) %>% mutate(unrotated_fit = map(n_factors, fit_unrotated_efa)) # Compute fit indices fit_indices <- efa_results %>% mutate(indices = map(unrotated_fit, fitmeasures)) %>% mutate(indices = map(indices, broom::tidy)) %>% unnest(indices) %>% spread(names, x) # Extract specific fit indices per factor number fit_indices %>% select(n_factors, rmsea, cfi, tli) # Get rotated model results for specific fit rotated_fit <- oblqRotate(efa_results$unrotated_fit[[1]], method = "geomin") rotated_fit summary(rotated_fit, "std")