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:
- Define the latent variables (CFA)
- Extract predicted values, add them to your data frame and define an interaction variable
- 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