Quantitative Analysis/ Structural Equation Modelling
Through what step does an effect work?

Mediation Analysis: How to find out whether an effect works through a middle step

Mediation analysis asks whether one variable affects another through a middle step, and how much of the effect goes that way. This guide covers the ideas, the calculations, every part of the output, the assumptions that matter, a worked example and how to report it.

20 min read Structural equation modelling Intermediate

01What is mediation analysis?

Mediation analysis asks how or why one thing affects another. It looks for a middle step. If counselling improves well-being, does it do so by building coping skills? Mediation analysis splits the effect into the part that goes through that middle step and the part that does not.

The middle step is called the mediator. The cause is the exposure, often written X. The result is the outcome, often written Y.

An example

A programme offers counselling sessions to 600 adults. Each person attended between 0 and 12 sessions. You also have a coping skills score and a well-being score, both measured later. People who attended more sessions report higher well-being. You want to know three things. How big is the total effect of one more session? How much of it goes through coping skills? And does counselling help in other ways, beyond coping skills?

What you get out of it

  1. Indirect effect
    The part of the effect that goes through the mediator.
  2. Direct effect
    The part that remains after the mediator is taken into account.
  3. Total effect
    The two added together. It is the plain effect of X on Y.
  4. Share mediated
    The portion of the total effect that goes through the mediator.
  5. A verdict in words
    Whether mediation is full, partial or not supported.

02When to use it

Use it when you have a reason to think one variable works through another, and when X, M and Y are all numeric. Typical cases are programme theories, where an activity is expected to change something in people, and that change is expected to change a result.

If your mediator or outcome is a yes or no variable, if you want to take other variables into account, or if you have more than one mediator, use counterfactual mediation. If you have a longer chain, use path analysis.

Mediation needs a time order. The exposure should come first, then the mediator, then the outcome. If all three were measured at once, the analysis still runs, but it cannot tell which way the influence goes.

03What you need before you start

Requirements and what happens if they are not met
PointWhat is neededIf it is not met
Three numeric variablesAn exposure (X), a mediator (M) and an outcome (Y). All three are numeric and all three are different variables.For yes or no or ordered variables, covariates, or more mediators, use counterfactual mediation.
Order in time or logicX comes before M, and M before Y. A mediator is something X changes, and that in turn changes Y.If M could just as well come first, the analysis cannot tell the two stories apart.
Sample sizeThe more the better. The example has 600 cases and a tight interval. With a few dozen cases the interval is wide.Intervals are wide, and the bootstrap becomes unstable.
Measured mediatorM is measured, not guessed. It should be measured reliably.Noise in M weakens the indirect effect and moves the rest to the direct effect.
Missing answersCases missing any of the three variables are left out.Check missing values first.

04The idea in a picture

Figure 1 shows the three parts. Arrow a is the effect of the exposure on the mediator. Arrow b is the effect of the mediator on the outcome. The direct effect is what is left of the exposure effect once the mediator is held fixed.

Figure 1. The three parts of a mediation modelThree boxes. Counselling sessions point to coping skills with arrow a. Coping skills point to well-being with arrow b. Counselling sessions also point straight to well-being with the direct effect.Counsellingsessions (X)Coping skills(mediator, M)Well-being(outcome, Y)a = 1.60b = 0.56direct = 0.51
Figure 1. The three parts of a mediation model, with the values from the example

The route through the mediator is the indirect effect. It takes arrow a and then arrow b. The route that skips the mediator is the direct effect.

05How it is calculated

Two regressions

Two regressions give all the pieces. The first predicts the mediator from the exposure and gives a. The second predicts the outcome from the exposure and the mediator together. It gives b and the direct effect c′. A third regression of the outcome on the exposure alone gives the total effect c.

Multiplying and adding

indirect effect = a × b
total effect = direct effect + indirect effect
share mediated = indirect effect / total effect

In the example, a is 1.601 and b is 0.565, so the indirect effect is 1.601 × 0.565 = 0.904. The direct effect is 0.507. Together they make 0.507 + 0.904 = 1.411, which is the total effect from the third regression. The share mediated is 0.904 ÷ 1.411 = 0.64.

Is the indirect effect real?

The indirect effect is a product of two estimates, so its uncertainty is not simple. The module uses a bootstrap. It draws many new samples from your data, works out the indirect effect in each, and takes the middle 95% of the results as the interval. If the interval does not include zero, the indirect effect is supported.

The module also reports the Sobel test, an older formula-based check. The bootstrap interval is the one to rely on, because the Sobel test assumes the indirect effect has a bell-shaped spread, which it often does not.

06The model in more detail

The three regressions

M = a × X + error (path a)
Y = c' × X + b × M + error (paths c-prime and b)
Y = c × X + error (the total effect, path c)

In the example, counselling sessions (X) raise coping (M) by 1.601 points per session. Holding coping fixed, each point of coping is linked to 0.565 points of wellbeing (Y). With coping held fixed, the direct effect of counselling is 0.507. Without holding coping fixed, the total effect is 1.411.

Why total = direct + indirect

indirect effect = a × b
total effect c = direct effect c' + a × b

Check with the example: 1.601 × 0.565 = 0.904, and 0.507 + 0.904 = 1.411, which is the total effect 1.411. The share mediated is 0.904 ÷ 1.411 = 64%. The module gives this share only when the indirect and total effects point the same way. If they point opposite ways, a percentage would mislead.

The interval for the indirect effect

A product of two uncertain numbers does not have a bell-shaped spread, so the usual interval is not suitable. The module uses the bootstrap. It draws 2,000 new samples of the same size from your data, with cases picked at random and replaced each time. It runs the analysis on each sample, giving 2,000 indirect effects. The middle 95% of them, from the 2.5th to the 97.5th percentile, is the interval: 0.73 to 1.09. If it does not include zero, there is a clear indirect effect. You can choose the number of resamples. More give steadier intervals and take longer.

The Sobel test, and why it is not the main test

standard error of a × b = square root of ( b² × se(a)² + a² × se(b)² )
Sobel z = a × b / standard error

In the example, the standard error is the square root of (0.565² × 0.103² + 1.601² × 0.044²) = 0.092, and z = 0.904 ÷ 0.092 = 9.8. The Sobel test assumes a bell-shaped spread for the product, which is not true in small or moderate samples, so the bootstrap interval is the one to report. The module shows the Sobel result for comparison.

How the verdict is decided

The verdict in words
VerdictWhen it applies
Full mediationThe indirect effect is clear and the direct effect is not.
Partial mediationBoth the indirect and direct effects are clear and point the same way.
SuppressionThe indirect and direct effects point opposite ways, so the total is smaller than either.
No mediationThe indirect effect is not clear.
Mediation detectedThe indirect effect is clear but the total effect is not. A clear indirect effect with an unclear total can happen when the direct effect cancels it.

Assumptions that matter more than the numbers

The arithmetic is simple. What makes a mediation result believable is a set of assumptions the data cannot check. All four need to hold for the indirect effect to be read as a cause-and-effect result.

Randomising X removes the first and third problems, but not the second. This is why the module suggests counterfactual mediation with a sensitivity check when you need to say how a hidden factor could change the result.

07Reading the output

The effect table

This is the main result. It lists the indirect, direct and total effects with their intervals and says which are clear. The indirect and direct effects are in the units of the outcome. They add up to the total.

The path table

It gives a, b, c and c′ with standard errors, p-values and standardised values. The standardised values are on a common scale, so a and b can be compared.

The verdict

The module classifies the result in plain words.

  1. Full mediation. The indirect effect is clear and the direct effect is not. The mediator accounts for the whole effect.
  2. Partial mediation. The indirect effect is clear and the direct effect is also clear. The mediator accounts for part of the effect.
  3. Suppression. The direct and indirect effects point in opposite directions. Read with care and consider other models.
  4. No evidence of mediation. The interval of the indirect effect includes zero.

The module also draws the bootstrap results, so you can see how steady the indirect effect is across resamples.

08How to run it in AnalyZ Solutions

Open Structural Equation Modelling and choose Mediation Analysis. The module is marked Beta.

  1. Choose the exposure (X)
    The variable you think has an effect.
  2. Choose the mediator (M)
    The variable you think carries part of the effect.
  3. Choose the outcome (Y)
    The result you care about. X, M and Y must be different numeric variables.
  4. Set the bootstrap resamples
    The default suits exploring. Use more for a final report.
  5. Click Run Mediation Analysis
    You get the effect table, the path table, a diagram, the bootstrap chart and a plain-language interpretation.
When your data come from a survey with sampling weights. With a survey weight set, the regressions use the weights, the intervals follow the survey design, and the weighted number of cases is shown.

09Reading the output, panel by panel

Every part of the Mediation Analysis output
PanelWhat it showsWhat to look for
Effect tableIndirect, direct and total effects, raw and standardised, with intervals.Whether the indirect interval avoids zero. The share mediated.
Path tablePaths a, b, c and c-prime, with standard errors and p-values.Whether each path is clear and points the way you expected.
DiagramX, M and Y with the paths.A quick picture of the result.
Bootstrap chartThe spread of the indirect effect over the resamples.A spread clearly away from zero.
Sobel testz and p for the indirect effect.Use it to compare, not as the main test.
Verdict and interpretationFull, partial, suppression, none or mediation detected, in words.A first draft. Check the numbers.

10Interpreting the result

The figures below are invented to show the steps. They come from a real run of the module on a simulated dataset of 600 adults, with 2,000 bootstrap resamples.

Paths
PathEstimateStandard errorp-valueStandardised
a: sessions → coping skills1.6010.103< 0.0010.54
b: coping skills → well-being (with sessions held fixed)0.5650.044< 0.0010.50
c: sessions → well-being (total)1.4110.126< 0.0010.42
c′: sessions → well-being (direct)0.5070.133< 0.0010.15

Step 1: read arrows a and b. Each extra counselling session goes with 1.60 more points of coping skills (a). People with one more point of coping skills have 0.56 more points of well-being, at the same number of sessions (b). Both are clear.

Effect decomposition
EffectEstimate95% CIClear effect
Indirect (a × b)0.9040.73 to 1.09Yes
Direct (c′)0.507Yes
Total (c)1.411Yes

Step 2: read the indirect effect. The indirect effect is 0.90, with an interval of 0.73 to 1.09. The interval does not include zero, so coping skills carry part of the effect of counselling on well-being.

Step 3: read the direct effect. The direct effect is 0.51, and it is also clear. Counselling is linked to well-being beyond what coping skills explain.

Step 4: put it together. This is partial mediation. One extra session goes with 1.41 more points of well-being in total. About 64% of that runs through coping skills, and the rest does not.

In plain words

People who attended more counselling sessions reported higher well-being. Most of that gain, about two thirds, went through better coping skills. A smaller part happened in other ways that this analysis did not measure. The pattern fits the idea that counselling works largely by building coping skills. It does not prove it, because people who attend more sessions may differ in other ways.

11How to report the result

Example write-up. We tested whether the effect of counselling sessions on wellbeing works through coping skills, in 600 clients. Each extra session was linked to 1.60 more points of coping, and each point of coping to 0.56 more points of wellbeing, holding sessions fixed. The indirect effect was 0.90 (95% bootstrap interval 0.73 to 1.09, 2,000 resamples). The direct effect was 0.51 and the total effect 1.41. About 64% of the total effect went through coping, so coping partly mediates the effect. This reading assumes no important unmeasured factor affects both coping and wellbeing.

12A checklist before you trust the result

  1. X comes before M, and M before Y, by design or by logic.
  2. You can say why no outside factor drives both M and Y.
  3. The mediator was measured reliably.
  4. You report the bootstrap interval for the indirect effect, with the number of resamples.
  5. You report the direct and total effects as well.
  6. You say the share mediated only when the effects point the same way.
  7. You say "consistent with", not "proves", unless the study was randomised and M was well controlled.

13Common mistakes

Calling it proof of mechanism. A significant indirect effect is consistent with your theory. Other explanations can produce the same pattern.

Measuring everything at once. With no time order, the mediator could just as well be a result.

Ignoring other causes. If something affects both the mediator and the outcome and you did not measure it, the indirect effect can be wrong. Counterfactual mediation offers a check for how much that could matter.

Insisting that the total effect must be significant first. An indirect effect can be clear even when the total is not, for instance when two routes work in opposite directions.

Reading the share mediated as exact. It is unstable when the total effect is small, so treat it as a rough guide.

Using it for yes or no outcomes. The numbers will not mean what they seem to. Use counterfactual mediation.

Frequently Asked Questions
What is the difference between mediation and moderation?
Mediation asks how an effect works, through which middle step. Moderation asks for whom or when it works differently, such as for women compared with men.
What is the difference between direct and indirect effects?
The indirect effect goes through the mediator. The direct effect is what remains of the exposure effect after the mediator is held fixed. The two add up to the total effect.
Do I need a significant total effect first?
No. An indirect effect can be clear when the total is small, because a direct effect can pull the other way.
How many resamples should I use?
The default is fine for exploring. A thousand or more gives steadier intervals for a final report.
What if my mediator or outcome is yes or no?
Use counterfactual mediation, which handles yes or no and ordered variables.
Can I include other variables to adjust for?
Not in this module. Counterfactual mediation lets you add covariates.
Why use the bootstrap and not the Sobel test?
The Sobel test assumes the product of two numbers has a bell-shaped spread. It does not, particularly in samples under a few hundred. The bootstrap makes no such assumption.
What does "partial mediation" mean?
Some of the effect goes through the mediator and some does not. It does not say how many other mediators there are.
What is suppression?
The direct and indirect effects point opposite ways, so they partly cancel in the total. The total can then look small even when both parts are large.
Does mediation prove the mechanism?
No. It shows the data fit the mechanism. Other mechanisms or a hidden common cause can produce the same numbers.
How do I choose between this and counterfactual mediation?
Use this one for a numeric exposure, mediator and outcome with no other adjustment. Use counterfactual mediation for yes or no or ordered variables, covariates, several mediators, and a sensitivity check.

Test whether an effect works through a middle step

Open Structural Equation Modelling in AnalyZ Solutions. Free to sign up, free to analyze.

Get started
Related Guides