as $\sum_{X,M} p(Y | a,M,X) p(M | a,X) p(X)$. The mean difference between $Y(a)$ and $Y(a')$ for some treatment value $a$ of interest and reference value $a'$ is ${\mathbb{E}}[Y(a)] - {\mathbb{E}}[Y(a')]$ and quantifies the *average causal effect* of treatment $A$ on the outcome $Y$.

Mediation Analysis and Path-Specific Effects
--------------------------------------------

An important goal in causal inference is to understand the mechanisms by which some treatment $A$ influences some outcome $Y$. A common framework for studying mechanisms is *mediation analysis* which seeks to decompose the effect of $A$ on $Y$ into the *direct effect* and the *indirect effect* mediated by a third variable, or more generally into components associated with particular causal pathways. As an example, the direct effect of $A$ on $Y$ in Fig. \[fig:graphs\](a) corresponds to the effect along the edge $A \rightarrow Y$ and the indirect effect corresponds to the effect along the path $A \rightarrow M \rightarrow Y$, mediated by $M$.

In the potential outcome notation, the direct and indirect effects can be defined using nested counterfactuals such as $Y(a, M(a'))$ for $a, a' \in {\mathfrak X}_A$, which denotes the value of $Y$ when $A$ is set to $a$ while $M$ is set to whatever value it 