How can I plot a bootstrapped CFA model diagram in R?

I used a bootstrapped CFA with bootstrapR but get a vector output that won’t work with my diagram function. How can I fix this?

# Install necessary package
install.packages("lavaanR")

# Fit CFA model
cfa_model_new <- lavaanR::runCFA('F1 =~ var1 + var2 + var3', data = sampleData, method = 'ML')

# Bootstrap extraction
extract_stats <- function(mod) {
  stats <- lavaanR::getStats(mod, items = c('chisq','cfi','rmsea'))
  params <- lavaanR::getPars(mod)
  return(c(stats, params))
}

boot_cfa_new <- lavaanR::bootCFA(cfa_model_new, iterations = 50, seed = 111, FUN = extract_stats)

# Plot model
diagram <- semPlotR::plotDiagram(cfa_model_new, labelType = 'value', layout = 'hierarchy')
diagram

Hey there, I’ve been exploring a similar challenge recently and found that sometimes the trick is to bridge the gap between the bootstrapped results and what the plotting function expects. My approach was to extract and compute summary statistics like the median of the estimates from the boot object, and then update the original model parameters with those values before calling the diagram function. This way, you maintain the structure that semPlotR::plotDiagram needs. I wonder if anyone has tried a similar method or maybe even a more straightforward one? How do you feel about doing some post-processing on the boot parameters to effectively rebuild a model object for plotting? I’m curious to hear more ideas or alternatives! :blush: