1

I'm conducting a mediation analysis for my thesis. The mediation consists of one predictor variable, 4 mediators and three outcomes. After running my model and looking at the significant covariances between the mediators as well as between the outcomes, I thought it made sense to include interaction terms. I've tried out a few options to add the interaction terms to my model specification, but R could not run the model.

Does anybody know where I have to add the interaction effects in my model specification?

More information and code

Covariates: age_BL, education_gr, monkeypox_FU Predictor: trauma_sum_crit_BL Mediators: loneliness_total_score_BL, bdi_total_score_BL, stai_total_score_BL, bis15_total_score_BL Outcomes: rb_sex_noz_FU, rb_sub_noz_FU, audit_sumscore_FU

I want to allow interaction between all mediators such as:

bdi_total_score_BL * stai_total_score_BL
bdi_total_score_BL * loneliness_total_score_BL
bdi_total_score_BL * bis15_total_score_BL
stai_total_score_BL * loneliness_total_score_BL
stai_total_score_BL * bis15_total_score_BL
loneliness_total_score_BL * bis15_total_score_BL

I also want to allow interaction between two outcomes like:

rb_sub_noz_FU * audit_sumscore_FU

This is my model specification resp. code:

> specmod_comp <-  "
+              # Direct effect: Trauma -> Substance 
+              rb_sub_noz_FU ~ c1 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              rb_sex_noz_FU ~ c2 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              audit_sumscore_FU ~ c3 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              
+              # Mediators: Trauma -> Mediator
+              bdi_total_score_BL ~ a11 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              stai_total_score_BL ~ a12 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              loneliness_total_score_BL ~ a2 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              bis15_total_score_BL ~ a3 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+              
+              # Mediators: Mediator -> Risk behaviour
+              rb_sub_noz_FU ~ su11 * bdi_total_score_BL
+              rb_sub_noz_FU ~ su12 * stai_total_score_BL
+              rb_sub_noz_FU ~ su2 * loneliness_total_score_BL
+              rb_sub_noz_FU ~ su3 * bis15_total_score_BL
+              
+              rb_sex_noz_FU ~ se11 * bdi_total_score_BL
+              rb_sex_noz_FU ~ se12 * stai_total_score_BL
+              rb_sex_noz_FU ~ se2 * loneliness_total_score_BL
+              rb_sex_noz_FU ~ se3 * bis15_total_score_BL
+              
+              audit_sumscore_FU ~ au11 * bdi_total_score_BL
+              audit_sumscore_FU ~ au12 * stai_total_score_BL
+              audit_sumscore_FU ~ au2 * loneliness_total_score_BL
+              audit_sumscore_FU ~ au3 * bis15_total_score_BL
+              
+              # Covariances
+              bdi_total_score_BL ~~ stai_total_score_BL
+              bdi_total_score_BL ~~ loneliness_total_score_BL
+              bdi_total_score_BL ~~ bis15_total_score_BL
+              stai_total_score_BL ~~ loneliness_total_score_BL
+              stai_total_score_BL ~~ bis15_total_score_BL
+              loneliness_total_score_BL ~~ bis15_total_score_BL
+               
+              rb_sub_noz_FU ~~ rb_sex_noz_FU
+              rb_sub_noz_FU ~~ audit_sumscore_FU
+              rb_sex_noz_FU ~~ audit_sumscore_FU
+              
+              # Indirect effect: Trauma -> Mediator -> Risk behaviour
+              a11su11 := a11 * su11
+              a12su12 := a12 * su12
+              a2su2 := a2 * su2
+              a3su3 := a3 * su3
+              
+              a11se11 := a11 * se11
+              a12se12 := a12 * se12
+              a2se2 := a2 * se2
+              a3se3 := a3 * se3
+              
+              a11au11 := a11 * au11
+              a12au12 := a12 * au12
+              a2au2 := a2 * au2
+              a3au3 := a3 * au3
+              
+              # Total effect: Trauma -> Mediator -> Risk behaviour
+              total_su11 := c1 + (a11 * su11)
+              total_su12 := c1 + (a12 * su12)
+              total_su2 := c2 + (a2 * su2)
+              total_su3 := c3 + (a3 * su3)
+              
+              total_se11 := c1 + (a11 * se11)
+              total_se12 := c1 + (a12 * se12)
+              total_se2 := c2 + (a2 * se2)
+              total_se3 := c3 + (a3 * se3)
+              
+              total_au11 := c1 + (a11 * au11)
+              total_au12 := c1 + (a12 * au12)
+              total_au2 := c2 + (a2 * au2)
+              total_au3 := c3 + (a3 * au3)
+                  "

I tried creating the interaction effects outside lavaan:

path_comp$int_m_bs <- path_comp$bdi_total_score_BL * path_comp$stai_total_score_BL
path_comp$int_m_bl <- path_comp$bdi_total_score_BL * path_comp$loneliness_total_score_BL
path_comp$int_m_bb <- path_comp$bdi_total_score_BL * path_comp$bis15_total_score_BL
path_comp$int_m_sl <- path_comp$stai_total_score_BL * path_comp$loneliness_total_score_BL
path_comp$int_m_sb <- path_comp$stai_total_score_BL * path_comp$bis15_total_score_BL
path_comp$int_m_lb <- path_comp$loneliness_total_score_BL * path_comp$bis15_total_score_BL

path_comp$int_o_suau <- path_comp$rb_sub_noz_FU * path_comp$audit_sumscore_FU

I then added these interactions to my code:

> specmod_comp <-  "
+               # Direct effect: Trauma -> Substance 
+               rb_sub_noz_FU ~ c1 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               rb_sex_noz_FU ~ c2 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               audit_sumscore_FU ~ c3 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               
+               # Mediators: Trauma -> Mediator
+               bdi_total_score_BL ~ a11 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               stai_total_score_BL ~ a12 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               loneliness_total_score_BL ~ a2 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               bis15_total_score_BL ~ a3 * trauma_sum_crit_BL + age_BL + education_gr + monkeypox_FU
+               
+               **# Interaction between mediators
+               int_m_bs ~ int1 * bdi_total_score_BL * stai_total_score_BL
+               int_m_bl ~ int2 * bdi_total_score_BL * loneliness_total_score_BL
+               int_m_bb ~ int3 * bdi_total_score_BL * bis15_total_score_BL
+               int_m_sl ~ int4 * stai_total_score_BL * loneliness_total_score_BL
+               int_m_sb ~ int5 * stai_total_score_BL * bis15_total_score_BL
+               int_m_lb ~ int6 * loneliness_total_score_BL * bis15_total_score_BL
+               
+               # Interaction between outcomes
+               int_o_suau ~ int7 * rb_sub_noz_FU * audit_sumscore_FU**
+               
+               # Mediators: Mediator -> Risk behaviour
+               rb_sub_noz_FU ~ su11 * bdi_total_score_BL
+               rb_sub_noz_FU ~ su12 * stai_total_score_BL
+               rb_sub_noz_FU ~ su2 * loneliness_total_score_BL
+               rb_sub_noz_FU ~ su3 * bis15_total_score_BL
+               
+               rb_sex_noz_FU ~ se11 * bdi_total_score_BL
+               rb_sex_noz_FU ~ se12 * stai_total_score_BL
+               rb_sex_noz_FU ~ se2 * loneliness_total_score_BL
+               rb_sex_noz_FU ~ se3 * bis15_total_score_BL
+               
+               audit_sumscore_FU ~ au11 * bdi_total_score_BL
+               audit_sumscore_FU ~ au12 * stai_total_score_BL
+               audit_sumscore_FU ~ au2 * loneliness_total_score_BL
+               audit_sumscore_FU ~ au3 * bis15_total_score_BL
+               
+               # Indirect effect: Trauma -> Mediator -> Risk behaviour
+               a11su11 := a11 * su11
+               a12su12 := a12 * su12
+               a2su2 := a2 * su2
+               a3su3 := a3 * su3
+               
+               a11se11 := a11 * se11
+               a12se12 := a12 * se12
+               a2se2 := a2 * se2
+               a3se3 := a3 * se3
+               
+               a11au11 := a11 * au11
+               a12au12 := a12 * au12
+               a2au2 := a2 * au2
+               a3au3 := a3 * au3
+               
+               # Total effect: Trauma -> Mediator -> Risk behaviour
+               total_su11 := c1 + (a11 * su11)
+              total_su12 := c1 + (a12 * su12)
+             total_su2 := c2 + (a2 * su2)
+              total_su3 := c3 + (a3 * su3)
+              
+              total_se11 := c1 + (a11 * se11)
+              total_se12 := c1 + (a12 * se12)
+              total_se2 := c2 + (a2 * se2)
+              total_se3 := c3 + (a3 * se3)
+              
+              total_au11 := c1 + (a11 * au11)
+              total_au12 := c1 + (a12 * au12)
+              total_au2 := c2 + (a2 * au2)
+              total_au3 := c3 + (a3 * au3)
+                   " 

This resulted in the following error message:

Warning: lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigateError in lavaanify(model = FLAT, constraints = constraints, varTable = DataOV,  : 
  lavaan ERROR: wrong number of arguments in modifier (int1,bdi_total_score_BL) of element int_m_bs~stai_total_score_BL
MrFlick
  • 195,160
  • 17
  • 277
  • 295
linduru
  • 11
  • 1

1 Answers1

0

Does anybody know where I have to add the interaction effects in my model specification?

The way you did it is fine. But if you only have 2-way interaction terms, lavaan's model.syntax does recognize the colon operator that is recognized in formula objects.

mod <- 'Y ~ X + W + X:W'
fit <- sem(mod, data = ...)

This triggers lavaan to calculate the product term for you, and add it to the covariance matrix (and mean vector) that the model tries to reproduce.

This resulted in the following error message:

It was a warning, not an error. If you want to avoid it, you can divide variables with large SDs by a meaningful constant (e.g., 10 or 100), so their slopes are interpreted in 10s or 100s of the original units. Variables with large scales will be compounded by multiplication, so that is probably why the warning occurs only after adding product terms.

Terrence
  • 780
  • 4
  • 7