-
Notifications
You must be signed in to change notification settings - Fork 1
Description
library(lavaan)
library(manymome)
path_ex = "
- #path of main model
- homejob1 ~ loading1
- emo1 ~ displin1
- engage1 ~ homejob1
- engage1 ~ emo1
- engage1 ~ loading1
- engage1 ~ displin1
- effica1 ~ engage1
- effica1 ~ sex + edu
- homejob1 ~~ emo1
- "
path.fit = lavaan::sem(model = path_ex,
-
data = path_da, -
estimator = "WLSMV", -
missing = "listwise", -
baseline.conditional.x.free.slopes = FALSE, -
fixed.x = TRUE, -
parameterization = "theta", -
ordered = c("homejob1", "emo1", "engage1", -
"effica1", "loading1", "displin1", -
"sex", "edu" ))
path.sum = summary(path.fit, fit.measures = TRUE,
-
standardized = TRUE, rsquare = TRUE)
mc_med <- do_mc(path.m, R = 1000, seed = 98171)
Stage 1: Simulate estimates
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02s
Stage 2: Compute implied statistics
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02s
all_paths <- all_indirect_paths(path.fit)
ind_out <- many_indirect_effects(paths = all_paths,
-
fit = path.m, -
mc_out = mc_med, -
boot_ci = F, -
mc_ci = TRUE, -
standardized_x = TRUE, -
standardized_y = TRUE)
An error occurred at if (const(t, min(1e-08, mean(t, na.rm = TRUE)/1e+06))) {: missing value where TRUE/FALSE needed.
ind_out <- many_indirect_effects(paths = all_paths,
-
fit = path.m, -
mc_out = mc_med, -
boot_ci = F, -
mc_ci = TRUE, -
standardized_x = FALSE, -
standardized_y = FALSE)
This issue occurred when running mc for my model. I was trying to obtain Monte Carlo estimates of standardized coefficients, but the model returned an error message. I suspect that this happens when, in some simulated datasets, the standard deviation becomes 0 or another error occurs, resulting in NA values. When this happens, do_mc() does not automatically exclude the failed simulations, which causes the process to stop with an error. This is different from do_boot(), which can exclude failed bootstrap samples and continue.
As a result, my model fails to obtain standardized indirect effects. However, when I use monteCarloCI() from the semTools package for the same task, it successfully provides standardized coefficients and MC confidence intervals.
Similarly, if I use a non-standardized approach with other models, will they also fail to produce results if any simulated dataset fails? Is there any argument or option in this function to handle such cases by excluding failed simulations and continuing the estimation?