465 views

Skip to first unread message

Feb 22, 2019, 5:52:21 PM2/22/19

to lavaan

I am trying to run Random Intercept Cross-Lagged Panel Model (RI-CLPM) using the Lavaan syntax Mund & Nestler (2017) provided in their paper.

If I could get some help extending this code to add a third variable (mediator) to the two variable model, I would find it tremendously helpful.

Below is Mund & Nestler's syntax, to which I attempted to add a third variable. All edits are highlighted in yellow, specific questions highlighted in green.

Thank you in advance for any help (and credit to the authors of this paper)

Figure of two-variable RI-CLPM

*####
++++++++++++++++++++++++++++++++++++++++++++++++++++++*

*####
Random-Intercept Cross-Lagged Panel Model ####*

*####
++++++++++++++++++++++++++++++++++++++++++++++++++++++*

*## load package*

*library(lavaan)*

*## load data*

*data <- read.table("./data/Fakedata_RI-CLPM_R.dat",
header = T)*

*## Define model for lavaan*

*riclpm <- '*

*# Define intercept factors*

*ix =~ 1*x1+1*x2+1*x3+1*x4*

*iy =~ 1*y1+1*y2+1*y3+1*y4*

iz *=~
1*z1+1*z2+1*z3+1*z4*

*# Define phantom latent variables*

*etax1 =~ 1*x1*

*etax2 =~ 1*x2*

*etax3 =~ 1*x3*

*etax4 =~ 1*x4*

*etay1 =~ 1*y1*

*etay2 =~ 1*y2*

*etay3 =~ 1*y3*

*etay4 =~ 1*y4*

*etaz1 =~ 1*z1*

*etaz2 =~ 1*z2*

*etaz3 =~ 1*z3*

*etaz4 =~ 1*z4*

*# Autoregressive effects*

*etax2 ~ a1*etax1*

*etax3 ~ a1*etax2*

*etax4 ~ a1*etax3*

*etay2 ~ a2*etay1*

*etay3 ~ a2*etay2*

*etay4 ~ a2*etay3*

*etaz2 ~ a2*etaz1*

*etaz3 ~ a2*etaz2*

*etaz4 ~ a2*etaz3*

* *

*# Crosslagged effects*

*etay2 ~ c1*etax1*

*etay3 ~ c1*etax2*

*etay4 ~ c1*etax3*

*etax2 ~ c2*etay1*

*etax3 ~ c2*etay2*

*etax4 ~ c2*etay3*

* *

*etaz2 ~ c1*etax1*

*etaz3 ~ c1*etax2*

*etaz4 ~ c1*etax3*

__ __

*etax2 ~ c2*etaz1*

*etax3 ~ c2*etaz2*

*etax4 ~ c2*etaz3*

__ __

*etay2 ~ c1*etaz1*

*etay3 ~ c1*etaz2*

*etay4 ~ c1*etaz3*

__ __

*etaz2 ~ c2*etay1*

*etaz3 ~ c2*etay2*

*etaz4 ~ c2*etay3*

*# Some further constraints on the
variance structure*

*# 1. Set error variances of the observed
variables to zero*

*x1 ~~ 0*x1*

*x2 ~~ 0*x2*

*x3 ~~ 0*x3*

*x4 ~~ 0*x4*

*y1 ~~ 0*y1*

*y2 ~~ 0*y2*

*y3 ~~ 0*y3*

*y4 ~~ 0*y4*

*z1 ~~ 0*z1*

*z2 ~~ 0*z2*

*z3 ~~ 0*z3*

*z4 ~~ 0*z4*

*# 2. Let lavaan estimate the variance
of the latent variables*

*etax1 ~~ varx1*etax1*

*etax2 ~~ varx2*etax2*

*etax3 ~~ varx3*etax3*

*etax4 ~~ varx4*etax4*

*etay1 ~~ vary1*etay1*

*etay2 ~~ vary2*etay2*

*etay3 ~~ vary3*etay3*

*etay4 ~~ vary4*etay4*

*etaz1 ~~ varz1*etaz1*

*etaz2 ~~ varz2*etaz2*

*etaz3 ~~ varz3*etaz3*

*etaz4 ~~ varz4*etaz4*

*# 3. We also want estimates of the
intercept factor variances and an*

*#
estimate of their covariance*

*ix ~~ varix*ix*

*iy ~~ variy*iy*

*iz ~~ variz*iz*

*ix ~~ covi*iy*

*ix ~~ covi*iz*

*iy ~~ covi*iz*

* *

*# 4. We have to define that the
covariance between the intercepts and*

*#
the latents of the first time point are zero*

*etax1 ~~ 0*ix*

*etay1 ~~ 0*ix*

*etaZ1 ~~ 0*ix*

*etax1 ~~ 0*iy*

*etay1 ~~ 0*iy*

*etaZ1 ~~ 0*iy*

*etax1 ~~ 0*iz*

*etay1 ~~ 0*iz*

*etaZ1 ~~ 0*iz*

*# 5. Finally, we estimate the
covariance between the latents of x and y*

*#
of the first time point, the second time-point and so on. note that*

*#
for the second to fourth time point the correlation is constrained to*

*#
the same value*

*etax1 ~~ cov1*etay1*

*etax2 ~~ e1*etay2*

*etax3 ~~ e1*etay3*

*etax4 ~~ e1*etay4*

__ __

*etax1 ~~ cov1*etaz1*

*etax2 ~~ e1*etaz2*

*etax3 ~~ e1*etaz3*

*etax4 ~~ e1*etaz4*

__ __

*etay1 ~~ cov1*etaz1*

*etay2 ~~ e1*etaz2*

*etay3 ~~ e1*etaz3*

*etay4 ~~ e1*etaz4*

*# The model also contains a mean structure
and we have to define some*

*# constraints for this part of the
model. the assumption is that we*

*# only want estimates of the mean of
the intercept factors. all other means*

*# are defined to be zero:*

*x1 ~ 0*1*

*x2 ~ 0*1*

*x3 ~ 0*1*

*x4 ~ 0*1*

*y1 ~ 0*1*

*y2 ~ 0*1*

*y3 ~ 0*1*

*y4 ~ 0*1*

*z1 ~ 0*1*

*z2 ~ 0*1*

*z3 ~ 0*1*

*z4 ~ 0*1*

*etax1 ~ 0*1*

*etax2 ~ 0*1*

*etax3 ~ 0*1*

*etax4 ~ 0*1*

*etay1 ~ 0*1*

*etay2 ~ 0*1*

*etay3 ~ 0*1*

*etay4 ~ 0*1*

* *

*etaz1 ~ 0*1*

*etaz2 ~ 0*1*

*etaz3 ~ 0*1*

*etaz4 ~ 0*1*

*ix ~ 1*

*iy ~ 1*

*iz ~ 1*

*## define correlations (NOT MODIFIED—QUESTION)*

*cori := covi /
(sqrt(varix) * sqrt(variy))*

*cor1 := cov1 /
(sqrt(varx1) * sqrt(vary1))*

*cort2 := e1 /
(sqrt(varx2) * sqrt(vary2))*

*cort3 := e1 /
(sqrt(varx3) * sqrt(vary4))*

*cort4 := e1 /
(sqrt(varx4) * sqrt(vary4))*

*'*

*fit <- sem(riclpm, data = data)*

*summary(fit, fit.measures = T)*

Mar 5, 2019, 10:21:31 AM3/5/19

to lavaan

Apologies for another post but would really find any feedback very helpful. Questions are highlighted in green. Thank you again.

Mar 5, 2019, 11:48:08 AM3/5/19

to lav...@googlegroups.com

Hi,

What are your questions? I do see the highlighted green areas.
What specifically are your questions?

--

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.

To post to this group, send email to lav...@googlegroups.com.

Visit this group at https://groups.google.com/group/lavaan.

For more options, visit https://groups.google.com/d/optout.

Mar 5, 2019, 6:18:14 PM3/5/19

to lavaan

I'm sorry that my question wasn't clear. I am extending the code that was written for 2 variables to 3 and wasn't sure that the modifications I made in highlighted green areas were accurate.

Mar 5, 2019, 7:53:23 PM3/5/19

to lavaan

I see. Everything looks fine to me.

Mar 5, 2019, 8:13:46 PM3/5/19

to lavaan

Wonderful. Thank you!

Nov 3, 2022, 5:55:26 AM11/3/22

to lavaan

Did it work out at the end? I tried the same, but somehow lavaan didn't recognise varz...

Reply all

Reply to author

Forward

0 new messages