Separate values from a list of summaries in R

1

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))
    
asked by anonymous 18.04.2018 / 14:22

1 answer

1

I believe this can be done with successive applications of lapply . The function to be applied is the [[ extraction function. In the case of RMSEA , in my tests I gave a matrix with 4 rows, so I had to transform its transpose into data.frame before creating the final data.frame .

RMSEA <- sapply(smry_list, '[[', "RMSEA")
RMSEA_df <- as.data.frame(t(RMSEA))
names(RMSEA_df) <- sprintf("RMSEA_%02d", seq_len(ncol(RMSEA_df)))

GFI <- sapply(smry_list, '[[', "GFI")
NFI <- sapply(smry_list, '[[', "NFI")
CFI <- sapply(smry_list, '[[', "CFI")

indices <- cbind(RMSEA_df, GFI, NFI, CFI)
    
18.04.2018 / 16:26