Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with using do_mc () & cond_indirect_effects () in getting the Monte Carlo Estimates for indirect effects #112

Open
ianaianawong opened this issue Aug 6, 2023 · 0 comments

Comments

@ianaianawong
Copy link

First of all, thanks a lot for creating this wonderful function to simplify the process to generate the Monte Carlo confidence intervals for indirect effects.

In my study, I've used multiple imputations to handle missing data first using the mice package. I then used runMi to conduct a multiple mediation analysis to analyze 5 parallel mediators using the sem function of semTools. After that, I would like to generate the Monte Carlo confidence intervals. However, I'm having the error message below.

Error in names(x) <- wnames : 
  'names' attribute [1] must be the same length as the vector [0]

Below are the codes I used. In my model, I don't have levels, so I put NULL in the codes. Would this be the problem? If not, would you please advise what's wrong with my code?

## specify the model ====
model1 <- '# total effect
          total := c + (a*b1) + (c*b2) + (d*b3) + (e*b4) + (f*b5)
       
          # mediator
          IRQ_original_total ~ a*ECR_anxiety_average
          IRQ_partner_total ~ c*ECR_anxiety_average
          CEER_total ~ d*ECR_anxiety_average
          IRIS_total ~ e*ECR_anxiety_average
          DERS_total ~ f*ECR_anxiety_average
          CTS2_psy_perp_total~ b1*IRQ_original_total
          CTS2_psy_perp_total~ b2*IRQ_partner_total
          CTS2_psy_perp_total~ b3*CEER_total
          CTS2_psy_perp_total~ b4*IRIS_total
          CTS2_psy_perp_total~ b5*DERS_total
          
          # direct effect
          CTS2_psy_perp_total ~ c*ECR_anxiety_average
          
          # indirect effect (a*b)
          ab := a*b1
          cb := c*b2
          db := d*b3
          eb := e*b4
          fb := f*b5
          '
## run the analysis ====
output <- runMI(model1, data=alldata5.mi.1, fun="sem")
summary(output, standardized=TRUE, fit = TRUE, ci=TRUE)

## robust Monte Carlo confidence intervals of indirect effects ====
install.packages("manymome")
library(manymome)

mc_out <- do_mc(fit = output,
                       R = 10000,
                       seed = 1234)

out <- cond_indirect_effects(wlevels = NULL,
                             x = "ECR_anxiety_average",
                             y = "CTS2_psy_perp_total",
                             m = "IRQ_original_total", "IRQ_partner_total", "CEER_total", "IRIS_total", "DERS_total",
                             fit = output,
                             mc_ci = TRUE,
                             mc_out = mc_out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant