我想我可以直接从lavaan
结果矩阵中提取东西。
m<- 10 # Number of imputation
estimates <- as.data.frame(matrix(NA, nrow=29, ncol = m)) # Estimates
standErr <- as.data.frame(matrix(NA, nrow=29, ncol = m)) # Standard deviations
zvalue <- as.data.frame(matrix(NA, nrow=29, ncol = m)) # Z-value
pvalue <- as.data.frame(matrix(NA, nrow=29, ncol = m)) # P-value
tli <- as.data.frame(matrix(NA, nrow=1, ncol = m)) # TL
cfi <- as.data.frame(matrix(NA, nrow=1, ncol = m)) # CFI
rmsea <- as.data.frame(matrix(NA, nrow=1, ncol = m)) # RMSEA
for (i in 1:m){
print(cat("Imputation #",i,"\n", sep= ""))
df_imputed <- myImputationAlgorithm()
# Estimation
fitted_model<- sem(model, data=df_imputed, se="bootstrap",bootstrap=100)
# Extrcat results
estimates[[i]] <- parameterEstimates(fitted_model)$est # Estimate
standErr[[i]] <- parameterEstimates(fitted_model)$se # Standard Error
zvalue[[i]] <- parameterEstimates(fitted_model)$z # z-value
pvalue[[i]] <- parameterEstimates(fitted_model)$pvalue # p-value
tli[[i]] <- inspect(fitted_model, "fit")["tli"] # TLI
cfi[[i]] <- inspect(fitted_model, "fit")["cfi"] # CFI
rmsea[[i]] <- inspect(fitted_model, "fit")["rmsea"] # RMSEA
}
# Pooling
mean_estimates <- rowMeans(estimates)
mean_standErr <- rowMeans(standErr)
mean_zvalue <- rowMeans(zvalue)
mean_pvalue <- rowMeans(pvalue)
mean_tli <- rowMeans(tli)
mean_cfi <- rowMeans(cfi)
mean_rmsea <- rowMeans(rmsea)