6

谁能告诉我如何在模型语句中lavaan为结构方程模型的包编写潜在变量交互?

假设我有潜在变量L1和一些观察到的变量F1,并且想编码它们对某些结果的交互影响Y

L1 =~ x1 + x2

Y ~ L1 * F1 

这行不通。

提前致谢!

4

1 回答 1

5

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

于 2014-07-15T16:35:55.800 回答