zepid.causal.causalgraph.dag.DirectedAcyclicGraph¶
-
class
zepid.causal.causalgraph.dag.
DirectedAcyclicGraph
(exposure, outcome)¶ -
__init__
(exposure, outcome)¶ Constructs a Directed Acyclic Graph (DAG) for determination of adjustment sets
Parameters: - exposure (str) – Exposure of interest in the causal diagram
- outcome (str) – Outcome of interest in the causal diagram
- TODO add other implementations in the future... have as self.mediator, self.censor, self.missing (#) –
Examples
Setting up environment
>>> from zepid.causal.causalgraph import DirectedAcyclicGraph
Creating directed acyclic graph
>>> dag = DirectedAcyclicGraph(exposure="X", outcome="Y") >>> dag.add_arrow(source="X", endpoint="Y") >>> dag.add_arrow(source="V", endpoint="Y") >>> dag.add_arrows(pairs=(("W", "X"), ("W", "Y")))
Determining adjustment sets
>>> dag.calculate_adjustment_sets() >>> dag.adjustment_sets >>> dag.minimal_adjustment_sets
Plot diagram
>>> dag.draw_dag() >>> plt.show()
Assess arrow misdirections that result in the chosen adjustment set being invalid
>>> dag.assess_misdirections(chosen_adjustment_set=set("W"))
References
Shrier I, & Platt RW. (2008). Reducing bias through directed acyclic graphs. BMC medical research methodology, 8(1), 70.
Methods
__init__
(exposure, outcome)Constructs a Directed Acyclic Graph (DAG) for determination of adjustment sets add_arrow
(source, endpoint)Add a single arrow to the current causal DAG add_arrows
(pairs)Add a set of arrows to the current causal DAG add_from_networkx
(network)assess_misdirections
(chosen_adjustment_set)Arrow direction can potentially be misspecified. calculate_adjustment_sets
()Determines all sufficient adjustment sets for the causal diagram using the algorithm described in Shrier & Platt “Reducing bias through directed acyclic graphs” BMC Medical Research Methodology 2008. draw_dag
([positions, invert, fig_size, …])Draws the current input causal DAG -