0

我在 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

我错过了什么?

4

1 回答 1

0

我想我可以直接从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)
于 2019-09-18T23:08:46.203 回答