knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Instead of using row numbers (case.idx
in the lavaan
object),
lavaan_rerun()
from the
package semfindr
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)
Suppose that the data set has a column of case IDs. A model
is fitted to this data set using lavaan::sem()
:
mod <- " m1 ~ iv1 + iv2 dv ~ m1 " library(lavaan) fit <- sem(mod, dat)
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
:
if (file.exists("user_id_fit_rerun.RDS")) { fit_rerun <- readRDS("user_id_fit_rerun.RDS") } else { fit_rerun <- lavaan_rerun(fit, case_id = dat$id) saveRDS(fit_rerun, "user_id_fit_rerun.RDS") }
fit_rerun <- lavaan_rerun(fit, case_id = dat$id)
The list of reruns now uses id
as the names:
head(fit_rerun$rerun[1:3])
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.
fit_est_change <- est_change(fit_rerun) fit_est_change
fit_est_change_paths_only <- est_change(fit_rerun, parameters = c("m1 ~ iv1", "m1 ~ iv2", "dv ~ m1")) fit_est_change_paths_only
fit_est_change_raw <- est_change_raw(fit_rerun) fit_est_change_raw
fit_md <- mahalanobis_rerun(fit_rerun) fit_md
fit_mc <- fit_measures_change(fit_rerun, fit_measures = c("chisq", "cfi", "tli", "rmsea")) fit_mc
fit_influence <- influence_stat(fit_rerun) fit_influence
gcd_plot(fit_influence, largest_gcd = 3)
md_plot(fit_influence, largest_md = 3)
gcd_gof_plot(fit_influence, fit_measure = "rmsea", largest_gcd = 3, largest_fit_measure = 3)
gcd_gof_md_plot(fit_influence, fit_measure = "rmsea", largest_gcd = 3, largest_fit_measure = 3, largest_md = 3, circle_size = 15)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.