Graph

class pqp.identification.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

add_edges(edges)

Add multiple edges to the graph

draw()

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

identify(**kwargs)

Uses IDC to identify an arbitrary estimand

identify_ate(outcome, treatment_condition, ...)

Identifies the average treatment effect

identify_cate(outcome, treatment_condition, ...)

Identifies the conditional average treatment effect

Methods Documentation

add_edge(edge)

Adds an edge to the graph

Parameters:

edge (DirectedEdge or BidirectedEdge) – the edge to add

add_edges(edges)

Add multiple edges to the graph

Parameters:

edges (list of DirectedEdge or BidirectedEdge) – the edges to add

draw()

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

identify(**kwargs)

Uses IDC to identify an arbitrary estimand

Finds the interventional distributions in a causal estimand and replaces them with equivalent conditional probability expressions using IDC.

Parameters:

estimand (Expression) – the estimand to identify

Returns:

the identified estimand, containing no do-operators

Return type:

AbstractExpression

identify_ate(outcome, treatment_condition, control_condition)

Identifies the average treatment effect

Parameters:
  • outcome (Variable) – the outcome variable

  • treatment_condition (dict) – the treatment condition

  • control_condition (dict) – the control condition

Returns:

the identified average treatment effect

Return type:

AbstractExpression

identify_cate(outcome, treatment_condition, control_condition, subpopulation)

Identifies the conditional average treatment effect

Parameters:
  • outcome (Variable) – the outcome variable

  • treatment_condition (dict) – the treatment condition

  • control_condition (dict) – the control condition

  • subpopulation (dict) – the subpopulation condition

Returns:

the identified conditional average treatment effect

Return type:

AbstractExpression