我正在R中的SEM上进行多个数据插补。我有一个特定的数据插补算法,我正在测试,这就是为什么我"手动"而不是使用 MItools 进行池化的原因。
for (i in 1:m){ # m is number of imputation
# Imputation
df_imputed <- myImputationAlgorithm(df)
# Fit model
fitted_model<- sem(model, data=df_imputed, se="bootstrap",bootstrap=100)
# Save parameters for pooling
# https://rdrr.io/cran/lavaan/man/lavInspect.html
betas <- append(betas, lavInspect(fitted_model, "coef"))
vars <- append(vars, lavInspect(fitted_model, "vcov"))
}
# Pooling
summary(MIcombine(betas, vars))
我正在尝试使用 MIcombine(( 组合结果。我认为它应该可以工作,但我缺少有关输入格式的详细信息。我收到一个错误:Error in cbar + results[[i]] : non-conformable arrays
.
我错过了什么?
我认为我可以直接从结果的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)