2
$\begingroup$

I'm trying to set up a mediated moderation model using lavaan but am unsure how to code it. I want to replicate Hayes process model number 7, but with two independent variables and an interaction between them. The independent variables are dummy coded, so I don't think I can just multiply them together to get the interaction term. But the moderator, mediator, and outcome variables are continuous.

Here's what my data looks like:

df <- data.frame( iv1 = c(rep(0, 50), rep(1, 50)),
                  iv2 = c(rep(c(0,1), 50)),
                  moderator = rnorm(mean = 5.19, n = 100, sd = 1.22),
                  mediator = rnorm(mean = 4.02, n = 100, sd = 1.90)
                  dv = rnorm(mean = 3.27, n = 100, sd = 1.35))

Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

Actually, yes, you can just multiply the binary predictors together. The 0 and 1 are logical parameters, and multiplying in this case preserves the logical relation. You will create a new 0-1 variable which will correctly represent the interaction. Sometimes it really is that easy.

$\endgroup$

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.