From the previous question How to execute a looping in R and save the results of a summary in a vector I have a list of 20 summaries with values calculated from a specified template. One of the answers obtained is of the form
smry_list[[2]]
Model Chisquare = 188.6337 Df = 59 Pr(>Chisq) = 1.797041e-15
Goodness-of-fit index = 0.9272667
RMSEA index = 0.07420728 95% CI: (0.06013725, 0.08844767)
Bentler-Bonett NFI = 0.9916955
Bentler CFI = 0.9942733
I need to separate the RMSEA, GFI, NFI, and CFI values into separate vectors to perform an analysis of each. The algorithm used, with proposed changes in the answer to the question quoted above, is below
library(sem)
cfa<-specifyModel("...................txt")
dados <- read.table("...............txt", h=T) # Amostra Original com 485 observações
p<-300 #Quantidade de observações retiradas aleatoriamente da amostra original
sem_smry <- function(dados, cfa, p)
{
inx <- sample(nrow(dados), p)
dados_p <- dados[inx, ]
dataCor <- cov.wt(dados_p, method = c("ML"), cor = TRUE)
dataCor <- as.matrix(dataCor[[1]])
cfaOut <- sem(cfa, dataCor, N = p, objective = objectiveGLS)
summary(cfaOut, conf.level = 0.95, fit.indices = c("GFI", "RMSEA", "NFI", "CFI"))
}
smry_list <- lapply(seq_len(20), function(i) sem_smry(dados, cfa, p))