I am beginner to run mediation analysis using lavaan package in r and have some issues to run the models and understand errors.
Here is my syntax.
# Ordinal NP with covariates
model1 <- ' # outcome
CogTest ~ c*EV +b*NP + Sex + AgeatTest + TesttoDeath + Race + Edu*Occu
# mediator
NP ~ a*EV + Sex + AgeatDeath + Gen
# indirect effect (a*b)
ab := a*b
# dirdct effect
direct := c
# total effect
total := c + (a*b)
'
NP : ordinal, mediator EV : continuous, predictor CogTest : continuous, outcome Sex, AgeatTest, TesttoDeath, Race, Edu*Occu (interaction of Edu and Occu) : covariates for the outcome path Sex, AgeatDeath, and Gen : covariates for the mediator path.
fit.model1.delta <- sem(model1, data = df, ordered = c("NP"))
summary(fit.model1.delta)
When I ran the model, I got an error message.
Error in if (!all(x == cache$theta)) { :
missing value where TRUE/FALSE needed
But, if one of the two covariates, AgeatTest and TesttoDeath, was excluded from the outcome path, for example
# outcome
CogTest ~ c*EV +b*NP + Sex + TesttoDeath + Race + Edu*Occu
or
CogTest ~ c*EV +b*NP + Sex + AgeatTest + Race + Edu*Occu
The model was fitted and results were released. Does anyone know what was wrong with my analysis?
Thanks in advance!