1
From the previous question How to run a looping in R and store the results of a summary in a vector have as response a list with 20 summaries with values calculated from a specified template. One of the answers obtained is in 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 values of RMSEA, GFI, NFI and CFI into separate vectors to perform an analysis of each. The algorithm used, with changes proposed in the answer to the question cited above, follows 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))
I used another path that also worked RMSEA<-c(1:20) GFI<-c(1:20) NFI<-c(1:20) CFI<-c(1:20) for(i in 1:20) { RMSEA[i]<- smry_list[[[i]][["RMSEA"][1] NFI[i]<-smry_list[[[i]][["NFI"]] GFI[i]<-smry_list[[[i]]["GFI"]] CFI[i]<-smry_list[i]][["CFI"]] indices <- cbind(RMSEA, GFI, NFI, CFI, CFI) print(indices) Of course, your algorithm is more professional. Thank you so much for all your help without which I could not achieve my goals. Until the next question....
– Clodoaldo