lavaan mediation with interaction terms and glmer() and lmer() models

115 views
Skip to first unread message

Nadine Herzog

unread,
Feb 14, 2024, 11:13:26 AM2/14/24
to lavaan
Hey hive-mind,
I am sure someone must have asked this before, but I couldn't find any other conversations that adress my specific question.

My problem is, that I am trying to run a mediation analysis with lavaan, but get zero degrees of freedom in the output. That can not be right.

I suspect the problem may come from two sources:
1) I am trying to fit a glmer() and a lmer() model with the random factor "ID" (because my data is trial-by-trial, i.e. multiple rows per ID)

2) I am trying to look at whether an interaction effect is mediated by a certain EEG measure (power in my case)

Can someone help me in trying to find what I did wrong to get zero degrees of freedom?

My data is:
c path:
correct <- binary outcome variable (can either be 1 or 0, per trial within-subject variable)
DFA <- continous predictor (between-subject variable, one value per ID)
condition <- categorical/binary predictor (within-subject, per trial)
AAratio <- continous predictor (between-subject variable, one value per ID)

when I do this manually with glmer(), I find a significant 3-way interaction of  DFA*condition*AAratio

now I want to know how 'power_data' (within-subject, per trial) might mediate this relationship...
so for my a-path I would manually do a lmer() with 
power_data ~ DFA*condition*AAratio + (1|ID)

and then b-path a glmer(): 
correct ~ power_data + (1|ID)

so far so good... but when I try to do this with lavaan with the following code, I get 0 degrees of freedom and this is weird...

my code:

library(lavaan)

model <- '

#Mediation paths
power_data ~ a1*DFA + a2*AAratio + a3*condition + a4*(DFA_AAratio) + a5*(DFA_condition) + a6*(AAratio_condition) + a7*(DFA_AAratio_condition)
correct ~ b*power_data

#Direct path
correct ~ c1*DFA + c2*AAratio + c3*condition + c4*(DFA_AAratio) + c5*(DFA_condition) + c6*(AAratio_condition) + c7*(DFA_AAratio_condition)

#Mediated effect (indirect path)
indirect := a1*b + a2*b + a3*b + a4*b + a5*b + a6*b + a7*b

#Total effect
total := indirect + c1 + c2 + c3 + c4 + c5 + c6 + c7
'

fit <- sem(model, data = subset, cluster = "ID")

summary(fit, fit.measures=TRUE)

Any help would be appreciated :)
Thanks a lot!



Reply all
Reply to author
Forward
0 new messages