Mediation in Latent Growth Model using growth() function

151 views
Skip to first unread message

A G

unread,
Oct 8, 2020, 9:24:15 AM10/8/20
to lavaan
Dear Professors

I am analyzing a latent growth model of two latent variables over 10 measurement time points with a mediation on the slope of one of my latent variables (feed).

My syntax is the following:

# mediation 
lgcm <- '
# random intercept and slope
i_feed =~ 1*Feed_t1 + 1*Feed_t2 + 1*Feed_t3 + 1*Feed_t4 + 1*Feed_t5 + 1*Feed_t6 + 1*Feed_t7 + 1*Feed_t8 + 1*Feed_t9 + 1*Feed_t10  
s_feed =~ 0*Feed_t1 + 1*Feed_t2 + 2*Feed_t3 + 3*Feed_t4 + 4*Feed_t5 + 5*Feed_t6 + 6*Feed_t7 + 7*Feed_t8 + 8*Feed_t9 + 9*Feed_t10

i_amb =~ 1*Amb_t1 + 1*Amb_t2 + 1*Amb_t3 + 1*Amb_t4 + 1*Amb_t5 + 1*Amb_t6 + 1*Amb_t7 + 1*Amb_t8 + 1*Amb_t9 + 1*Amb_t10  
s_amb =~ 0*Amb_t1 + 1*Amb_t2 + 2*Amb_t3 + 3*Amb_t4 + 4*Amb_t5 + 5*Amb_t6 + 6*Amb_t7 + 7*Amb_t8 + 8*Amb_t9 + 9*Amb_t10 

# control variable regressions
i_feed ~ Age + Gender + JT  + TI_t0 + LG_t0
s_feed ~ Age + Gender + JT + TI_t0 + LG_t0

i_amb ~ Age + Gender + JT + TI_t0 + LG_t0
s_amb ~ Age + Gender +JT + TI_t0 + LG_t0

# mediator
Ef_t1 ~ a1*Ef_t1
s_feed ~ b1*Ef_t1

Ef_t2 ~ a2*Ef_t2
s_feed ~ b2*Ef_t2

Ef_t3 ~ a3*Ef_t3
s_feed ~ b3*Ef_t3

Ef_t4 ~ a4*Ef_t4
s_feed ~ b4*Ef_t4

Ef_t5 ~ a5*Ef_t5
s_feed ~ b5*Ef_t5

Ef_t6 ~ a6*Ef_t6
s_feed ~ b6*Ef_t6

Ef_t7 ~ a7*Ef_t7
s_feed ~ b7*Ef_t7

Ef_t8 ~ a8*Ef_t8
s_feed ~ b8*Ef_t8

Ef_t9 ~ a9*Ef_t9
s_feed ~ b9*Ef_t9

Ef_t10 ~ a10*Ef_t10
s_feed ~ b10*Ef_t10

# indirect effect
a1b1 := a1 * b1
a2b2 := a2 * b2
a3b3 := a3 * b3
a1b4 := a4 * b4
a2b5 := a5 * b5
a3b6 := a6 * b6
a1b7 := a7 * b7
a2b8 := a8 * b8
a3b9 := a9 * b9
a1b10 := a10 * b10

# direct effect
outcome =~ 0*Feed_t1 + 1*Feed_t2*c1 + 2*Feed_t3*c2 + 3*Feed_t4*c3 + 4*Feed_t5*c4 + 5*Feed_t6*c5 + 6*Feed_t7*c6 + 7*Feed_t8*c7 + 8*Feed_t9*c8 + 9*Feed_t10*c9 

# total effect
total1 := c1 + (a1*b1) 
total2 := c2 + (a2*b2) 
total3 := c3 + (a3*b3) 
total4 := c4 + (a4*b4) 
total5 := c5 + (a5*b5) 
total6 := c6 + (a6*b6) 
total7 := c7 + (a7*b7) 
total8 := c8 + (a8*b8) 
total9 := c9 + (a9*b9) 
total10 := c10 + (a10*b10) 
'

fit <- growth(lgcm, data = dtall, sample.nobs=nobs, estimator = "ml", missing="fiml" ) 
summary(fit)
fitmeasures(fit)


I have some experience with the growth function and my model without the mediation fits nicely. I am new to implementing a mediation within the growth function tough.

I do get error messages when fitting the model:

Error in lavaan::lavaan(model = lgcm, data = dtall, sample.nobs = nobs,  : 
  lavaan ERROR: missing observed variables in dataset: c1 c2 c3 c4 c5 c6 c7 c8 c9

I guess the code I provide here is incorrect, and my question is where I did the mistake with implementing the Cs? 

Information on the data:
My mediator Ef is measured at each time point (T1-T10) and should affect the slope of feed (feed_s).
My two latent variables Feed and Amb are measured at each time point (T1-T10).
I control for demographic (Age, Gender, JT..) and time-invariant variables (e.g., LG_t0) that were collected at a time 0 prior to the time-lagged assessment of my latent variables.


Thank you so much for any help on that!

Mauricio Garnier-Villarreal

unread,
Oct 8, 2020, 12:31:01 PM10/8/20
to lavaan
Your problem is in this line

outcome =~ 0*Feed_t1 + 1*Feed_t2*c1 + 2*Feed_t3*c2 + 3*Feed_t4*c3 + 4*Feed_t5*c4 + 5*Feed_t6*c5 + 6*Feed_t7*c6 + 7*Feed_t8*c7 + 8*Feed_t9*c8 + 9*Feed_t10*c9 

By putting the c1 etc after the variables Feed_t ... lavaan is treating c1 as a variable, not a label.

Also, not clear what you are trying to with this by fixing the slopes to growth curve values? I think you want to have the growth curve intercepts/slopes as predictors here, right?

A G

unread,
Oct 8, 2020, 5:01:00 PM10/8/20
to lavaan
>> By putting the c1 etc after the variables Feed_t ... lavaan is treating c1 as a variable, not a label. 

Thank you a lot for that input! 
I adapted the line and now lavaan takes it as a label and my error message diminishes. I am a bit unsure as to what part you are referring with your second input:

>> Also, not clear what you are trying to with this by fixing the slopes to growth curve values? I think you want to have the growth curve intercepts/slopes as predictors here, right?

Do you mean for example this part?          s_feed ~ b10*Ef_t10
I am unsure whether I did it - therefore, rather a question: How is it possible to implement a mediator, that mediates the relationship between time-lagged measurements (e.g., Feed_t1_1 -> Feed_t2 is mediated by the measure of Ef_t1) 


And a further question: Is this feasible in terms of mediation standards, or should I specify e.g., Feed_t1_1 -> Feed_t3 is mediated by the measure of Ef_t2?

Thank you again!


Mauricio Garnier-Villarreal

unread,
Oct 9, 2020, 10:55:14 AM10/9/20
to lavaan
My second commend refered to the same line of code
outcome =~ 0*Feed_t1 + 1*Feed_t2*c1 + 2*Feed_t3*c2 + 3*Feed_t4*c3 + 4*Feed_t5*c4 + 5*Feed_t6*c5 + 6*Feed_t7*c6 + 7*Feed_t8*c7 + 8*Feed_t9*c8 + 9*Feed_t10*c9 

With soemthing like this, looks like Outcome is another Growth curve slope.

Also, th elines like this Ef_t1 ~ a1*Ef_t1, dont work for mediation, because the regression is on a variable with itself.

It sounds to me that what you are looking for is a cross-lagged mediation model. Can you specified which are your predictors, whict are your mediators, and which are your outcomes in the mediation?

It does sounds odd to me that your predictor and outcome are the same variable over time. But there is no reason you cant do it

You could do a crosslagged mediation model, in which take into account time presedence for it. For example, predictors at time 1 -> mediators at time 2 -> Outcomes at time 3
And you could extend it as you have longer 10 time points.

Anothe optiocn would be to use the Exact Discrete Model (EDM) to estimate continuous time longitudinal mediation. You could do this with the ctsem package, but would require to swicth to continuous time models with differentila equations, which are harder to follow

A G

unread,
Jan 18, 2021, 6:56:48 AM1/18/21
to lavaan
Hello 

Thank you again for you help! It was a much needed input. :)  I now proceeded to conduct a cross-lagged model with random intercepts (according to Hamaker et al., 2015) with multiple indicators for my two latent constructs (Mulder & Hamaker, 2019). I made it on to the RI-CLPM with weak invariance, which I will list below. Here, I would like to implement two time-invariant predictors (age=intervall, gender=binary), but am unsure  a bit on the procedure, as in Mulder & Hamaker (2019), they specify the modeling of time-invariant predictors on the random intercept, but not for latent variables (where in the procedure on Hamaker's Github, one random intercept per indicator variable is specified). 

Short Recap of my model (hopefully answering your questions above): 
  • I did put a picture of my cross-lagged model here attached (without time-invariant predictors or moderation)
  • Latent RI-CLPM: I aim to capture the reciprocal relationship of Ra and Fe over 10 measurement time points (T1-T10). 
  • Time-invariant predictors: Further, I would like to take Age, Gender, and a construct of learning goal orientation as time-invariant predictors, as these factors are likely to influence Fe and Ra p (all measured before at T0).
  • Moderation: I would like to specify a moderation of the cross-lagged effect of Fe1 on Ra2 (and so on) by a time-varying variable Es1
Question on time-invariant prediction: Is it correct to specify the time-invariant predictor on each random intercept for indicator variables I specify (as listed below), or do I need to first also specify a random intercept for my latent construct, and relate my time-invariant predictors to that?

Here my current model: 

clpm.ri.1.s1 <- '

## DEFINE INDICATOR-SPECIFIC LATENT INTERCEPTS + Control: Age (s1)

# BETWEEN-PERSON COMPONENTS
### Fe
ix1 =~ 1*T1_Q48_1 + 1*T2_Q48_1 + 1*T3_Q48_1 + 1*T4_Q48_1 + 1*T5_Q48_1 + 1*T6_Q48_1 + 1*T7_Q48_1 + 1*T8_Q48_1 + 1*T9_Q48_1 + 1*T10_Q48_1
ix2 =~ 1*T1_Q48_2 + 1*T2_Q48_2 + 1*T3_Q48_2 + 1*T4_Q48_2 + 1*T5_Q48_2 + 1*T6_Q48_2 + 1*T7_Q48_2 + 1*T8_Q48_2 + 1*T9_Q48_2 + 1*T10_Q48_2

### Ra
iy1 =~ 1*T1_Q50_1 + 1*T2_Q50_1 + 1*T3_Q50_1 + 1*T4_Q50_1 + 1*T5_Q50_1 + 1*T6_Q50_1 + 1*T7_Q50_1 + 1*T8_Q50_1 + 1*T9_Q50_1 + 1*T10_Q50_1
iy2 =~ 1*T1_Q50_2 + 1*T2_Q50_2 + 1*T3_Q50_2 + 1*T4_Q50_2 + 1*T5_Q50_2 + 1*T6_Q50_2 + 1*T7_Q50_2 + 1*T8_Q50_2 + 1*T9_Q50_2 + 1*T10_Q50_2
iy3 =~ 1*T1_Q50_3 + 1*T2_Q50_3 + 1*T3_Q50_3 + 1*T4_Q50_3 + 1*T5_Q50_3 + 1*T6_Q50_3 + 1*T7_Q50_3 + 1*T8_Q50_3 + 1*T9_Q50_3 + 1*T10_Q50_3

# Regression of random intercepts on Age as time-invariant predictor
  ix1 + ix2 + iy1 +iy2 + iy3 ~ Age*s1 # Constrained over time. 

## WITHIN-PERSON COMPONENTS

# measurement model for latent multiple indicator variables
### Fe
etax1  =~ 1*T1_Q48_1  + lbdx2*T1_Q48_2 
etax2  =~ 1*T2_Q48_1  + lbdx2*T2_Q48_2 
etax3  =~ 1*T3_Q48_1  + lbdx2*T3_Q48_2 
etax4  =~ 1*T4_Q48_1  + lbdx2*T4_Q48_2 
etax5  =~ 1*T5_Q48_1  + lbdx2*T5_Q48_2 
etax6  =~ 1*T6_Q48_1  + lbdx2*T6_Q48_2 
etax7  =~ 1*T7_Q48_1  + lbdx2*T7_Q48_2 
etax8  =~ 1*T8_Q48_1  + lbdx2*T8_Q48_2 
etax9  =~ 1*T9_Q48_1  + lbdx2*T9_Q48_2  
etax10 =~ 1*T10_Q48_1 + lbdx2*T10_Q48_2 

### Ra
etay1  =~ 1*T1_Q50_1  + lbdy2*T1_Q50_2  + lbdy3*T1_Q50_3
etay2  =~ 1*T2_Q50_1  + lbdy2*T2_Q50_2  + lbdy3*T2_Q50_3
etay3  =~ 1*T3_Q50_1  + lbdy2*T3_Q50_2  + lbdy3*T3_Q50_3
etay4  =~ 1*T4_Q50_1  + lbdy2*T4_Q50_2  + lbdy3*T4_Q50_3
etay5  =~ 1*T5_Q50_1  + lbdy2*T5_Q50_2  + lbdy3*T5_Q50_3
etay6  =~ 1*T6_Q50_1  + lbdy2*T6_Q50_2  + lbdy3*T6_Q50_3
etay7  =~ 1*T7_Q50_1  + lbdy2*T7_Q50_2  + lbdy3*T7_Q50_3
etay8  =~ 1*T8_Q50_1  + lbdy2*T8_Q50_2  + lbdy3*T8_Q50_3
etay9  =~ 1*T9_Q50_1  + lbdy2*T9_Q50_2  + lbdy3*T9_Q50_3
etay10 =~ 1*T10_Q50_1 + lbdy2*T10_Q50_2 + lbdy3*T10_Q50_3

# Autoregressive effects
### Fe
etax2 ~ a1*etax1
etax3 ~ a1*etax2
etax4 ~ a1*etax3
etax5 ~ a1*etax4
etax6 ~ a1*etax5
etax7 ~ a1*etax6
etax8 ~ a1*etax7
etax9 ~ a1*etax8
etax10 ~ a1*etax9

### Ra
etay2 ~ a2*etay1
etay3 ~ a2*etay2
etay4 ~ a2*etay3
etay5 ~ a2*etay4
etay6 ~ a2*etay5
etay7 ~ a2*etay6
etay8 ~ a2*etay7
etay9 ~ a2*etay8
etay10 ~ a2*etay9

# Crosslagged effects
### Ra on Fe
etay2 ~ c1*etax1
etay3 ~ c1*etax2
etay4 ~ c1*etax3
etay5 ~ c1*etax4
etay6 ~ c1*etax5
etay7 ~ c1*etax6
etay8 ~ c1*etax7
etay9 ~ c1*etax8
etay10 ~ c1*etax9

### Fe on Ra
etax2 ~ c2*etay1
etax3 ~ c2*etay2
etax4 ~ c2*etay3
etax5 ~ c2*etay4
etax6 ~ c2*etay5
etax7 ~ c2*etay6
etax8 ~ c2*etay7
etax9 ~ c2*etay8
etax10 ~ c2*etay9

# within-time covariances 
etax1 ~~ cov1*etay1              
etax2 ~~ cove*etay2                                      
etax3 ~~ cove*etay3
etax4 ~~ cove*etay4
etax5 ~~ cove*etay5
etax6 ~~ cove*etay6                                                
etax7 ~~ cove*etay7
etax8 ~~ cove*etay8
etax9 ~~ cove*etay9
etax10 ~~ cove*etay10
'

My fitting in sem: 
fit_clpm.ri.1.s1 <- sem(clpm.ri.1.s1, data = dt, verbose = T, orthogonal = T, estimator = "MLR", missing = "fiml") 

Thank you in advance on your help.
CLPM_modell.jpg

A G

unread,
Jan 18, 2021, 8:26:25 AM1/18/21
to lavaan

 Additional Question: 

Moderation: I would like to specify a moderation of the cross-lagged effect of Fe1 on Ra2 (and so on) by a time-varying variable Es

--> is it possible to implement such a moderation of a cross-lagged effect in SEM? 



Mauricio Garnier-Villarreal

unread,
Jan 19, 2021, 5:04:02 AM1/19/21
to lavaan
When you add the time invariant covariate like this, you are constraining it to have the same effect (Age label) across time and variables. I would recommend to have it constraint across time, but not across variables
##
# Regression of random intercepts on Age as time-invariant predictor
  ix1 + ix2 + iy1 +iy2 + iy3 ~ Age*s1 # Constrained over time.
##

Like this
ix1 ~ Agex*s1
ix2 ~ Agex*s1
iy1 ~ Agey*s1
iy2 ~ Agey*s1

You can always allow it to be different over time, and compare the models

I havent use the RI models before, so I will assume that part is correct

As the within time covariances are constraint to be equal, this is assuming the residual correlation is equal. This seems like an overly restrictive constraint to me, to could allow these covariances to be different over time.

About the moderation, you could build the latent factor interaction at each time point. With either double mean centering or residual cenering. You can do this with the ?indProd function from semTools.
Basically,
- the initial model need to have also the covariate predicting Ra
- create an interaction of indicators for Fe and the covariate.
- Then you cadd another latent variable that is define by these interaction indicators
- add the covariate and the latent interaction as predictors of Ra over time
- then evaluate the signifficance of the latent interaction factor
- evaluate the magnitude of its effect by the change in R2 when the factor indicator is added
- test for simple slopes with the probe2Way functions from semTools (make sure to use the one respective to same type of indicator interaction you used)
- plot the desire simple slopes with the plotProbe function from semTools



Hope this helps

Reply all
Reply to author
Forward
0 new messages