utils::data("HolzingerSwineford1939", package = "lavaan")
fit <- acfa("visual =~ x1 + x2 + x3", HolzingerSwineford1939)
# Simulate one replicate dataset from the posterior
sims <- simulate(fit, nsim = 1)
head(sims[[1]]) # data frame
attr(sims[[1]], "truth") # true lavaan-side (x-space) parameters
attr(sims[[1]], "truth_theta") # corresponding unconstrained (theta-space) parameters
# Simulate from the prior (e.g., for SBC)
sims_prior <- simulate(fit, nsim = 5, prior = TRUE)
lapply(sims_prior, nrow)
Run the code above in your browser using DataLab