Search code examples
rr-lavaanprocessr

How adjust a moderated moderated mediation model with processR package?


I want adjust a moderated moderated mediation model with lavaan and processR packages. The model is follow:

enter image description here

I tried to create the following moderations:

Innovativeness:Age

and

PBC:Innovativeness:Age

My data (df):

df <- structure(list(Attitude = structure(c(33, 30, 37, 29, 36, 42, 
27, 35, 35, 27, 22, 25, 42, 25, 38, 35, 38, 36, 34, 40), label = "Attitude", format.spss = "F8.2"), 
    SubNorm = structure(c(46, 53, 30, 27, 55, 37, 14, 55, 55, 
    57, 37.4, 48, 68, 43, 55, 39, 51.7, 36, 51.7, 60), label = "Subjective Norm", format.spss = "F8.2"), 
    PBC = structure(c(50, 50, 45, 38, 48, 41, 34, 40, 47, 42, 
    22, 38, 56, 42, 48, 38, 33, 30, 46, 45), label = "Perceived Behavior Control", format.spss = "F8.2"), 
    Intent = structure(c(21, 17, 14, 15, 15, 21, 18, 18, 19, 
    15, 10, 12, 21, 10, 19, 15, 21, 21, 19, 21), label = "Intention", format.spss = "F8.2"), 
    Behavior = structure(c(59, 36, 44, 35, 62, 60, 38, 38, 68, 
    42, 35, 16, 77, 24, 73, 35, 64, 35, 69, 60), label = "Behavior", format.spss = "F8.2"), 
    Religiosity = c(28L, 28L, 24L, 30L, 19L, 25L, 23L, 21L, 20L, 
    15L, 21L, 20L, 21L, 17L, 27L, 29L, 24L, 23L, 17L, 25L), Education = c(45L, 
    55L, 46L, 28L, 52L, 48L, 48L, 55L, 53L, 30L, 60L, 31L, 31L, 
    33L, 46L, 58L, 53L, 55L, 38L, 27L), Innovativeness = c(38L, 
    39L, 37L, 54L, 40L, 49L, 30L, 53L, 58L, 45L, 59L, 32L, 43L, 
    49L, 57L, 59L, 37L, 54L, 52L, 43L), Age = c(46L, 35L, 27L, 
    33L, 42L, 56L, 49L, 42L, 41L, 31L, 31L, 43L, 45L, 59L, 44L, 
    57L, 28L, 48L, 28L, 55L)), row.names = c(NA, -20L), class = c("tbl_df", 
"tbl", "data.frame"))

I tried this:

library(lavaan)
library(processR)

md_1 <- tripleEquation(
  labels = list(X = "PBC", M = "Intent", Y = "Behavior"), 
  covar = list(name = c("SubNorm", "Attitude"), 
               site = c("M", "M")),
  moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'), 
               site = list('a', 'a2', 'b'))
)

a2 is the flow of Innovativeness (W) - see statistical diagram image.

Analysis:

fit_1 <- sem(
  model = md_1, 
  estimator = 'ML', 
  data = df, 
  se = 'bootstrap', 
  bootstrap = 10,
  fixed.x = TRUE
  )

But:

estimatesTable(fit_1)
   Variables         Predictors label     B   SE     z       p     β
1     Intent                PBC    a1 -0.16 0.44 -0.37   0.711 -0.31
2     Intent     Innovativeness    a2 -0.01 0.22 -0.02   0.982 -0.01
3     Intent PBC:Innovativeness    a3  0.00 0.01 -0.02   0.982 -0.02
4     Intent                Age    a4 -0.06 0.15 -0.41   0.681 -0.16
5     Intent            PBC:Age    a5  0.00 0.00  0.67   0.506  0.34
6     Intent            SubNorm    f1  0.03 0.04  0.69   0.492  0.09
7     Intent           Attitude    f2  0.44 0.08  5.82 < 0.001  0.78
8   Behavior                PBC     c  0.72 0.52  1.37   0.171  0.33
9   Behavior             Intent    b1  0.98 2.67  0.37   0.714  0.23
10  Behavior        Religiosity    b2  0.08 2.05  0.04   0.967  0.02
11  Behavior Intent:Religiosity    b3  0.02 0.11  0.21   0.834  0.17

The flows Innovativeness:Age and PBC:Innovativeness:Age were not produced.

How adjust this line:

moderator = list(name = c('Innovativeness', 'Age', 'Religiosity'), 
                 site = list('a', 'a2', 'b'))

to get these desired flows?

Thanks.


Solution

  • I finally got an answer to your question. And as there is no other answer on this or any other sites, I'll post my solution.

    What you're missing is vars argument, where you identify the variables that should be in the triple interaction. So in your case you have a model 25, and there should be triple interaction WZX. General template for model 25 is the following (just replace with your variable names in the strings):

    moderator <- list(name=c('W', 'Z', 'V'), 
                      site=list(c('a'), c('a'), c('b')))
    
    # Next part forces the triple interaction
    # Two variables, both on the site 'a'
    # X is added to these two variables to form a triple interacion
    vars <- list(name=list(c('W', 'Z')), 
                 site=list(c('a', 'a')))
    
    model1 <- tripleEquation(X='X',
                             M='M',
                             Y='Y',
                             moderator=moderator,
                             vars=vars)
    

    Next, let's output the formula.

    cat(model1)
    

    What you can observe is that there is indeed a new term: a7*interaction0. This interaction0 is the triple interaction between W, Z and X. But, your data does not have a column interaction0, so you have to make one.

    df$interaction0 <- df$W * df$Z * df$X
    

    Only now can you run the following to fit the model and output it.

    semfit <- sem(model=model1, data=df)
    summary(semfit)
    

    This works for models 11, 12, 13, 18, 19, 20, 25, 26, 27, 32, 33, 34, 37, 38, 39, 42, 43, 44, 46, 47, 48, 51, 52, 53, 54, 55, 56, 57...