Developing a better understanding of the processes we observe in the world around us often involves gaining insight into the causal pathways through which effects operate (mediation) and the contexts or conditions under which these processes occur (moderation). For example, education may improve health partly by increasing income, which in turn enables access to better living conditions and healthcare. This is an example of a mediated process. At the same time, the strength of the relationships may differ across groups (moderation): the income gains associated with education may be larger for men than for women, or may translate into health improvements only at certain ages. Such complex processes can be described as moderated mediation or mediated moderation.
In this guide, we will explore how to use multi-group structural equation modelling (SEM) in R to estimate and interpret concurrent processes of mediation and moderation.
Access the code used here.
Access the data here.
What are moderated mediation and mediated moderation?
Moderated mediation refers to situations in which a mediation effect varies across contexts or cases. In other words, the question is not only if the effect of X on Y goes through a mediator, but also in what context does the effect appear (the mediator).
Using the figure below as a guide, we can start with the basic mediated model (Panel A), where X affects Y partly through a mediator M. Panels B–D then introduce moderation at different stages of this process. For example, in first-stage mediated moderation (Panel B), the moderator Z changes the strength of the X–M relationship. This means that the indirect effect of X on Y via M depends on Z. Conceptually, Z does not act directly on the outcome, but instead shapes how strongly the mediator is activated by X.
Similarly, in second-stage mediated moderation (Panel C), Z moderates the M to Y path, implying that the mediator matters more (or less) for specific values of Z. More complex cases (Panels D–H) allow moderation at multiple stages, including the direct effect, but the unifying idea remains the same: the mediation process depends on a moderator.

Although the terms are often used interchangeably, they emphasise different starting points. Mediated moderation begins with a moderation effect and asks whether a mediator can explain that effect — that is, what mechanism accounts for the interaction? Moderated mediation, by contrast, begins with a mediation process and asks whether the indirect effect varies across levels of a moderator — that is, for whom or under what conditions does the mediation operate? Statistically, the models overlap, although conceptually the processes are different. When choosing between these two concepts, it is best to use theory and prior research to guide the interpretation’s focus.
Estimating moderated mediation using path analysis
In a previous guide, we saw that path analysis, or SEM, is an excellent framework for investigating mediation effects. We also explored moderation using two strategies: interactions and multi-group analysis. Here, we will combine these ideas to estimate mediated moderation using multi-group SEM.
To illustrate mediated moderation in practice, we estimate a simple mediation model to examine how the effect of education (degree) on mental health is mediated by income. We will also explore whether this mediation process differs by gender. Specifically, we will test whether the paths in the mediation model differ between men and women, indicating mediated moderation.
The set-up of the mediation model is similar to the one we discussed before. We will also analyse this separately for men and women by adding the option group = "gndr.fct". This will run the model separately for men and women:
library(lavaan)
model <- 'sf12mcs_1 ~ degree.fct + logincome_1
logincome_1 ~ degree.fct'
fit <- sem(model, data = usw, group = "gndr.fct")
summary(fit, standardized = TRUE)## Group 1 [Male]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sf12mcs_1 ~ ## degree.fct -0.270 0.145 -1.860 0.063 -0.270 -0.013 ## logincome_1 0.338 0.043 7.869 0.000 0.338 0.056 ## logincome_1 ~ ## degree.fct -0.767 0.023 -33.636 0.000 -0.767 -0.227 ## ## Group 2 [Female]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sf12mcs_1 ~ ## degree.fct -1.651 0.140 -11.825 0.000 -1.651 -0.074 ## logincome_1 -0.111 0.045 -2.491 0.013 -0.111 -0.016 ## logincome_1 ~ ## degree.fct -0.711 0.019 -38.136 0.000 -0.711 -0.228
For both men and women, higher educational attainment is associated with lower income, and the magnitude of this relationship is very similar across groups. Where the models differ is in how income and education relate to mental health. Among men, income is positively associated with mental health, while the direct effect of education on mental health is close to zero. Among women, by contrast, income is weakly negatively related to mental health, and education has a substantially stronger direct negative association with mental health.
Taken together, these patterns indicate that the overall effect of education on mental health differs by gender, not only in size but also in mechanism, with income acting as a positive mediator for men but not for women.
To better understand the relationships we have found, we can put the results in a SEM diagram:

Note that I present the standardised coefficients (the last column in the output) because they are easier to compare across groups. Also, the grey arrow indicates a relationship that is not statistically significant.
Testing the differencess across groups
Using this framework, we can also test whether the mediation process is the same for men and women by fitting constrained models that force certain paths to be equal across groups, and then comparing them to the unconstrained model. For example, let’s examine whether the effect of logincome on mental health is statistically significant across groups (second-stage moderation model).
We will run a model where we restrict the coefficient to be equal by giving it the same label in both groups (c(b, b)):
model <- 'sf12mcs_1 ~ degree.fct + c(b, b)*logincome_1
logincome_1 ~ degree.fct'
fit2 <- sem(model, data = usw, group = "gndr.fct")
summary(fit2, standardized = TRUE)## Group 1 [Male]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sf12mcs_1 ~ ## degree.fct -0.436 0.143 -3.038 0.002 -0.436 -0.021 ## logincom_1 (b) 0.122 0.031 3.944 0.000 0.122 0.020 ## logincome_1 ~ ## degree.fct -0.767 0.023 -33.636 0.000 -0.767 -0.227 ## ## Group 2 [Female]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sf12mcs_1 ~ ## degree.fct -1.485 0.138 -10.775 0.000 -1.485 -0.067 ## logincom_1 (b) 0.122 0.031 3.944 0.000 0.122 0.017 ## logincome_1 ~ ## degree.fct -0.711 0.019 -38.136 0.000 -0.711 -0.228
In the output, we see that the unstandardized coefficient for logincome is 0.12 in both groups. To formally test whether this constraint decreases the model fit, we can compare the two models:
anova(fit, fit2)
## ## Chi-Squared Difference Test ## ## Df AIC BIC Chisq Chisq diff RMSEA Df diff Pr(>Chisq) ## fit 0 524463 524586 0.000 ## fit2 1 524513 524627 52.511 52.511 0.046645 1 4.279e-13 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC and BIC are both higher in the constrained model, indicating a worse fit. The chi-square difference test is also statistically significant, indicating that the restricted model fits significantly worse than the unconstrained model. This is an indication that moderated mediation is present in the data.
We could test each relationship separately, or we could do an overall test to see if the entire mediation process differs by group (total effect moderation model, panel H in the figure above).
Below, we expand the model, restrict all paths, and then compare the model with no restriction to the new one.
model <- 'sf12mcs_1 ~ c(c, c)*degree.fct + c(b, b)*logincome_1
logincome_1 ~ c(a, a)*degree.fct'
fit3 <- sem(model, data = usw, group = "gndr.fct")
anova(fit, fit3)## ## Chi-Squared Difference Test ## ## Df AIC BIC Chisq Chisq diff RMSEA Df diff Pr(>Chisq) ## fit 0 524463 524586 0.000 ## fit3 3 524542 524638 84.696 84.696 0.033915 3 < 2.2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
As expected, the overall test also shows that the constrained model fits significantly worse than the unconstrained one, again implying the presence of moderated mediation.
Estimating indirect and total effects
Finally, now that we know that the relationships are significantly different across groups, we can estimate group-specific indirect and total effects by labelling the paths separately for men and women:
model <- 'sf12mcs_1 ~ c(cm, cf)*degree.fct + c(bm, bf)*logincome_1
logincome_1 ~ c(am, af)*degree.fct
# indirect effect (a*b)
abm := am*bm
abf := af*bf
# total effect
totalm := cm + (am*bm)
totalf := cf + (af*bf)'
fit <- sem(model, data = usw, group = "gndr.fct")
summary(fit, standardized = TRUE)Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
abm -0.260 0.034 -7.662 0.000 -0.260 -0.013
abf 0.079 0.032 2.485 0.013 0.079 0.004
totalm -0.530 0.142 -3.740 0.000 -0.530 -0.026
totalf -1.572 0.136 -11.560 0.000 -1.572 -0.071The results show a clear process of mediated moderation. For men, the indirect effect of education on mental health via income is negative and statistically significant, while for women, the indirect effect is positive but much smaller. The total effect of education on mental health is substantially more negative for women than for men, indicating that both the size and the mechanism of the effect differ across groups.
Want to learn more?
Using continuous variables for moderated mediation
So far, we have used gender as a moderator by fitting the mediation model separately for men and women. The same idea works when the moderator is continuous. There are multiple ways to do this in practice; here, we turn age into three groups (young, middle, old), then fit a multi-group mediation model with age as the grouping variable.
# make three age groups
usw <- usw |>
mutate(age_grp = case_when(
age < 35 ~ "young",
age >= 35 & age < 55 ~ "middle",
age >= 55 ~ "old"
)) |>
mutate(age_grp = factor(age_grp,
levels = c("young", "middle", "old")))The mediation model will examine the effect of living in an urban area on satisfaction with life, with income as the mediating variable. The hypothesis is that the effect of urban residence on satisfaction is mediated by income and that the process varies by age.
model <- 'sati_1 ~ urban.fct_1 + logincome_1
logincome_1 ~ urban.fct_1'
fit_sati <- sem(model, data = usw, group = "age_grp")
summary(fit_sati, standardized = TRUE)## Group 1 [young]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sati_1 ~ ## urban.fct_1 -0.081 0.035 -2.332 0.020 -0.081 -0.021 ## logincome_1 -0.022 0.007 -3.251 0.001 -0.022 -0.030 ## logincome_1 ~ ## urban.fct_1 -0.093 0.046 -1.995 0.046 -0.093 -0.018 ## ## Group 2 [old]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sati_1 ~ ## urban.fct_1 -0.070 0.029 -2.445 0.015 -0.070 -0.022 ## logincome_1 0.023 0.011 2.012 0.044 0.023 0.018 ## logincome_1 ~ ## urban.fct_1 -0.055 0.022 -2.441 0.015 -0.055 -0.022 ## ## Group 3 [middle]: ## ## Regressions: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## sati_1 ~ ## urban.fct_1 -0.219 0.030 -7.207 0.000 -0.219 -0.059 ## logincome_1 0.081 0.010 8.431 0.000 0.081 0.069 ## logincome_1 ~ ## urban.fct_1 -0.023 0.026 -0.860 0.390 -0.023 -0.007
Again, we can visualise the results to understand better the processes involved:

In all three groups, urban residence is negatively associated with life satisfaction. Still, the magnitude of this direct effect varies substantially across the life course, being strongest among the middle-aged group. The role of income as a mediator also differs by age. For younger respondents, higher income is associated with slightly lower life satisfaction, whereas for older respondents, especially middle-aged respondents, income is positively related to satisfaction. At the same time, the association between urban residence and income is weak and statistically non-significant for the middle-aged group, indicating that income does not meaningfully mediate the urban–satisfaction relationship at midlife.
Overall, the figure shows that age moderates both the direct and indirect pathways (i.e., moderated mediation), with the strength and even the direction of the mediation process changing across age groups.
Testing differences across groups
Based on these results, we could investigate further whether the mediation process differs statistically across age groups by fitting constrained models. We could do this for each path by including restrictions across two or three groups at a time. This would enable testing specific hypotheses. Here, to make things simple, we will do another overall test to see if the entire mediation process is the same across groups:
model <- 'sati_1 ~ c(c, c, c)*urban.fct_1 + c(b, b, b)*logincome_1
logincome_1 ~ c(a, a, a)*urban.fct_1'
fit_sati2 <- sem(model, data = usw, group = "age_grp")
anova(fit_sati, fit_sati2)## ## Chi-Squared Difference Test ## ## Df AIC BIC Chisq Chisq diff RMSEA Df diff Pr(>Chisq) ## fit_sati 0 278422 278602 0.000 ## fit_sati2 6 278504 278633 94.399 94.399 0.033495 6 < 2.2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The results show that the constrained model fits significantly worse than the unconstrained model, indicating that the mediation process differs across age groups (i.e., moderated mediation).
Calculating indirect and total effects across groups
To better understand how the mediation process differs across groups, we can calculate the direct and indirect effects for each group:
model <- 'sati_1 ~ c(cy, co, cm)*urban.fct_1 + c(by, bo, bm)*logincome_1
logincome_1 ~ c(ay, ao, am)*urban.fct_1
# indirect effect (a*b)
aby := ay*by
abo := ao*bo
abm := am*bm
# total effect
totaly := cy + (ay*by)
totalo := co + (ao*bo)
totalm := cm + (am*bm)'
fit_sati <- sem(model, data = usw, group = "age_grp")Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
aby 0.002 0.001 1.700 0.089 0.002 0.001
abo -0.001 0.001 -1.553 0.121 -0.001 -0.000
abm -0.002 0.002 -0.855 0.392 -0.002 -0.000
totaly -0.079 0.035 -2.272 0.023 -0.079 -0.021
totalo -0.071 0.029 -2.488 0.013 -0.071 -0.022
totalm -0.221 0.030 -7.249 0.000 -0.221 -0.060The results show that the indirect effects of urban residence on life satisfaction via income are small and statistically non-significant across all age groups. However, the total effects differ substantially, with the strongest negative effect observed among the middle-aged group. This suggests that while income does not meaningfully mediate the urban–satisfaction relationship at any age, the overall impact of urban residence on life satisfaction is most pronounced in midlife.
When including continuous moderators, it is essential to remember that the multi-group approach requires categorising the moderator, which can lead to loss of information and statistical power. Alternative methods, such as using interaction terms within a single-group SEM framework, may be more appropriate when the moderator is continuous and the sample size is large enough. Alternatively, we could run sensitivity analyses with different codings of the moderator to ensure robust results.
Conclusions
Moderated mediation provides a powerful way to move beyond simply documenting that “effects differ by group” toward understanding how and where those differences arise within a causal system. Multi-group SEM offers a flexible framework for investigating mediation and moderation concurrently. It also enables fine-grained hypothesis testing and facilitates interpretation.
Was the information useful?
Consider supporting the site:
