Understanding Mediation and Moderation Analysis
SEM

Understanding Mediation and Moderation Analysis

March 8, 202510 min read

A practical guide to testing indirect effects, conditional effects, and moderated mediation using PROCESS macro and lavaan in R.

What is Mediation?

Mediation analysis tests whether the effect of an independent variable (X) on a dependent variable (Y) operates through a third variable called the mediator (M). For example: does job satisfaction (X) affect turnover intention (Y) through organisational commitment (M)? In a mediation model, the total effect of X on Y is decomposed into a direct effect (X → Y) and an indirect effect (X → M → Y). The indirect effect represents the mechanism or process through which X influences Y.

What is Moderation?

Moderation occurs when the strength or direction of the relationship between X and Y depends on a third variable (W), called the moderator. For example: the effect of training on performance may be stronger for employees with high motivation than low motivation. Statistically, moderation is tested by including an interaction term (X×W) in the regression model. If the interaction is significant, moderation exists. Probing techniques like the Johnson-Neyman method and simple slopes analysis reveal at which levels of W the effect of X on Y is significant.

The PROCESS Macro

The PROCESS macro, developed by Andrew F. Hayes, is the most widely used tool for mediation and moderation analysis in SPSS, SAS, and R. It provides over 90 pre-built models covering simple mediation (Model 4), simple moderation (Model 1), moderated mediation (Model 7, 8, 14, 15), and more complex conditional process models. PROCESS uses bootstrapping (typically 5,000 or 10,000 resamples) to construct confidence intervals for indirect effects, which is preferred over the older Sobel test because it does not assume normality of the indirect effect.

Mediation in lavaan (R)

In R, you can run mediation analysis using lavaan. Define the model with regression paths: "M ~ a*X" and "Y ~ c_prime*X + b*M", then define the indirect effect: "indirect := a*b" and total effect: "total := c_prime + a*b". Fit the model with sem(model, data=df, se="bootstrap", bootstrap=5000). The bootstrapped confidence interval for the indirect effect tells you whether mediation is significant — if the interval does not include zero, the indirect effect is statistically significant.

Interpreting and Reporting Results

When reporting mediation results, include: the total effect (c path), the direct effect (c' path), the indirect effect (a×b) with its bootstrap confidence interval, and the proportion of the total effect mediated. For moderation, report the interaction coefficient, its significance, and simple slopes or Johnson-Neyman results. Use visual plots to illustrate moderation effects. Follow APA 7th edition guidelines and always include effect sizes alongside significance tests.

Common Pitfalls

Avoid claiming causation from cross-sectional mediation — temporal precedence (X occurs before M, which occurs before Y) is necessary for causal mediation claims. Be cautious about interpreting partial mediation as definitive evidence of a specific mechanism. When running moderated mediation, ensure your sample size is adequate — underpowered interaction tests have high Type II error rates. Finally, always centre or standardise your variables before creating interaction terms to reduce multicollinearity.

SEM