Identification Algorithms
CausalDynamics.backdoor_adjustment_set — Function
backdoor_adjustment_set(g, X, Y)Find a valid backdoor adjustment set for estimating the causal effect of X on Y.
Delegates to CausalInference.find_min_backdoor_adjustment. Returns nothing if no valid set exists (false from CausalInference).
Arguments
g: Directed acyclic graphX: Treatment nodeY: Outcome node
Returns
Set{Int}of adjustment nodes (possibly empty if no backdoors), ornothing
CausalDynamics.is_backdoor_adjustable — Function
is_backdoor_adjustable(g, X, Y)Return true if a backdoor adjustment set exists (including the empty set when there are no backdoor paths).
CausalDynamics.frontdoor_adjustment_set — Function
frontdoor_adjustment_set(g, X, Y, M)Check if M is a valid frontdoor adjustment set for estimating the causal effect of X on Y.
The frontdoor criterion states that a set M is a valid frontdoor adjustment set if:
- M blocks all directed paths from X to Y
- There are no backdoor paths from X to M
- All backdoor paths from M to Y are blocked by X
Uses reachability (BFS), not path enumeration — safe on dense DAGs.
Arguments
g: Directed acyclic graphX: Treatment nodeY: Outcome nodeM: Potential mediator set
Returns
trueif M is a valid frontdoor adjustment set,falseotherwise
CausalDynamics.find_frontdoor_mediators — Function
find_frontdoor_mediators(g, X, Y)Find single-node frontdoor mediators between X and Y.
Candidates are nodes on some directed path X → Y (nodes_on_directed_paths), checked with frontdoor_adjustment_set. Avoids enumerating all simple paths.
CausalDynamics.find_instruments — Function
find_instruments(g, X, Y)Find instrumental variables for estimating the causal effect of X on Y.
An instrumental variable Z must satisfy:
- Z has a causal effect on X
- Z affects Y only through X (exclusion restriction)
- Z is independent of confounders of X and Y (independence)
Arguments
g: Directed acyclic graphX: Treatment nodeY: Outcome node
Returns
- Vector of potential instrumental variables
Examples
using CausalDynamics, Graphs
# IV example
g = DiGraph(4)
add_edge!(g, 1, 2) # Z → X
add_edge!(g, 2, 3) # X → Y
add_edge!(g, 4, 2) # U → X
add_edge!(g, 4, 3) # U → Y
# Z is a valid instrument
instruments = find_instruments(g, 2, 3) # [1]References
- Angrist, J. D., & Pischke, J. S. (2009). Mostly Harmless Econometrics
CausalDynamics.is_valid_instrument — Function
is_valid_instrument(g, Z, X, Y)Check if Z is a valid instrumental variable for X → Y.
An instrument Z must satisfy three conditions:
- Relevance: Z has a causal effect on X (directed path Z → X)
- Exclusion restriction: Z affects Y only through X (all paths Z → Y go through X)
- Independence: Z is independent of confounders (no backdoor paths Z → Y)
Arguments
g::AbstractGraph: Directed acyclic graphZ::Int: Potential instrument nodeX::Int: Treatment nodeY::Int: Outcome node
Returns
Bool:trueif Z is a valid instrument,falseotherwise
Examples
using CausalDynamics, Graphs
# Valid instrument
g = DiGraph(4)
add_edge!(g, 1, 2) # Z → X
add_edge!(g, 2, 3) # X → Y
add_edge!(g, 4, 2) # U → X
add_edge!(g, 4, 3) # U → Y
is_valid_instrument(g, 1, 2, 3) # true
# Invalid: Z has direct path to Y
g2 = DiGraph(3)
add_edge!(g2, 1, 2) # Z → X
add_edge!(g2, 1, 3) # Z → Y (violates exclusion)
add_edge!(g2, 2, 3) # X → Y
is_valid_instrument(g2, 1, 2, 3) # falseNotes
- The independence condition (3) is checked conservatively: if any backdoor paths exist, returns
false - In practice, independence may hold even with backdoor paths if they are blocked
References
- Angrist, J. D., & Pischke, J. S. (2009). Mostly Harmless Econometrics, Chapter 4
CausalDynamics.find_all_adjustment_sets — Function
find_all_adjustment_sets(g, X, Y)List valid backdoor adjustment sets via CausalInference.list_backdoor_adjustment.
CausalDynamics.is_valid_adjustment_set — Function
is_valid_adjustment_set(g, X, Y, Z)Check if Z is a valid backdoor adjustment set via CausalInference.
CausalDynamics.minimal_adjustment_set — Function
minimal_adjustment_set(g, X, Y)Minimal backdoor adjustment set (same as backdoor_adjustment_set).