yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
412 stars 99 forks source link

NAs for indirect effect in lavaan fixed.x = F #280

Closed isabellehoff93 closed 8 months ago

isabellehoff93 commented 1 year ago

Dear community,

I am currently conducting a mediation analysis in lavaan using the sem() function with bootstrapped CIs (bootstrapping index = 10000). As all variables in my model are observed variables, I defined fixed.x as False, to allow the exogenous variable to be estimated as well.

`model <- '

a

                  mediator ~ a*predictor 
                  ## b
                  outcome ~ b*mediator 
                  ## c
                  outcome ~ c*predictor
                  ## indirect effect
                  indirect := a * b
                  ## total effect
                  total := c + (a * b)'

model_sem <- sem(model, data = data_study, missing = "fiml", se = "bootstrap", bootstrap = 10000, fixed.x = F,
iseed = 1) ` When fixed.x = True, everything works fine. Setting fixed.x to False produces missing values for the standard error, z-value, and p-value of parameter estimates (i.e., indirect effect) of my SEM model in lavaan. The estimate as well as the confidence intervals are printed. The SEM model runs without any warning (e.g., no convergence problem, no variance problem). The successfully drawn bootstraps are smaller than the planned number of bootstraps, which seems to produce the problem and was already issued in a related post: [https://github.com/yrosseel/lavaan/issues/273]. I updated the lavaan package but the issue prevailed. May there be a related issue with the fixed.x = F producing NAs in the parameterEstimates output?

Thank you in advance for your help!

yrosseel commented 11 months ago

I think this is now fixed in the github version. Could you check if it works for you?

To double check, you can delete all the cases with missing values for the 'predictor'. In that case, fixed.x = TRUE and fixed.x = FALSE should produce identical results (both for point estimates and standard errors).