Suppose higher side-quest engagement is associated with more in-game purchases. Guild membership affects both, so that association alone does not answer what would happen if every player’s engagement were set to high. `pyro.do` creates a version of a Pyro causal model for that intervention, allowing its consequences to be simulated. section 7.1.6 section 7.1.7
Call `pyro.do(model, {"Side-quest Engagement": tensor(1.)})` to obtain a new model with engagement fixed at high; use `tensor(0.)` for low. Calling either returned model generates outcomes under its specified intervention. Unlike conditioning on players whose observed engagement was high, this operation sets engagement regardless of the causes that would ordinarily determine it. section 7.1.6 section 7.2.6
Operationally, `pyro.do` finds a targeted `pyro.sample` call and replaces its sampled value with the supplied value. This parallels replacing a target’s assignment function in a structural causal model. In a causal graphical model, the corresponding operation removes incoming edges and puts all probability on the intervention value. Other assignments remain unchanged; downstream computations can respond to the new value. The sample-site replacement describes the essential operation, not every implementation detail. section 7.2.2 section 7.2.5 section 7.2.6
Simulate two engagement policies
Create high- and low-engagement models, draw 500 purchase outcomes from each, and compare their means. In one simulation, mean purchases were about 89.9 for high engagement and 130.7 for low engagement; the corresponding experimental means were about 93.0 and 131.4. Agreement is useful evidence for this model, not a guarantee: errors in the causal DAG can make the intervention analysis wrong. section 7.1.6 section 7.1.7
Listing 7.9 Representing interventions with pyro.do
int_engaged_model = pyro.do( #1
model, #1
{"Side-quest Engagement": tensor(1.)} #1
) #1
int_unengaged_model = pyro.do( #2
model, #2
{"Side-quest Engagement": tensor(0.)} #2
) #2
The listing shows the model-and-target-value call that creates separate high- and low-engagement intervention models. section 7.1.6
The returned model also supports counterfactual workflows. For a hypothetical femur length of 46 cm, sample it with the original exogenous distribution to obtain an interventional height distribution; sample the same model with an exogenous posterior informed by observed measurements to obtain a counterfactual distribution. In a Bayesian workflow, combine intervened models with `Predictive` to estimate an average treatment effect and its posterior uncertainty. section 9.3.2 section 9.3.4 section 11.6.6
