CausalGraphs.jl

CausalGraphs.jl is a Julia package for graph-based causal identification, semiparametric effect estimation, and missing-data weighting in acyclic directed mixed graphs (ADMGs) and missingness DAGs (mDAGs). It includes estimator-routing checks for a-fixable, p-fixable, and nested-fixable effects, plus symbolic Pearl-Shpitser ID for more general ADMG queries and finite-support plug-in estimation with EIF CIs for discrete ID functionals.

It brings together ideas and workflows from Anna Guo and Razieh Nabi's R packages flexCausal and flexMissing, rewritten and adapted for Julia.

Installation

using Pkg
Pkg.add(url="https://github.com/xiangao/CausalGraphs.jl")

Quick Start

using CausalGraphs, DataFrames, Random

Random.seed!(1)
n = 500
X = randn(n)
A = Float64.(rand(n) .< 1 ./ (1 .+ exp.(-X)))
Y = 2 .* A .+ X .+ randn(n)
data = DataFrame(X=X, A=A, Y=Y)

graph = make_graph(
    vertices = [:X, :A, :Y],
    di_edges = [(:X, :A), (:X, :Y), (:A, :Y)],
)

identify(graph, :A, :Y).strategy
:a_fixable
result = estimate_causal(
    a = [1, 0],
    data = data,
    graph = graph,
    treatment = :A,
    outcome = :Y,
)

result[:TMLE].ACE
2.0321394471141216

Vignettes

VignetteDescription
Graphs and IdentificationADMG construction, visualization, graph properties, and identify() routing
General ADMG ID AlgorithmSymbolic Pearl-Shpitser ID, finite-support plug-in estimation with EIF CIs, hedge failures, and fixing diagnostics
Berkeley Admissions with IDReal-data front-door ADMG, Pearl-Shpitser ID functional, finite-support plug-in estimation with EIF CIs, and non-identification sensitivity
Estimation: Backdoor and Front-DoorBackdoor/a-fixable and front-door/p-fixable estimation workflows
Nested-Fixable and Missing DataNested-fixable effects, ANIPW/NIPW, and missing-data weighting with mDAGs
Smoking Cessation NHEFSEnd-to-end real-data workflow: hypothesize a graph, identify, estimate, and compare assumptions
Job Training NSWEconomics example: experimental assignment, measured selection, unmeasured selection, identification, and estimation
Job Search Mediation JOBS IIEconomics mediation example: DAG, total-effect estimation, and natural direct and indirect effects

Core API

  • make_graph
  • draw_graph
  • to_mermaid
  • identify
  • ID_algorithm
  • estimate_id
  • estimate_causal
  • estimate_causal_npcausal
  • make_mdag
  • compute_missing_weights

Optional NPCausal.jl Bridge

estimate_causal_npcausal(...) keeps identification in CausalGraphs.jl and, when NPCausal.jl is also installed and loaded, delegates supported estimation to NPCausal.admg_estimate_causal.

using Pkg
Pkg.add(url="https://github.com/xiangao/NPCausal.jl")

using CausalGraphs, NPCausal

graph = make_graph(
    vertices = [:A, :M, :Y],
    di_edges = [(:A, :M), (:M, :Y)],
    bi_edges = [(:A, :Y)],
)

res = estimate_causal_npcausal(
    a = [1, 0],
    data = data,
    graph = graph,
    treatment = :A,
    outcome = :Y,
    nsplits = 5,
)

r = x -> round(x, sigdigits=4)
(ACE = r(res[:TMLE].ACE),
 lower_ci = r(res[:TMLE].lower_ci),
 upper_ci = r(res[:TMLE].upper_ci))

The bridge covers backdoor/a-fixable effects via NPCausal.ate, p-fixable effects via NPS TMLE, nested-fixable effects via ANIPW, and finite-support discrete ID-algorithm functionals via :IDPlugin.

References

  • Anna Guo and Razieh Nabi, flexCausal: causal effect estimation in ADMGs with hidden variables.
  • Anna Guo and Razieh Nabi, flexMissing: weighting-based identification and estimation in graphical models of missing data.