0
$\begingroup$

I am familiarizing myself with SEM and the lavaan package for R bc I would like to run a mediation analysis. My problem is that the data I have is nested and currently I don't see how I could do a mediation analysis on this type of data using lavaan.

The data is from a cognitive psychology study where participants recall answers on a memory test for questions presented in a study phase. The data is clustered by participant (ID ~ 50) and by the topic of the questions (topics = 8). The outcome variable is recall (0/1) the predictor is a variable reflecting if the question is related to a previous reading (0/1) and the mediator is a curiosity rating (1-5). The data is trial level (80 responses/participant), clustered by participants and question topic (all participants read all the questions - 10 resps/topic).

How would you implement a mediation analysis on this data using lavaan, taking into account the clustering of the data? Any help is appreciated.

$\endgroup$
0
$\begingroup$

Do you want to test the mediation at the level-2, level-1 or both? You have here an example of testing an homologous model at both levels:

      model <- '
        level: 1
            # direct effect
                 y3 ~ c*x3
               # mediator
                 y2 ~ a*x3
                 y3 ~ b*y2
               # indirect effect (a*b)
                 ab := a*b
               # total effect
                 total := c + (a*b)
        level: 2
                    # direct effect
                 y3 ~ c*x3
               # mediator
                 y2 ~ a*x3
                 y3 ~ b*y2
               # indirect effect (a*b)
                 ab := a*b
               # total effect
                 total := c + (a*b)
    '
      
    fit <- sem(model = model, data = Demo.twolevel, cluster = "cluster")
    summary(fit, std=T)
$\endgroup$
2
  • $\begingroup$ thank you! the syntax is fine, although it turned out that lavaan can not handle binary and ordinal variables yet :/ trying mplus now $\endgroup$ Jul 8 '21 at 10:27
  • $\begingroup$ Yes, that's true. Please check the solution as verified if it solves the general problem $\endgroup$
    – Sinval
    Jul 8 '21 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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