Three binary variables follow the DAG X → Y, X → Z, Y → Z: P(X = 1) = p, P(Y = 1 | x) = expit(a0 + a1x) and P(Z = 1 | x, y) = expit(b0 + bxx + byy). Conditioning (passive): among the runs in which Y happened to equal y, how often is Z = 1? That is P(Z = 1 | Y = y) = ∑x f(1 | x, y) f(x | y). Intervening (active): change the program so that Y is set to y; the arrow X → Y is cut, X keeps its own distribution, and P(Z = 1 | Y := y) = ∑x f(1 | x, y) f(x). The two differ because X, a common cause of Y and Z, is distributed differently among the units with Y = y. Both programs run below with a seeded generator; their running estimates converge to the two different exact values.
Observational program (seed s): for each run draw x, then y given x, then z given (x, y). Interventional program (seed s + 1): draw x, then z given (x, y) with y fixed; one uniform decides z under both settings y = 0 and y = 1, so each run also shows a unit's two counterfactual outcomes. Exact values by the two sums above.
code/ch17_directed_graphs.py (binary_scm_exact, binary_scm_sim, intervene; Figure 17.S1).