Mediation Analysis
Every method in this course answered one question: does the treatment work, and by how much. This last lesson asks a different one: how does it work? When FreshCart's push notification lifts grocery spend, is it because the notification gets people to open the app more and browse, or because the notification itself reminds them of a sale they buy on the spot? Same total effect, two very different stories, and they call for two very different decisions.
Mediation analysis splits a total effect into the part that travels through a middle variable (a mediator) and the part that does not. By the end of this lesson you will be able to:
- Tell a total, a direct, and an indirect effect apart, and say what each one means
- Decompose an effect in R with the product method, and put a confidence interval on the indirect piece
- Explain why mediation leans on an assumption even a perfect randomized experiment cannot deliver
Prerequisites: Lessons 1 to 3 of this course (confounding and potential outcomes, matching, difference-in-differences), and Lesson 2 where the mediator first appeared as the middle of a chain \(X \to Z \to Y\). You can fit lm() and read a coefficient.
A total effect hides a mechanism
FreshCart, the online grocery from Lesson 10, runs a clean A/B test on lapsing shoppers: a random half receive a re-engagement push notification, the other half receive nothing. A week later, the shoppers who got the push spent about $10.59 more on average. Randomization did its job, so that $10.59 is a real causal total effect, with no confounding of the push to worry about.
But "the push adds $10.59" does not tell the product team what to build. There are two ways it could happen:
- The indirect route. The push nudges shoppers to open the app more often. More app opens mean more browsing, and more browsing means more in the basket. Here the effect flows through app opens: push \(\to\) opens \(\to\) spend.
- The direct route. The push itself carries a "20% off today" line, and some shoppers tap straight through and buy, no extra browsing needed. Here the effect skips the mediator entirely: push \(\to\) spend.
App opens is the mediator, the variable in the middle of the indirect route. In Lesson 2 you met exactly this shape, a chain \(X \to Z \to Y\), and the rule was "leave the mediator alone when you want the total effect." This lesson is the payoff: when the mechanism is the question, you deliberately open up that chain and measure each piece. Switch the diagram below to mediator to see the shape we are about to take apart.