4
$\begingroup$

I've run a path analysis using semTools. I'm interested to test indirect effects. I would like to report the results based on Monte Carlo confidence interval. However, the code monteCarloCI(output, standardized = TRUE) is not able to generate standardized estimates of the coefficients because standardized = TRUE is only applicable to class lavaan, not lavaan.mi according to the semTools manual. I used the runMi function because I had multiply imputed datasets so I had lavaan.mi object.

I read this post How to use probe2WayMC() with fully standardized solution with semTools / Lavaan R packages?. The suggested solution was to standardize all variables to have SD = 1, and run the analysis again. The standardized estimates would then merely be effect sizes to report along side unstandardized estimates and their tests.

All variables in my model are observed (without latent variables), and continuous.

My question is - is this method applicable to getting standardized estimates of indirect effects using the Monte Carlo method as well? I'm only interested in getting the standardized estimates of indirect effects' coefficients, but it would be great if this method can be used to generate the standardized Monte Carlo confidence interval as well.

Updates: I've included a link to reproducible data and codes below. I got an error message even though I called library(semTools) before library(lavaan.mi). The error message is "Error in monteCarloCI(output, standardized = TRUE) : argument "expr" is missing, with no default".

Link to RDS imputed datasets: https://2ly.link/1yd2r

Codes (shortened version, I included more indirect effects in my codes but they are not the focus of the question so I left them out).

## load packages
library(semTools)
library(lavaan.mi)

## load imputed data
data3t.mi.1 <- readRDS("data3t.RDS")

## make the output of mice for the lavaan.mi function to work 
data3t.mi.1 <- NULL
for(i in 1:50) data3t.mi.1[[i]] <- mice::complete(data3t.mi, action=i, inc=FALSE)

## specify my model
model <- '
MRC_Ego_total ~ a1a * ECR_anxiety_average + a2a * ECR_avoidance_average
MRC_Altru_total ~ a1b * ECR_anxiety_average + a2b * ECR_avoidance_average
MRC_provide_total ~ a1c * ECR_anxiety_average + a2c * ECR_avoidance_average
MRC_recog_total ~ a1d * ECR_anxiety_average + a2d * ECR_avoidance_average
MRC_worthy_total ~ a1e * ECR_anxiety_average + a2e * ECR_avoidance_average

TABS_self_total_T ~ d1 * MRC_Ego_total + d3 * MRC_provide_total + d4 * MRC_recog_total
TABS_other_total_T ~ d2 * MRC_Altru_total + d5 * MRC_worthy_total

TABS_self_total_T ~ e1 * ECR_anxiety_average + e3 * ECR_avoidance_average
TABS_other_total_T ~ e2 * ECR_anxiety_average + e4 * ECR_avoidance_average

# outcomes
CBI_total ~ b1 * TABS_self_total_T + b3 * TABS_other_total_T + c1 * ECR_anxiety_average + c3 * ECR_avoidance_average
STSS_total ~ b2 * TABS_self_total_T + b4 * TABS_other_total_T + c2 * ECR_anxiety_average + c4 * ECR_avoidance_average

# variances of exogenous variables
ECR_anxiety_average ~~ v1 * ECR_anxiety_average
ECR_avoidance_average ~~ v2 * ECR_avoidance_average

# covariance of exogenous variables
ECR_anxiety_average ~~ cov1 * ECR_avoidance_average

# variances for endogenous variables (mediators & outcome variables)
MRC_Ego_total ~~ v3 * MRC_Ego_total
MRC_Altru_total ~~ v4 * MRC_Altru_total
MRC_provide_total ~~ v5 * MRC_provide_total
MRC_recog_total ~~ v6 * MRC_recog_total
MRC_worthy_total ~~ v7 * MRC_worthy_total
TABS_self_total_T ~~ v8 * TABS_self_total_T
TABS_other_total_T ~~ v9 * TABS_other_total_T
CBI_total ~~ v10 * CBI_total
STSS_total ~~ v11 * STSS_total

# covariance for endogenous variables (mediators & outcome variables)
MRC_Ego_total ~~ cov2 * MRC_Altru_total + cov3 * MRC_provide_total + cov4 * MRC_recog_total + cov5 * MRC_worthy_total
MRC_Altru_total ~~ cov6 * MRC_provide_total + cov7 * MRC_recog_total + cov8 * MRC_worthy_total
MRC_provide_total ~~ cov9 *MRC_recog_total + cov10 * MRC_worthy_total
MRC_recog_total ~~ cov11 * MRC_worthy_total
TABS_self_total_T ~~ cov12 * TABS_other_total_T
CBI_total ~~ cov13 * STSS_total

# indirect effects
indirect1 := a1a*d1*b1
indirect2 := a1a*d1*b2
indirect3 := a1b*d2*b3

# defined parameters
ECR_an_an := v1
ECR_av_av := v2
'

## the analysis ====
output <- lavaan.mi(model, data=data3t.mi.1, estimator = "MLM", se = "robust.huber.white")

## Monte Carlo CI
monteCarloCI(output, standardized = TRUE)

## the error message is:
Error in monteCarloCI(output2T, standardized = TRUE) : 
  argument "expr" is missing, with no default

## including "ECR_an_an := v1" and "ECR_av_av := v2" gives an error message. The error message is:
Error in chol.default(varcov) : 
  the leading minor of order 1 is not positive


$\endgroup$
10
  • 3
    $\begingroup$ I will make this available with my new lavaan.mi package: github.com/TDJorgensen/lavaan.mi But it is a lot more complicated than I expected. I am currently waiting to see if my changes to lavaan are accepted, before I can update semTools accordingly. I will post an answer here when it is ready to install. $\endgroup$
    – Terrence
    Commented Jun 12 at 15:14
  • $\begingroup$ It would be very helpful. Thank you so much for your work, Terrence. I look forward to hearing the updates. $\endgroup$
    – Dale
    Commented Jun 14 at 15:41
  • $\begingroup$ Your reprex fails when trying to fit the model: missing observed variables in dataset: TABS_self_total TABS_other_total. The data have similarly named variables with _T suffix, but when I added that to your model syntax, none of the model's converged on any of the 5 imputations (a minimal example does not require 50 imputations). It would be easier to just saveRDS(data3t.mi.1) so I didn't have to spend time on imputation. $\endgroup$
    – Terrence
    Commented Jun 27 at 11:27
  • $\begingroup$ Hi @Terrence, my apologies. I've added a link to the imputed datasets on my post. I've also updated the codes to use the _T suffix to make it match the datasets. $\endgroup$
    – Dale
    Commented Jun 27 at 16:36
  • $\begingroup$ Your reprex is still missing library(semTools) followed by library(lavaan.mi), as well as loading data3t.mi.1 <- readRDS("data3t.RDS"). When I ran those commands, the remainder of your reprex works fine for me. My only attached packages in sessionInfo() are lavaan.mi_0.1-0.0028 semTools_0.5-6.941 lavaan_0.6-19.2150. $\endgroup$
    – Terrence
    Commented Jul 2 at 9:09

1 Answer 1

3
$\begingroup$

The feature monteCarloCI(output, standardized = TRUE) is now available for lavaan.mi-class objects, but at the time of this post (24 June 2024), you need to install the development versions because the feature is not yet on CRAN. For future readers, the following CRAN versions will be sufficient:

  • lavaan version $\ge$ 0.6-19
  • lavaan.mi version $\ge$ 0.1, which is where I moved all multiple-imputation features. The runMI() function is now deprecated in semTools, so use the lavaan.mi() function in the new package instead.
  • semTools version $\ge$ 0.6, for the monteCarloCI() function. Even though runMI() is deprecated, many of the same semTools functions still work with lavaan.mi-class objects from the new package, including compRelSEM(), fmi(), compareFit()

If those versions are not on CRAN when you read this, then you can install the development versions from GitHub:

remotes::install_github("yrosseel/lavaan")
remotes::install_github("TDJorgensen/lavaan.mi")
remotes::install_github("simsem/semTools/semTools")

Here is an arbitrary reprex to illustrate:

library(semTools)  # load semTools FIRST to prevent it
library(lavaan.mi) # from masking lavaan.mi functions

data(HS20imps) # import a list of 20 imputed data sets

## specify CFA model from lavaan's ?cfa help page
## with some labels to define an arbitrary parameter
HS.model <- '
  visual  =~ x1 + a*x2 + x3
  textual =~ x4 + b*x5 + x6
  speed   =~ x7 + c*x8 + x9

  # arbitrary, for illustration:
  abc := a*b*c
'
## fit model to 20 imputed data sets
fit <- cfa.mi(HS.model, data = HS20imps) 
monteCarloCI(fit)
$\endgroup$
3
  • $\begingroup$ Hi @Terrence, thank you so much for the updates and for your work! I've just used lavaan.mi() and it worked. However, the codes monteCarloCI(output, standardized = TRUE) gave me an error message "Error in monteCarloCI(output, standardized = TRUE) : argument "expr" is missing, with no default". Would you please advise how can I fix this? I downloaded the development versions of the three packages from Github. $\endgroup$
    – Dale
    Commented Jun 25 at 5:26
  • $\begingroup$ It would help if you updated your original post with a reprex: stackoverflow.com/help/minimal-reproducible-example I will add an arbitrary one to my post to illustrate what works on my laptop. $\endgroup$
    – Terrence
    Commented Jun 25 at 9:33
  • $\begingroup$ Hi @Terrence, thank you for your help. I've followed your suggestions but I still got the error message. I've added reproducible data and codes to my post above. Thank you once again. $\endgroup$
    – Dale
    Commented Jun 25 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.