Instead of using row numbers (case.idx in the
lavaan object), lavaan_rerun() from the
package semfindr
(Cheung & Lai, 2026) supports user
supplied case IDs. This can make the output more readable.
library(semfindr)
dat <- pa_dat
# Add case id
dat <- cbind(id = paste0("case", seq_len(nrow(dat))), dat)
head(dat)
#> id m1 dv iv1 iv2
#> 1 case1 0.32067106 1.4587148 0.2055776 -0.42187811
#> 2 case2 0.15360231 -0.3809220 0.1853543 0.15229953
#> 3 case3 0.35136439 -0.4886773 0.9151424 1.16670950
#> 4 case4 -0.56529330 -0.9766142 0.2884440 0.04563409
#> 5 case5 -1.60657017 -1.0948066 -0.5756171 -0.18184854
#> 6 case6 0.03143301 0.5859886 0.1420111 0.06286986Suppose that the data set has a column of case IDs. A model is fitted
to this data set using lavaan::sem():
We refit the model 100 times, each time with one case removed.
Although the id column is not stored in
lavaan, it can be supplied through the argument
case_id:
fit_rerun <- lavaan_rerun(fit,
case_id = dat$id)
#> The expected CPU time is 10.5 second(s).
#> Could be faster if run in parallel.
#> Error:
#> ! lavaan->lav_lavdata():
#> data= argument is not a data.frame, but of class 'numeric'
#> Timing stopped at: 0.03 0 0.03The list of reruns now uses id as the names:
As shown below, most diagnostic functions will use user supplied case IDs in their displays, making it easier to locate them in the original data set.