Solution (source code)

= Solution

A <nonparametric structural equation model> for the graph can be written
$$
X=f_X(U_X),\qquad A=f_A(U_A),\qquad
M=f_M(A,X,U_M),\qquad Y=f_Y(M,X,U_Y).
$$
The bidirected edge $A\leftrightarrow Y$ permits dependence between $U_A$ and $U_Y$; apart from this pair the exogenous variables are mutually independent. The basic <potential outcomes> are
$$
M(a,x)=f_M(a,x,U_M),
\qquad
Y(m,x)=f_Y(m,x,U_Y),
$$
and the natural nested outcome is $Y(a)=Y(M(a,X),X)$.

The exogenous independences imply that the whole family $\{M(a,x):a,x\}$ is independent of $\{X,A,Y(m,x):m,x\}$, while $X$ is independent of $A$ and the basic response potentials. The bidirected edge means that $A$ and $Y(m,x)$ need not be independent. Useful observed-counterfactual consequences include
$$
M(a)\mathrel{\perp\!\!\!\perp}A\mid X,
\qquad
M\mathrel{\perp\!\!\!\perp}Y(m)\mid A,X.
$$