Graph

class pqp.graph.Graph(edges=[])

Bases: object

A causal graph

The best way to create a Graph is using the <= and & infix operators. When you use these operators between Variable s, they create a DirectedEdge or BidirectedEdge respectively.

Example: The Front-Door Model
>>> x, y, m = make_vars("xym")
>>> g = Graph([
...     m <= x,
...     y <= m,
...     y & x,
... ])
Example: The Back-Door Model
>>> x, y, z = make_vars("xyz")
>>> g = Graph([
...     y <= [x, z],
...     x <= z,
... ])

You can use the identify method to identify a causal estimand. The estimand can either be passed as an expression or as an instance of AbstractCausalEstimand, such as ATE or CATE.

Example

>>> x = Variable("X")
>>> y = Variable("Y")
>>> g = Graph([
...     y <= x,
... ])
>>> g.identify(ATE([y], [x]))
P(y | x)
Parameters:

edges (list of DirectedEdge or BidirectedEdge) – the edges in the graph

Methods Summary

add_edge(edge)

Adds an edge to the graph

draw()

Draws the causal diagram using networkx (must be installed).

Methods Documentation

add_edge(edge)

Adds an edge to the graph

Parameters:

edge (DirectedEdge or BidirectedEdge) – the edge to add

draw()

Draws the causal diagram using networkx (must be installed).