Moderated Mediation with categorical moderator

Hi I'm trying to make the following moderated mediation but I'm missing the final step on testing differences between groups. The code below tests the indirect effects for each level of the categorical variable, but I have no clue how to test if the indirect effect differs between categories.

I want to test the indirect effect of "Spatial" on "MCUnd" through "TotCorr" in which "Condition" moderates the effect of "Spatial" on "TotCorr".

"Spatial", "TotCorr" and "MCUnd" are all continuous and "Condition" is categorical with four categories.

This is what I have:

# Now it's time to do the actual moderated mediation. First
# I created a model/object representing the treatment variable
# (spatial ability) to the mediator variable (dynamic). As it
# is a moderated mediation, SA is interacting with condition in this model

medmod.fit <- lm(TotCorr ~ Spatial * Condition, data=Masters)

# I then create a model/object for the effect from mediator
# to Y (Multiple Choice Understanding scores), again, as it
# is a modmed, variables are crossed with condition.

outmod.fit <- lm(MCUnd ~ TotCorr + Spatial * Condition +
TotCorr * Condition, data=Masters)

# At this point I run one overall mediation analysis and four
# mediation analyses that split the data by condition. This is
# consistent with Tingley, Yamamoto, Koole, & Imai (2012)

medmod <- mediate(medmod.fit, outmod.fit, treat = "Spatial",
mediator = "TotCorr")

medmod.cond1 <- mediate(medmod.fit, outmod.fit, treat = "Spatial",
mediator = "TotCorr", covariates = list(Condition = 1))

medmod.cond2 <- mediate(medmod.fit, outmod.fit, treat = "Spatial",
mediator = "TotCorr", covariates = list(Condition = 2))

medmod.cond3 <- mediate(medmod.fit, outmod.fit, treat = "Spatial",
mediator = "TotCorr", covariates = list(Condition = 3))

medmod.cond4 <- mediate(medmod.fit, outmod.fit, treat = "Spatial",
mediator = "TotCorr", covariates = list(Condition = 4))

#This is just an overall summary
summary(medmod)

# This is a summary of the mediation effects for each of the four
# conditions. If there is moderated mediation, the mediation effects
# should be different across conditions. I do find that there
# mediation effects in conditions 2 and 3(moderate effect), but no
# mediation effect in conditions 1 and 4.

summary(medmod.cond1)
summary(medmod.cond2)
summary(medmod.cond3)
summary(medmod.cond4)


Thank you!

-

migrated from stackoverflow.comJul 7 '13 at 1:23

This question came from our site for professional and enthusiast programmers.

What is it that you actually need help with? It's hard to tell what your actual question is here. If its a code question, can you provide a toy data frame to work with? We don't know what your Masters data looks like. An example of output that you're expecting to see would also be helpful (if it differs from the actual output). If its a more general "hey am I using this statistical technique correctly" question, consider adding the [statistics], or more relevant tags. –  Manetheran Jul 5 '13 at 3:32
Ah sorry, yes I just don't think this is the correct way to do this. Is there a way to do this type of ModMed where you get some sort of comparison of the mediation effect across conditions. –  user2438475 Jul 5 '13 at 4:19
Unfortunately im not well versed in mediator variables so i can't help you. –  Manetheran Jul 5 '13 at 4:24
The code above works perfectly fine, technically, but what it's doing is separating the dataset by condition and doing four separate mediation analyses. I was thinking there should be a better way to do this. –  user2438475 Jul 5 '13 at 4:24
Well thank you for letting me know I should add some extra information! –  user2438475 Jul 5 '13 at 4:25