Suppose an online game wants to estimate purchases if side-quest engagement were set to low. Filtering data to players with low engagement asks an observational question; setting engagement to low asks an interventional one. A do function transforms a causal model to represent that imposed value, after which an inference algorithm estimates the resulting distribution. section 10.8 section 11.6.2
Operationally, an ideal intervention fixes the target variable and removes its incoming causal influence. In a graph this is graph surgery. PyMC’s do function effectively replaces the target’s sampling expression with a constant. Pyro’s do function instead uses node-splitting: the imposed value influences children while a factual random variable retains the parents. For ordinary interventional queries, the two behave alike; node-splitting also supports certain counterfactual queries under an additional single-world assumption. section 11.6.1
A causal-generative-model workflow separates the intervention from the calculation:
- Specify a causal model and, for estimation rather than model-only inference, estimate its parameters from data. Check that the target query is identified under the model’s causal assumptions. section 10.8 section 11.6
- Apply do to set the target value, then run probabilistic inference on the transformed model. To ask about a hypothetical outcome for people with a different observed value, also condition on that factual value. section 11.6.2 section 10.8
Engagement and purchases
For P(purchases under engagement = 0), apply do(model, {"Side-quest Engagement": 0}) and sample purchases. For P(purchases under engagement = 0 | engagement = 1), additionally condition the intervention model on observed engagement = 1 before sampling. The second query asks about a selected factual group, not everyone under the intervention. section 10.8 section 11.6.2
Figure 11.13 The node-splitting transform splits the intervention target into a constant that keeps the children and a random variable that keeps the parents.
The node-splitting diagram distinguishes the imposed value passed to children from the factual variable that retains its parents. section 11.6.1
The same action step works in a parallel-world counterfactual model: intervene on a hypothetical switching strategy, retain evidence that a player stayed and lost, then use variable elimination to infer the hypothetical result. The reported probability of winning is 1 for that evidence. Applying do alone does not establish a causal effect: identification depends on the causal assumptions, and estimation additionally requires data. section 9.2.4 section 10.8 section 11.6
