liveBook · Manning

Counterfactual graph

As explained in Causal AI

A counterfactual graph is a graph formed by collapsing equivalent nodes across the intervention worlds of a parallel world graph while retaining nodes relevant to a counterfactual query.

Suppose a customer received a treatment, but you want to know what their outcome would have been without it. The question combines a factual condition with a hypothetical outcome. A counterfactual graph puts variables from those worlds into one query-specific DAG so their relationships can be examined. section 10.10 section 10.7.2

Start with a parallel world graph and the events in the query. Identify variables that must have the same value across worlds because the intervention does not affect them, then collapse their nodes. Keep the nodes relevant to the query. This matters because an uncollapsed parallel world graph can misleadingly suggest, through d-separation, that two copies of the same unaffected variable are independent. D-separation can instead be used on the counterfactual graph. section 10.7.2 section 9.1.3

An effect on the treated

Consider P(A_{T=−t}=+a | T=+t): among cases that received treatment, ask about the outcome under no treatment. The events A_{T=−t}=+a and T=+t determine the counterfactual graph. Adding further events need not change its structure: the illustrated expanded query, which also includes B=−b and V_{B=−b}=+v, produces the same graph. The graph supports reasoning about identification; constructing it does not itself establish that the query is identifiable. section 10.7.2 section 10.7.5

Listing 10.10 Listing 10.10 Counterfactual graph events AT=–t=+a and T=+t
from y0.algorithm.identify.cg import make_counterfactual_graph

events = {A @ -t: +a, T: +t}    #1
cf_graph, _ = make_counterfactual_graph(dag, events)
gv_draw(cf_graph)

The Y0 listing turns the factual and hypothetical events into a counterfactual graph from a causal DAG. section 10.7.2

Counterfactual graphs are used for graphical identification, including queries that can be graphed but not identified from lower-level data. A single-world intervention graph (SWIG) is a different option: it splits a node, retains all original variables, and relies on a single-world assumption. Counterfactual graphs instead collapse equivalent nodes across worlds and retain those relevant to a particular query. section 10.10 section 10.7.5

How Causal AI covers it

How deep it goes
Explains construction by collapsing equivalent parallel-world nodes and demonstrates Y0 graph creation, without treating graph construction as proof of identification.
Examples
Uses an effect-on-the-treated query, an expanded query with the same graph, and Python code that constructs and draws the graph.
What it assumes
Assumes causal DAGs, interventions, counterfactual queries, and d-separation; explains why parallel-world nodes must sometimes be merged.
What you can do after
Apply it via Y0 to construct a query-specific graph and assess cross-world relationships while checking identification separately.
How it connects
Connects parallel world graphs, d-separation, graphical identification, causal DAGs, and single-world intervention graphs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.