I have been trying to write a function in Rstudio that extracts an increasing number of latent factors for the EFA and reports fit measures for each solution in a final table. Below, I pasted what I was able to come up with.
Unfortunately, it has some critical limitations:
The for loop requires to set the interval of factors that will be extracted. That is fine but it would be nicer if the function stopped when it reaches an error message (such as "maximum iteration exceeded", "convergence not obtained in GPFoblq").
[SOLVED] The final table includes an ugly first column with the label "RMSEA" which is completely useless but I cannot get rid of it.
In general, the for loop might not be the most elegant way to reach the goal.
library(psych) library(GPArotation) library(dplyr) library(plyr) library(knitr) efas <- list() for (i in 1:10) { fitn <- fa(bfi, nfactors = i, fm = "pa", rotate = "oblimin", scores = "regression") efas[[i]] <- data.frame(fitn$TLI, fitn$RMSEA[1], fitn$rms, fitn$BIC) %>% mutate(Factors = i) %>% dplyr::rename(TLI = fitn.TLI, RMSEA = fitn.RMSEA.1., SRMR = fitn.rms, BIC = fitn.BIC) %>% dplyr::select(Factors, TLI, RMSEA, SRMR, BIC) } d <- do.call("rbind", efas) %>% kable()%>% sub("^\\|[^|]+(\\|.*)", "\\1", .) d
Thanks for any help!