Interaction within the groups

99 views
Skip to first unread message

sd1808

unread,
Feb 5, 2019, 9:42:07 PM2/5/19
to lavaan
I am trying to write a very linear regression with an interaction term. My outcome is y and main predictor is x and z/a are confounders. One confounder ('a') interacts with x. I need to calculate if the interaction between x and three groups of a is significant or not. Here is my model

HS.model<-' y ~ x + z + x:a'
fit= sem(HS.model, data=data, group="a", missing="fiml")
summary(fit)

I get an error 

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: x x:a

And the result I get is each group separately. How can I check interaction in this model? 

Terrence Jorgensen

unread,
Feb 6, 2019, 9:53:50 AM2/6/19
to lavaan
I need to calculate if the interaction between x and three groups of a is significant or not.

If there are 3 groups in "a", you need to create 2 dummy codes to represent them


But if you want a multigroup model (group = "a"), then "a" cannot be a variable in your model.  Alternatively, you can allow for the effect of X to be implicitly moderated by a in the multigroup model by giving the slopes different labels (and leaving "a" out of the regression equation).


Testing the interaction would involve comparing models in which the slopes are different (interaction) to a model in which the slopes are the same across groups:

mod.int <- 'y ~ c(g1, g2, g3)*x + z'

mod
.no.int <- 'y ~ c(g1, g1, g1)*x + z'

Fit both models, then compare them using lavTestLRT().  Note that without labeling the z slopes above, they will differ across groups by default (implicitly, z:a interaction).  To avoid that, provide identical labels for the z effect in both models:  c(foo, foo, foo)*z

I assume you are using SEM instead of OLS regression with the lm() function because you have missing data.  Multiple imputation is also an option if you want to run regular regression with standard formulas: lm(y ~ x * a + z).  Check out the mitml package for helpful functions to facilitate imputation and pooling results.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

sd1808

unread,
Feb 7, 2019, 7:48:20 AM2/7/19
to lavaan
Dear Terrence, 
This is most useful, I really appreciate your help. I made 2 dummy code and my model looks like 

HS.model1<-' y ~ x + z + x:a1'
HS.model2<-'y ~ x+z+x:a2' 

Can I confirm that in both the model the x:a1 is comparing when a=0 with when a=1. And then x:a2 is comparing when a=0 and when a=2.  Do I need to put these two in the same HS.model or can they be separate? 

I am unable to understand why you mean by multigroup model. I am not that advanced with lavaan package. I will go through the tutorial. 

I cannot thank you enough. I have wasted my last 2 months trying to understand this myself. 

Cheers
sd1808

Terrence Jorgensen

unread,
Feb 8, 2019, 6:23:37 AM2/8/19
to lavaan
Can I confirm that in both the model the x:a1 is comparing when a=0 with when a=1.

No, you are comparing a=1 to a = {either 0 or 2}.  But you aren't actually doing that because you left out the simple effect of a1.

And then x:a2 is comparing when a=0 and when a=2.  

No, that would compare a = 2 to a = {1 or 0}, if you included a2.

Do I need to put these two in the same HS.model or can they be separate? 

They both need to be in the model to make the pairwise comparisons you expect.  And the interaction term is only sensible if you obey the hierarchical principle and include both lower-order effects.

mod0 <- ' y ~ x + a1 + a2 + z + 0*x:a1 + 0*x:a2'
mod1
<- 'y ~ x + a1 + a2 + z + x:a1 + x:a2'


You can fit both models and use lavTestLRT() to compare them, or you can just fit the interaction model with labels for the interaction terms and use lavTestWald().

mod <- 'y ~ x + a1 + a2 + z + int1*x:a1 + int2*x:a2'
fit
<- lavaan(mod, ...)
lavTestWald
(fit, constraints = c("int1","int2"))
Reply all
Reply to author
Forward
0 new messages