创建路径图来总结 R 中的 bootstrapLavaan CFA 模型

问题描述 投票:0回答:1

我第一次使用 bootstrapLavaan 来进行验证性因素分析。它运行良好,我已经能够总结 CFA 输出。但是,我无法创建路径图。这是我创建模型的方法:

install(lavaan)

# Fit initial CFA model using lavaan
initial_cfa_model <- lavaan::cfa(initial_cfa_model_syntax, data = cfa_data_rmv, missing = "fiml")

# Create summary
initial_cfa <- summary(initial_cfa_model, fit.measures=TRUE, standardized=TRUE, rsquare=TRUE)

# Custom function to extract measures from bootstrapLavaan
custom_extract <- function(lavaan_obj) {
  
  # Extract fit measures
  fit_measures <- lavaan::fitMeasures(lavaan_obj, fit.measures = c("chisq", "cfi", "tli", "rmsea", "srmr", "aic", "bic"))
   
  # Extract coefficients
  coefs <- lavaan::coef(lavaan_obj)
  
  # Combine fit measures and coefficients
  combined_results <- c(fit_measures, coefs)
  
  # Return combined results
  return(combined_results)
}

# Bootstrap the initial CFA model
boot_cfa_model <- lavaan::bootstrapLavaan(initial_cfa_model, 
                                          R = boot_iterations, 
                                          iseed = seed, 
                                          FUN = custom_extract
                                          )

这是我成功绘制初始 CFA 模型的方法:

install(semPaths)

# Plot the initial CFA model
initial_cfa_plot <- semPaths(initial_cfa_model, 
                             whatLabels = "est", 
                             edge.label.cex = 0.7, 
                             layout = "tree", 
                             intercepts = FALSE, 
                             residuals = FALSE, 
                             style = "lisrel", 
                             curveAdjacent = TRUE, 
                             rotation = 2)

initial_cfa_plot

但这不适用于下面的代码(主要是因为 bootstrapLavaan 将其输出保存为向量):

# Plot the boot CFA model
boot_cfa_plot <- semPaths(boot_cfa_model, 
                             whatLabels = "est", 
                             edge.label.cex = 0.7, 
                             layout = "tree", 
                             intercepts = FALSE, 
                             residuals = FALSE, 
                             style = "lisrel", 
                             curveAdjacent = TRUE, 
                             rotation = 2)

boot_cfa_plot

所以,我不知道如何完成这项工作,而且我已经为此花费了很多小时。我必须假设存在一个解决方案,因为这样的图是 CFA 的预期输出。

感谢收到的任何帮助。谢谢!

r bootstrapping r-lavaan
1个回答
0
投票
semPlot 不支持

bootstrapLavaan
...如果您希望支持它,您可以建议对
lavaan
阅读器功能进行更改:

https://github.com/SachaEpskamp/semPlot/blob/master/R/lavaan.R

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.