6

Can anyone show me how to code latent variable interactions in the model statement for lavaan package for structural equation models?

Suppose I had latent variable L1 and some observed variable F1 and would like to code their interaction effect on some outcome Y:

L1 =~ x1 + x2

Y ~ L1 * F1 

This doesn't work.

Thanks in advance!

user20650
  • 24,654
  • 5
  • 56
  • 91
user3773375
  • 61
  • 1
  • 4
  • 1
    I think you may get a better response on [cross-validated](http://stats.stackexchange.com/) as this is more to do with statistics – user20650 Jun 25 '14 at 03:21

1 Answers1

6

Thanks to the important comment of John Madden I'll differentiate between moderation (the thing you are probably looking for) and mediation.

Moderation (interaction of variable values)

The quick answer to your question is: To my knowledge there is no lavaan-integrated possibility to do an interaction of two latent variables, but here is my go at a workaround:

  1. Define the latent variables (CFA)
  2. Extract predicted values, add them to your data frame and define an interaction variable
  3. Do your intended regression (with our without the latent variables themselves)

Here is some toy code for the workaround - the moderation doesn't make any sense with this data (mtcars which is in R base) and will give you a warning, but the structure of the workflow should be clear.

library(lavaan)

# 1. set up your measurement models
cfamodel <- "
    #defining the latent variables
    L1 =~ drat + wt
    L2 =~ disp + hp
"
fitcfa <- cfa(data = mtcars, model = cfamodel)

# 2. extract the predicted values of the cfa and add them to the dataframe
semdata <- data.frame(mtcars, predict(fitcfa))

# create a new variable with the interaction of L1 and L2
semdata <- semdata %>%
              mutate(L1L2 = L1 * L2)

# 3. now set up the regression and add the predefined interaction to the model
# a) regression with both latent variables and the interaction
semmodel1 <- "
    # define regression
    mpg ~ L1 + L2 + L1L2
"
fitsem1 <- sem(data = semdata, model = semmodel1)
summary(fitsem1)

# b) regression with only the interaction (does that even make sense? I don't know...)
semmodel2 <- "
    # define regression
    mpg ~ L1L2
"
fitsem2 <- sem(data = semdata, model = semmodel2)
summary(fitsem2)

Mediation (interaction of weights)

For Mediation you need to define a new parameter as a product of the two regression weights that are of interest. In your example with L1 as latent variable, F1 as observed variable and Y as dependend variable, that would be:

# define Regressions (direct effect)
Y ~ lambda1*X
Y ~ lambda2*M

# define Regressions (effect on mediator)
M ~ X

# define Interaction
interac := lambda1*lambda2

fit <- sem(model, data = Data)
summary(fit)

lavaan will then give you an estimate of the interaction.

The := operator "defines new parameters which take on values that are an arbitrary function of the original model parameters." Example taken from: http://lavaan.ugent.be/tutorial/mediation.html

j_5chneider
  • 390
  • 5
  • 15
  • 2
    I don't see where there is an interaction term in your response. The example you take is from a mediation example, whereas the OP is asking for an interaction, which, in the language of psychology, is referred to as moderation, and, to the best of my knowledge, is not supported by lavaan at this time. – John Madden Mar 20 '18 at 14:40
  • thanks for the comment. I was going to edit the answer for ages and finally found some time. <3 – j_5chneider Feb 13 '19 at 11:32
  • @j_5chneider thanks for the moderation example. Do you think this would be possible for a moderated mediation? Ive been stuck with this for some quite time – blazej Mar 06 '19 at 21:21
  • 1
    @blazej Good question. I think I've never read about a moderated mediation. Can you maybe plot/draw the paths of the model? I can't really imagine where the moderation and where the mediation comes in. – j_5chneider Mar 09 '19 at 00:59
  • 1
    sure, how do you want me to plot it? As a separate question? Oh wait... This is based on Mplus code but it's an example of moderated mediation that I'm dealing with: http://www.offbeat.group.shef.ac.uk/FIO/model14.htm – blazej Mar 10 '19 at 12:22
  • 1
    @blazej Perfect, thanks. The example in your link is a manifest model. I made you an example with `mtcars` data that is intergrated in R base, so you can run it too: `model <- " # paths on dependend variable mpg ~ lambda1*cyl + lambda2*disp + drat + disp:drat # path on mediator disp ~ cyl # define mediation: interaction of weights interac := lambda1*lambda2 " fit <- sem(model, data = mtcars) summary(fit)` – j_5chneider Mar 11 '19 at 19:18
  • 1
    @blazej If one of your variables that is involved in the moderation is modeled latent, you'd need to define them beforehand and extract the predicted values as in the moderation example above and then insert the interaction variable into the model. I can't insert line breaks in comments, so you'll have to do that after copying the code. To relate the example from my last comment to your example from the website: mpg = Y, cyl = X, disp = M, drat = V, disp:drat = MV (Moderation), interac = indirect effect (Mediation) – j_5chneider Mar 11 '19 at 19:37
  • 1
    Wow! Thank looks indeed great. Any idea why this has not been described in lavaan materials? I might make it a separate question if you'd like to describe this example in full? – blazej Mar 13 '19 at 18:59
  • @blazej You're very welcome. I gues that the moderated mediation is not described because their documentation can only describe so much models. So they describe the basic concepts and leave it to the practitioners to combine any model specifications. The documentation would be excessive if they'd even only describe the models from the website you gave me the link to - and they do the work or free (unlike MPlus). – j_5chneider Mar 14 '19 at 10:07
  • 1
    @blazej Making it a separate question is a good idea. Write one up and link me, so I can describe the answer with more explanation. – j_5chneider Mar 14 '19 at 10:10