Nested Random Intercepts

75 views
Skip to first unread message

Seamus Donnelly

unread,
Jun 5, 2025, 2:53:19 AM6/5/25
to lavaan

Hi Everyone,

 I’m trying to estimate what is basically a random-intercept cross lagged panel model but with nested random intercepts. I have 2 variables which were each measured 3 times a day, over 10 days, for each participant. I want to estimate the auto-regressive and cross-lagged effects using  consecutive measurements in the same day. This means I would ideally have by-participant random intercepts and by-day random intercepts nested within participants (I know multilevel modelling software would more naturally handle this nesting, but I haven’t found a way to estimate autoregressive and cross lagged effects using the residuals). To my understanding, lavaan doesn’t have an option for estimating nested random intercepts but I’ve found what I think might be a solution.

If I remember correctly, estimating nested random intercepts is equivalent to estimating (a) one distribution of random intercepts defined over participants and (b) a second distribution of random intercepts defined over each crossing of participant and day. I don't think there's an easy way to estimate this second distribution in lavaan but I had an idea: What if I first estimate the by-participant random intercepts like normal, and then create a separate latent variables for  each day (e.g., one LV for fear_1, fear_2, fear_3 all of which are from day 1, one LV for fear_4, fear_5, fear_6 all from day 2), and constrain the variances and covariances of each of those day-specific latent variables to be the same. It seems to me like that would treat participants' day-specific deviations from their average as samples from the same distribution. Below is a snippet of the code I had in mind (I've left out the time-point specific residuals and autoregressive/cross lagged paths). I’m not 100% confident about this though, so I’m keen to hear if anyone thinks this won’t work.

 

model1 <-'

# by participant random intercepts

Fear_SI =~ 1*fear_total_1 + 1*fear_total_2 + 1*fear_total_3 + 1*fear_total_4 +1*fear_total_5 + 1*fear_total_6 + 1*fear_total_7 + 1*fear_total_8 + 1*fear_total_9

SA_SI  =~ 1*sa_total_1 + 1*sa_total_2 + 1*sa_total_3 + 1*sa_total_4 +1*sa_total_5 + 1*sa_total_6 + 1*sa_total_8 + 1*sa_total_9

Fear_SI ~~ Fear_SI

SA_SI ~~ SA_SI

Fear_SI ~~ SA_SI

 

# by participant and day random intercepts

fear_day_1 =~ 1*fear_total_1 + 1*fear_total_2 + 1*fear_total_3

fear_day_2 =~ 1*fear_total_4 + 1*fear_total_5 + 1*fear_total_6

fear_day_3 =~ 1*fear_total_7 + 1*fear_total_8 + 1*fear_total_9

 

fear_day_1~~VarF*fear_day_1

fear_day_2~~VarF*fear_day_2

fear_day_3~~VarF*fear_day_3

 

sa_day_1 =~ 1*sa_total_1 + 1*sa_total_2 + 1*sa_total_3

sa_day_2 =~ 1*sa_total_4 + 1*sa_total_5 + 1*sa_total_6

sa_day_3 =~ 1*sa_total_7 + 1*sa_total_8 + 1*sa_total_9

 

sa_day_1~~VarS*sa_day_1

sa_day_2~~VarS*sa_day_2

sa_day_3~~VarS*sa_day_3

 

fear_day_1~~Cov*sa_day_1

fear_day_2~~Cov*sa_day_2

fear_day_3~~Cov*sa_day_3

Reply all
Reply to author
Forward
0 new messages