library(CausalStructures)

Equivalence Classes
Source: vignettes/articles/equivalence-classes.qmd
Equivalence classes of graphs arise in several settings, for instance, during causal discovery algorithms. This guide covers the graph classes that represent such classes and how to work with them.
Equivalence classes of DAGs
A PDAG (partially directed acyclic graph) is a graph whose edges may be directed or undirected, with no directed cycles. Two DAGs are Markov equivalent if and only if they have the same skeleton and the same v-structures (unshielded colliders).
Each Markov equivalence class of DAGs has a unique CPDAG (completed partially directed acyclic graph) representation. In a CPDAG, an edge is directed precisely when it has the same orientation in every DAG in the equivalence class; otherwise it remains undirected.
Given a DAG, dag_to_cpdag() computes its CPDAG:
dag <- cgraph(C %-->% X, A %-->% X + Y, Y %-->% Z)
cpdag <- dag_to_cpdag(dag)
plot(cpdag)
The v-structure C --> X <-- A appears in every DAG in the equivalence class and therefore remains directed. The edges A --- Y and Y --- Z are undirected because no v-structure or Meek rule forces their orientation.
count_dags() tells us how many DAGs are in the class, and enumerate_dags() lists them all:
count_dags(cpdag)
#> [1] 3enumerate_dags(cpdag)
#> [[1]]
#> DAG with 5 nodes and 4 edges:
#> nodes: A, C, X, Y, Z
#> edges:
#> A --> X, C --> X, A --> Y, Y --> Z
#>
#> [[2]]
#> DAG with 5 nodes and 4 edges:
#> nodes: A, C, X, Y, Z
#> edges:
#> Y --> A, A --> X, C --> X, Y --> Z
#>
#> [[3]]
#> DAG with 5 nodes and 4 edges:
#> nodes: A, C, X, Y, Z
#> edges:
#> Y --> A, A --> X, C --> X, Z --> YWhen you need one concrete DAG to work with, dag_from_pdag() picks one:
dag_from_pdag(cpdag)
#> DAG with 5 nodes and 4 edges:
#> nodes: A, C, X, Y, Z
#> edges:
#> C --> X, A --> X, A --> Y, Y --> ZYou can compute adjustment sets on a CPDAG, and the result is valid for every DAG in the equivalence class:
all_adjustment_sets(cpdag, "X", "Z")
#> [[1]]
#> [1] "A"
#>
#> [[2]]
#> [1] "Y"An MPDAG (maximally oriented partially directed acyclic graph) can, for instance, arise when background knowledge is incorporated during causal discovery, orienting some edges of a CPDAG.
meek_closure() propagates all further orientations implied by Meek’s rules on a PDAG to obtain an MPDAG:
Here, X --- C was oriented to X --> C using Meek’s rules.
All the functions shown above work on any PDAG, CPDAG or MPDAG:
count_dags(pdag)
#> [1] 2
all_adjustment_sets(mpdag, "X", "Z")
#> [[1]]
#> [1] "A"
#>
#> [[2]]
#> [1] "Y"Every CPDAG represents a non-empty Markov equivalence class, so it always admits at least one consistent DAG extension and dag_from_pdag() is guaranteed to succeed. This is not true for a general PDAG or MPDAG: being acyclic (and, for an MPDAG, closed under Meek’s rules) is not sufficient to ensure a consistent extension exists. For example, a chordless undirected cycle is a valid PDAG and MPDAG, yet it cannot be oriented into a DAG without introducing a new v-structure:
Equivalence classes of MAGs
Maximal ancestral graphs (MAGs) naturally arise when some common causes are unobserved: every latent common cause between two observed nodes becomes a bidirected edge (<->) in the MAG. Two MAGs are Markov equivalent if they encode the same conditional independence structure over the observed variables.
Each Markov equivalence class of MAGs has a unique PAG (partial ancestral graph). Like a CPDAG for DAGs, the PAG marks each endpoint with the symbol shared by every MAG in the class. A circle (o) at an endpoint means that mark is not invariant; some MAGs in the class have a tail there and others have an arrowhead.
Consider a MAG where A and B share a hidden common cause, C directly causes B, and B directly causes D:
mag_to_pag() computes the PAG representing the Markov equivalence class of this MAG, so all MAGs that encode the same conditional independences:
pag <- mag_to_pag(mag)
pag
#> PAG with 4 nodes and 3 edges:
#> nodes: A, B, C, D
#> edges:
#> A o-> B, C o-> B, B --> DThe arrowheads at B on the A-B and C-B edges are invariant: A, B, and C form an unshielded collider at B (since A and C are non-adjacent), so every MAG in the class has an edge pointing into B from both sides. The circle marks at A and C are not invariant; the A-B edge could be A --> B or A <-> B, and similarly for C. The B --> D edge is invariant via Zhang’s orientation rule R1: since A and D are non-adjacent and A o-> B --> D, the tail at B is forced in all MAGs.
enumerate_mags() lets you explore the equivalence class:
enumerate_mags(pag)
#> [[1]]
#> MAG with 4 nodes and 3 edges:
#> nodes: A, B, C, D
#> edges:
#> A --> B, C --> B, B --> D
#>
#> [[2]]
#> MAG with 4 nodes and 3 edges:
#> nodes: A, B, C, D
#> edges:
#> A <-> B, C --> B, B --> D
#>
#> [[3]]
#> MAG with 4 nodes and 3 edges:
#> nodes: A, B, C, D
#> edges:
#> A --> B, B <-> C, B --> D
#>
#> [[4]]
#> MAG with 4 nodes and 3 edges:
#> nodes: A, B, C, D
#> edges:
#> A <-> B, B <-> C, B --> DYou can also answer various causal inference questions, see PAG Causal Effects for some examples.