liveBook · Manning

Directed acyclic graph

As explained in Causal AI

DAG is a graph class representing a directed acyclic graph and operations on its nodes and edges.

Suppose you want to estimate whether encouraging side-quest engagement increases in-game purchases. A correlation between engagement and purchases cannot answer that question on its own: player skill or time spent playing might affect both. A causal directed acyclic graph (DAG) makes proposed cause-and-effect relationships explicit before estimation. Each node is a variable; a directed edge points from a proposed cause to a variable it affects. The graph is acyclic: its arrows do not form a directed loop. section 11.2 section 13.1.1

Build the graph around the causal question, not merely around available predictors:

  • Identify the treatment and outcome, then add plausible common causes. For side-quest engagement and purchases, these include player skill and time spent playing. section 11.2
  • Add other variables according to their proposed causal roles. Group assignment and customization level may serve as instruments; total inventory is a collider and can introduce bias if handled as an ordinary adjustment variable. section 11.2
  • Check the assumptions behind each arrow with domain knowledge. A DAG states what is proposed to cause what; observed correlation alone does not establish an arrow. section 13.1.1

Why the arrows matter for fairness

A loan dataset might show higher rejection rates for men for two different reasons: advertising attracted less-qualified male applicants, or loan officers penalized men. A DAG distinguishes these proposed routes to the same statistical disparity. Removing gender from a training table does not, by itself, remove patterns carried by proxies such as names. section 1.3.4

Listing 11.1 Build the causal DAG
import pygraphviz as pgv     #1
from IPython.display import Image    #2

causal_graph = """
digraph {
    "Prior Experience" -> "Player Skill Level";
    "Prior Experience" -> "Time Spent Playing";
    "Time Spent Playing" -> "Player Skill Level";
    "Guild Membership" -> "Side-quest Engagement";
    "Guild Membership" -> "In-game Purchases";
    "Player Skill Level" -> "Side-quest Engagement";
    "Player Skill Level" -> "In-game Purchases";
    "Time Spent Playing" -> "Side-quest Engagement";
    "Time Spent Playing" -> "In-game Purchases";
    "Side-quest Group Assignment" -> "Side-quest Engagement";
    "Customization Level" -> "Side-quest Engagement";
    "Side-quest Engagement" -> "Won Items";
    "Won Items" -> "In-game Purchases";
    "Won Items" -> "Total Inventory";
    "In-game Purchases" -> "Total Inventory";
}
"""     #3
G = pgv.AGraph(string=causal_graph)   #3
G.draw('/tmp/causal_graph.png', prog='dot')    #4
Image('/tmp/causal_graph.png')    #5

The Graphviz DOT listing makes the gaming model concrete: each arrow declares a proposed causal relationship, and PyGraphviz loads the specification for visualization. section 11.2

In an effect-estimation workflow, the DAG is the model used for identification, not the estimate itself. A valid backdoor adjustment set blocks all backdoor paths; front-door and instrumental-variable approaches require different assumptions. The graph can also anchor a structural causal model, which adds functions describing how parent variables determine each modeled variable. An arrow can express a causal assumption, but it cannot by itself express a claim such as linearity. section 11.7 section 10.1.2

How Causal AI covers it

How deep it goes
Develops graph construction and its role in identification, while leaving functional mechanisms such as linearity outside the graph.
Examples
Uses loan-approval bias, gaming purchases, and a smoking–lung cancer graph to illustrate causal arrows.
What it assumes
Assumes a causal question and candidate variables, while introducing nodes and directed edges explicitly.
What you can do after
Apply it via DoWhy by specifying a DAG and using its assumptions to identify candidate causal-effect estimands.
How it connects
Connects DAGs to confounders, colliders, instrumental variables, backdoor adjustment, and structural causal models.

Also explained in

Compare how 15 books explain directed acyclic graph →

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.