Written and maintained by CASRAI Editorial Board
Last updated
A moderating variable is a variable that changes the strength (and sometimes the direction) of the effect of one variable on another. If a tutoring programme raises scores more for one group of students than for another, the grouping variable is a moderator. This page gives moderating variable examples from several fields, one fully worked calculation, and a test for telling a moderator from a mediator. Method detail lives in the linked guides.
Definition of a moderating variable in one paragraph
David Kenny defines it this way: “A moderator variable M is a variable that alters the strength of the causal relationship” between a cause X and an outcome Y. Moderation answers “for whom?” or “under what conditions?” the effect holds. It does not explain how the effect arises; that is mediation, covered below. See mediator vs moderator for the full contrast.
Formula: the moderation equation, every symbol explained
Kenny’s Equation 1 is Y = i + aX + bM + cXM + E.
- Y: the outcome.
- X: the predictor (the putative cause).
- M: the moderator.
- XM: the product of X and M (the interaction term).
- i: the intercept, the expected Y when X, M and XM are all 0.
- a: the effect of X on Y when M = 0.
- b: the effect of M on Y when X = 0.
- c: the moderation effect. Kenny describes the coefficient c on the XM term as measuring the moderation effect.
- E: the error term.
Rearranged, the effect of X on Y at a given value of M is a + cM. That one expression is the whole idea: the slope of X depends on M.
Worked example with the arithmetic shown
This is an illustrative calculation with invented group means, not a research finding. Y is an exam score, X is a tutoring programme (0 = none, 1 = programme), and M is student group (0 = Group A, 1 = Group B). The four cell means are:
| Group | No programme (X = 0) | Programme (X = 1) | Programme effect |
|---|---|---|---|
| Group A (M = 0) | 60 | 70 | 70 – 60 = 10 |
| Group B (M = 1) | 62 | 64 | 64 – 62 = 2 |
With this 0/1 coding the coefficients can be read directly from the means:
- i = 60 (Group A, no programme).
- a = 70 – 60 = 10 (programme effect in Group A, where M = 0).
- b = 62 – 60 = 2 (Group B difference without the programme).
- c = (64 – 62) – (70 – 60) = 2 – 10 = -8 (the difference between the two programme effects).
Check: the fitted value for Group B with the programme is i + a + b + c = 60 + 10 + 2 – 8 = 64, which matches the table. The programme effect is a + cM = 10 in Group A and 10 + (-8) = 2 in Group B, so the group variable moderates the effect.
Continuous moderators: simple slopes
If M is continuous, the same expression a + cM gives the effect at any value. Suppose a = 0.50 and c = -0.10 per unit of M (again illustrative). At M = 2 the effect of X is 0.50 + (-0.10)(2) = 0.30; at M = 5 it is 0.50 + (-0.10)(5) = 0.00. Probing a significant interaction this way is covered in simple effects analysis after a significant interaction.
Moderating variable examples by field
Each row below is an illustrative hypothesis in the form “the effect of X on Y is larger or smaller depending on M”. They are examples of structure, not reported results, except the two Kenny cases marked as such.
| Field | X (cause) | Y (outcome) | M (moderator) | Reading |
|---|---|---|---|---|
| Clinical psychology (Kenny) | Psychotherapy | Depression | Gender | Kenny’s example: therapy may reduce depression more for men than for women. |
| Intervention research (Kenny) | An intervention | Outcome of interest | Socioeconomic status | Kenny’s example: socioeconomic status moderates the effect of some intervention. |
| Education | Tutoring programme | Exam score | Prior achievement | The score gain may shrink as prior achievement rises. |
| Public health | Exercise hours | Resting heart rate | Age | The same weekly exercise may lower heart rate by different amounts at different ages. |
| Organisational research | Job demands | Burnout | Managerial support | High demands may predict burnout less strongly when support is high. |
| Sport science | Competitive anxiety | Performance | Skill level | Anxiety may hurt novices more than experts. |
| Medicine | Drug dose | Biomarker change | Sex or genotype | The dose-response slope may differ by subgroup (called effect modification in epidemiology; see effect modification vs confounding). |
| Marketing | Discount size | Purchase intent | Brand familiarity | Discounts may matter less for familiar brands. |
Categorical versus continuous moderators
A categorical moderator (sex, treatment arm, school type) gives one effect of X per category, as in the worked example. A continuous moderator (age, income, a scale score) gives a different effect at every value, which is why researchers report effects at chosen values such as the mean and one standard deviation either side. Whether M is categorical or continuous changes how you probe the result, not the equation.
Mediating variable examples and how they differ
A mediator is a different thing: Kenny writes that the effect of X on Y “may be mediated by a process or mediating variable M, and the variable X may still affect Y.” A mediator sits on the causal path; X changes M, and M changes Y. Two attributed examples from Kenny’s mediation page:
- Morse et al. (1994): contact with housing agencies mediated the effect of intensive case management on homelessness.
- Chakraborti et al. (2022): craving mediated the effect of pharmacological smoking-cessation treatments on smoking lapse, while cessation fatigue and negative mood did not.
For testing and reporting mediation, use mediation analysis methods and reporting, path analysis and what a mediator variable is.
How to tell a moderator from a mediator
Ask one question of the variable M: would X plausibly change it?
| Question | If yes | If no |
|---|---|---|
| Could X change M? | M is a candidate mediator (a mechanism) | M is a candidate moderator (a condition) |
| Does the question ask “how or why”? | Mediation | – |
| Does the question ask “for whom or when”? | – | Moderation |
The same variable can play either role depending on the theory. Social support, for example, could be a moderator if people differ in it before stress arrives, or a mediator if stress changes how much support people receive. The theory, not the statistics, decides.
Assumptions and common mistakes
- Omitting the main effects. The equation keeps both X and M alongside XM; fitting XM alone misreads c.
- Reading a and b as overall effects. With an interaction in the model, a is the effect of X only where M = 0. Choose a meaningful zero for M (for example by centring a continuous M).
- Treating a non-significant c as proof of no moderation. An interaction estimate can be imprecise.
- Confusing moderation with confounding. A confounding variable distorts the X-Y link; a moderator changes its size.
- Splitting a continuous moderator into high and low groups only to test it, which discards information.
How to write the hypothesis and report it
A hypothesis names all three roles: “The positive effect of tutoring on exam score is weaker for students with higher prior achievement.” To report, give the interaction coefficient c with its standard error or confidence interval and p value from your software output, then the simple effects of X at the chosen values of M. Template: “The programme by group interaction was b = [c], SE = [SE], 95% CI [lower, upper], p = [p]; the programme effect was [a] in Group A and [a + c] in Group B.” Fill the brackets from your own output. For the full reporting layout see moderation analysis and interaction terms.
How to calculate it in Excel, R or Python
Each snippet fits Y = i + aX + bM + cXM + E. With the four cell means above entered as data, each returns i = 60, a = 10, b = 2, c = -8.
Excel: arrange adjacent columns A = X, B = M, C = XM, D = Y. In C2 enter =A2*B2 and fill down to row 5. Then enter =LINEST(D2:D5, A2:C5, TRUE, FALSE) as an array formula across four cells in one row. LINEST returns coefficients in reverse column order: c, b, a, then the intercept i.
R:
d <- data.frame(x = c(0,0,1,1), m = c(0,1,0,1), y = c(60,62,70,64))
coef(lm(y ~ x * m, data = d))
Python:
import pandas as pd, statsmodels.formula.api as smf
d = pd.DataFrame({"x":[0,0,1,1], "m":[0,1,0,1], "y":[60,62,70,64]})
print(smf.ols("y ~ x * m", data=d).fit().params)
Four data points fit four parameters exactly, so these snippets demonstrate the coefficients only; real analyses need many observations per cell. For PROCESS output, see PROCESS macro model numbers and reporting.
FAQ
What is an example of a moderating variable?
Sex or gender in Kenny’s example: psychotherapy may reduce depression more for men than for women, so gender alters the strength of the therapy-depression relationship.
What is an example of a mediating variable?
Craving, in Chakraborti et al. (2022) as described by Kenny: craving mediated the effect of pharmacological smoking-cessation treatments on smoking lapse.
Can a variable be both a moderator and a mediator?
One variable can be modelled either way across different hypotheses, depending on the theory. If X can change M, a mediation question is available; if M is fixed beforehand and changes the X-Y effect, it is a moderation question.
How do I know moderation is present statistically?
The interaction coefficient c in Y = i + aX + bM + cXM + E is non-zero; its estimate and uncertainty come from your regression output.
Sources
- Kenny, D. A. Moderation. https://davidakenny.net/cm/moderation.htm (checked 2026-10-29).
- Kenny, D. A. Mediation. https://davidakenny.net/cm/mediate.htm (checked 2026-10-29).
The worked example and the field table are illustrative constructions, not results from published studies, except the two cases labelled as Kenny’s.








