0
$\begingroup$

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!

$\endgroup$

1 Answer 1

1
$\begingroup$

You can't put an interaction term in the model in lavaan. Create the interaction term first.

$\endgroup$
1
  • $\begingroup$ Thanks! I created the interaction term first before running lavaan. df$SESinter <- df$Edu*df$Occuand put this term in the outcome path CogTest ~ c*EV +b*NP + Sex + AgeatTest + TesttoDeath + Race + SESinter + Edu + Occu, but I am still getting the same error. Can anyone help me to fix it? Thanks! $\endgroup$
    – Trebit14
    Commented Jul 2, 2023 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.