Moderation in MLM - bug?

219 views
Skip to first unread message

Toby

unread,
Mar 4, 2024, 2:51:52 AM3/4/24
to lavaan
I am running the below model:
level: 1 F ~ A + B + A:B + Family_Background_SES + Age K ~ A + B + A:B + Family_Background_SES + Age
#Orthogonal variable correlations fixed to 0 F~~ 0*K
level: 2 F ~ A + B + A:B + Family_Background_SES + Age K ~ A + B + A:B + Family_Background_SES + Age F~~ 0*K
I am clustering by Sex. Error in lavaan(lavpartable, slotOptions = lavoptions2, slotSampleStats = lavsamplestats, : lavaan ERROR: Interaction terms involving latent variables (fA:B) are not supported. You may consider creating product indicators to define the latent interaction term. See the indProd() function in the semTools package.
I am a bit confused. Why am I getting this error - I have not specified a latent variable?

Kjell Slupphaug

unread,
Mar 11, 2024, 4:28:19 PM3/11/24
to lavaan
Moderation effects aren't supported in general. You can check out https://github.com/Kss2k/modsem

Christian Arnold

unread,
Mar 11, 2024, 4:34:44 PM3/11/24
to lav...@googlegroups.com
Why are moderation effects generally not supported? I don't see it that way.

Best

Christian
From: lav...@googlegroups.com <lav...@googlegroups.com> on behalf of Kjell Slupphaug <sluppha...@gmail.com>
Sent: Monday, March 11, 2024 9:28:19 PM
To: lavaan <lav...@googlegroups.com>
Subject: Re: Moderation in MLM - bug?
 
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/31f6010f-471c-4d94-8d56-d49b18d22e31n%40googlegroups.com.

Toby

unread,
Mar 18, 2024, 6:49:26 PM3/18/24
to lavaan
Moderation effects - as far as I can see - are well supported in other SEMs which are available to run using Lavaan. I do not quite understand your comment.

I would really appreciate some further elaboration - I am new to this after all !

Best wishes

T

Christian Arnold

unread,
Mar 19, 2024, 6:20:36 AM3/19/24
to lavaan
True. QMS/LMS are not supported. But that is different from "aren't supported in general".  Moderator effects are supported via the PI approach. Here are two examples:

library(lavaan)

# Simulate data
set.seed(1)
data <- simulateData("X ~ 0.2 * Y1 + 0.3 * Y2", sample.nobs = 4000)
data$x <- data$X + 0.4 * data$Y1 * data$Y2

# Use Y1:Y2
fit <- sem("X ~ Y1 + Y2 + Y1:Y2", data)
parameterEstimates(fit)

# Use indProd function
library(semTools)
data <- indProd(data, "Y1", "Y2", doubleMC = FALSE, namesProd = "Y1xY2")

fit <- sem("X ~ Y1 + Y2 + Y1xY2", data)
parameterEstimates(fit)


The question is why some variables are considered latent. Perhaps it would help if you could provide the complete source code?

Kjell Slupphaug

unread,
Mar 19, 2024, 6:30:02 AM3/19/24
to lav...@googlegroups.com
Yeah, I meant that interaction effects aren't supported by lavaan itself. I.e., you need to compute product indicators. Depending on your approach you also need to add complicated and/or tedious constraints. The modsem package is meant as an alternative to semTools -- amongst other things, specifying constraints automatically, before estimating the model in lavaan. 

I apologize for the confusion.

You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/BQYTo8t_mVI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/15806a84-d5d8-47fc-a2f0-9ed174370a95n%40googlegroups.com.

Christian Arnold

unread,
Mar 19, 2024, 6:47:54 AM3/19/24
to lav...@googlegroups.com
Sorry. I don't understand your argument. In the simple example I sent, you don't need to calculate product indicators. "Y1:Y2" is sufficient. True, with LV it doesn't work like that and you really have to think carefully about constraints. This has nothing to do with lavaan, but is a consequence of the PI approach. There are certainly other approaches such as LMS. I can't see that these are available in medmod? http://cran.nexr.com/web/packages/medmod/index.html
Sent: Tuesday, March 19, 2024 11:29:47 AM
To: lav...@googlegroups.com <lav...@googlegroups.com>

Kjell Slupphaug

unread,
Mar 19, 2024, 7:05:57 AM3/19/24
to lav...@googlegroups.com
I am sorry we are probably talking past each other. Im not sure what medmod has to do with anything (I referred to modsem). In your example you used observed variables (although you still computed a product using indprod), and as you say you dont need any constraints when using observed variables. I misread the syntax for the thread as well, I assumed Toby was using latent variables (not showing the whole syntax for the model), but it seems as though he was using observed variables. 


Yves Rosseel

unread,
Mar 19, 2024, 7:16:54 AM3/19/24
to lav...@googlegroups.com
In a MLM, the SEM approach is to use latent group-mean centering for all
variables that are specified at both the within and between level.
Therefore, they 'become' latent variables, and moderation is not allowed.

The way out is to create a new variable that is the product of the A and
B, and use this in the model syntax.

On 3/4/24 08:51, Toby wrote:
> I am clustering by Sex.

If you only have 2 levels, then MLM is not the way to go. Did you mean
to run a multiple group SEM?

Yves.
Reply all
Reply to author
Forward
0 new messages