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 betweenVariable
s, they create aDirectedEdge
orBidirectedEdge
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 ofAbstractCausalEstimand
, such asATE
orCATE
.Example
>>> x = Variable("X") >>> y = Variable("Y") >>> g = Graph([ ... y <= x, ... ]) >>> g.identify(ATE([y], [x])) P(y | x)
- Parameters:
edges (
list
ofDirectedEdge
orBidirectedEdge
) – 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
orBidirectedEdge
) – the edge to add
- add_edges(edges)¶
Add multiple edges to the graph
- Parameters:
edges (
list
ofDirectedEdge
orBidirectedEdge
) – 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 variabletreatment_condition (
dict
) – the treatment conditioncontrol_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 variabletreatment_condition (
dict
) – the treatment conditioncontrol_condition (
dict
) – the control conditionsubpopulation (
dict
) – the subpopulation condition
- Returns:
the identified conditional average treatment effect
- Return type:
AbstractExpression