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.
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.
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?
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.
| Point | What is needed | If it is not met |
|---|---|---|
| Three numeric variables | An 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 logic | X 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 size | The 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 mediator | M 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 answers | Cases missing any of the three variables are left out. | Check missing values first. |
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.
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.
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.
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.
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.
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.
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.
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.
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.
| Verdict | When it applies |
|---|---|
| Full mediation | The indirect effect is clear and the direct effect is not. |
| Partial mediation | Both the indirect and direct effects are clear and point the same way. |
| Suppression | The indirect and direct effects point opposite ways, so the total is smaller than either. |
| No mediation | The indirect effect is not clear. |
| Mediation detected | The 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. |
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.
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.
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 module classifies the result in plain words.
The module also draws the bootstrap results, so you can see how steady the indirect effect is across resamples.
Open Structural Equation Modelling and choose Mediation Analysis. The module is marked Beta.
| Panel | What it shows | What to look for |
|---|---|---|
| Effect table | Indirect, direct and total effects, raw and standardised, with intervals. | Whether the indirect interval avoids zero. The share mediated. |
| Path table | Paths a, b, c and c-prime, with standard errors and p-values. | Whether each path is clear and points the way you expected. |
| Diagram | X, M and Y with the paths. | A quick picture of the result. |
| Bootstrap chart | The spread of the indirect effect over the resamples. | A spread clearly away from zero. |
| Sobel test | z and p for the indirect effect. | Use it to compare, not as the main test. |
| Verdict and interpretation | Full, partial, suppression, none or mediation detected, in words. | A first draft. Check the numbers. |
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.
| Path | Estimate | Standard error | p-value | Standardised |
|---|---|---|---|---|
| a: sessions → coping skills | 1.601 | 0.103 | < 0.001 | 0.54 |
| b: coping skills → well-being (with sessions held fixed) | 0.565 | 0.044 | < 0.001 | 0.50 |
| c: sessions → well-being (total) | 1.411 | 0.126 | < 0.001 | 0.42 |
| c′: sessions → well-being (direct) | 0.507 | 0.133 | < 0.001 | 0.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 | Estimate | 95% CI | Clear effect |
|---|---|---|---|
| Indirect (a × b) | 0.904 | 0.73 to 1.09 | Yes |
| Direct (c′) | 0.507 | Yes | |
| Total (c) | 1.411 | Yes |
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.
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.
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.
Open Structural Equation Modelling in AnalyZ Solutions. Free to sign up, free to analyze.
Get started