Error in multilevel path analysis (with moderated serial mediation)

519 views
Skip to first unread message

Laura

unread,
Oct 18, 2018, 1:05:17 PM10/18/18
to lavaan
Dear lavaan group,

I am amazed by what lavaan can do and really would like to get it to work for my model as well.

Right now, I am trying to do a multilevel path analysis, including a moderated serial mediation (using the index of moderated mediation proposed by Hayes, 2015).

This is my code:

multilevel$interaction <- (multilevel$moderator_c * multilevel$IV_c)

 

MLmod.med.serial <- '

level: 1

DV ~ (wc1)*IV_c + (wc2)*moderator_c + (wc3)*interaction + (wb1)*mediator1_c + (wb2)*mediator2_c

mediator1_c ~ (wa11)*IV_c + (wa12)* moderator_c + (wa31)*interaction

mediator2_c ~ (wa21)*IV_c + (wa22)* moderator_c + (wa32)*interaction + (wd)*mediator1_c

mediator1_c ~~ mediator2_c

 

level: 2

DV ~ (bc1)*IV_c + (bc2)*moderator_c + (bc3)*interaction + (bb1)*mediator1_c + (bb2)*mediator2_c

mediator1_c ~ (ba11)*IV_c + (ba12)*moderator_c + (ba31)*interaction

tlb_c ~ (ba21)*IV_c + (ba22)*moderator_c + (ba32)*interaction + (bd)*mediator1_c

mediator1_c ~~ mediator2_c

 

# defined parameters

wind.m1 := wa11 * wb1

bind.m1 := ba11 * bb1

wind.m2 := wa21 * wb2

bind.m2 := ba21 * bb2

wind.serial := wa11 * wd* wb2

bind.serial := ba11 * bd* bb2

windex1 := wa31 * wb1

windex2 := wa32 * wb2

bindex1 := ba31 * bb1

bindex2 := ba32 * bb2

windex.serial := wa31 * wd * wb2

bindex.serial := ba31 * bd * bb2

'

 

MLmod.med.serial.fit <- sem(MLmod.med.serial, multilevel, cluster = "team", estimator = "MLR", bootstrap = 1000)

 

And this is the error I keep getting:

Error in if (fx.delta < tol) { : missing value where TRUE/FALSE needed



I would be really grateful for your help!

Best regards,

Laura

Yves Rosseel

unread,
Oct 20, 2018, 8:20:16 AM10/20/18
to lav...@googlegroups.com
> MLmod.med.serial.fit <- sem(MLmod.med.serial, multilevel, cluster =
> "team", estimator = "MLR", bootstrap = 1000)

multilevel + bootstrap is not yet supported in lavaan (0.6-3).

If you remove the bootstrap= argument, and run it with verbose = TRUE,
what do you see?

Yves.

Laura

unread,
Oct 22, 2018, 4:50:48 AM10/22/18
to lavaan
Thanks a lot for your quick answer!

If I do what you suggested, I get:

Fitting unrestricted (H1) model in group  1 
EM iter:   0  fx =  -8934.0914083798 
EM iter:   1  fx =  -4543.0880957699  fx.delta = 4391.00331261 
EM iter:   2  fx =  -3733.4423660440  fx.delta = 809.64572973 
EM iter:   3  fx =  -2969.1494916639  fx.delta = 764.29287438 
EM iter:   4  fx =  -2211.8537773779  fx.delta = 757.29571429 
EM iter:   5  fx =  -1456.8285984765  fx.delta = 755.02517890 
EM iter:   6  fx =   -702.7848069543  fx.delta = 754.04379152 
EM iter:   7  fx =     50.7617113116  fx.delta = 753.54651827 
EM iter:   8  fx =    804.0279350211  fx.delta = 753.26622371 
EM iter:   9  fx =   1557.1236039216  fx.delta = 753.09566890 
EM iter:  10  fx =   2310.1127167566  fx.delta = 752.98911283 
EM iter:  11  fx =   3063.0642529586  fx.delta = 752.95153620 
EM iter:  12  fx =   3816.3675000648  fx.delta = 753.30324711 
EM iter:  13  fx =   4572.9979835792  fx.delta = 756.63048351 
EM iter:  14  fx =   5377.2642435012  fx.delta = 804.26625992 
EM iter:  15  fx =                NA  fx.delta =        NA 
Error in if (fx.delta < tol) { : missing value where TRUE/FALSE needed


Best regards
Laura

Yves Rosseel

unread,
Oct 27, 2018, 12:00:47 PM10/27/18
to lav...@googlegroups.com, creon...@gmail.com
Thanks. Clearly, something goes wrong here, while estimating the
saturated model. Would you be able to send me (privately) the model and
the data (or just a snippet of the data, just enough to reproduce this)?

Thanks in advance,

Yves.
> --
> You received this message because you are subscribed to the Google
> Groups "lavaan" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to lavaan+un...@googlegroups.com
> <mailto:lavaan+un...@googlegroups.com>.
> To post to this group, send email to lav...@googlegroups.com
> <mailto:lav...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/lavaan.
> For more options, visit https://groups.google.com/d/optout.

Laura

unread,
Nov 2, 2018, 11:22:12 AM11/2/18
to lavaan

Update: Issue solved!

 

For others who might encounter the same problem:

I tried to model a cross-level interaction and introduced a level 2-variable in the level 1-section. This doesn't work because the level 2-variable has no level 1-variance. For a cross-level interaction to work, one would need a random slope on level 1 instead which is not yet possible in lavaan. According to Yves, lavaan dev 0.6-4.1343 (or higher) will produce the following warning:

 

Warning messages:

1: In lav_data_full(data = data, group = group, cluster = cluster,  :

   lavaan WARNING:

     Level-1 variable "mod" has no variance at the within level.

     The variable appears to be a between-level variable. Please remove

     this variable from the level 1 section in the model syntax.

2: In lav_h1_implied_logl(lavdata = lavdata, lavsamplestats = lavsamplestats,  :

   lavaan WARNING:

     H1 estimation resulted in a within covariance matrix with (near)

     zero variances for some of the level-1 variables: mod

 

Thanks a lot for the great help and the quick response!

Ramjanul Ahsan

unread,
Apr 16, 2020, 8:59:56 AM4/16/20
to lavaan
Hi Laura,

Can I get your final code? I am struggling with the coding to look into the Moderated mediation effect.


Thanks in advance.

Ramjan 

Laura

unread,
Apr 17, 2020, 10:14:59 AM4/17/20
to lavaan
Hi Ramjan,

I would if it had worked. Back then it did not work for the model I was trying to build so I ended up using Mplus.
But quite some time has passed since then so maybe it's possible to do this in lavaan now?!

Fingers crossed for your analyses!
Laura

Ramjanul Ahsan

unread,
Apr 17, 2020, 1:13:26 PM4/17/20
to lav...@googlegroups.com
Hi Laura,

Thanks for getting back to me. No it didn't work. Thats why I was bit optimistic when I see your post. 

Let's see how it goes.


Thanks again.
Ramjan

To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/d40d2d26-e874-452e-b6fd-bcf6b293dea2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages