Reference
CausalGraphs.draw_graph — Function
draw_graph(graph; direction="LR")Return a displayable graph object for an ADMG or MDAG.
Uses Graphviz (dot) to render an SVG when available — the SVG is embedded directly in HTML with no JavaScript dependency. Falls back to a Mermaid source object for environments without dot installed.
CausalGraphs.to_mermaid — Function
to_mermaid(graph; direction="LR")Return a Mermaid flowchart representation of an ADMG.
This is convenient in Quarto, Markdown, and notebook contexts that support Mermaid diagrams.
CausalGraphs.to_dot — Function
to_dot(graph; direction="LR")Return a Graphviz DOT representation of an ADMG.
Directed edges are blue. Bidirected edges, which represent hidden common causes, are red and drawn with arrowheads at both ends. Fixed vertices are drawn with square node shapes.
CausalGraphs.ID_algorithm — Function
ID_algorithm(g::ADMG, treatment, outcome)Run the Pearl-Shpitser ID algorithm for the ADMG total-effect query P(outcome | do(treatment)).
The return value is an ADMGIDResult. If identified == true, expression contains a symbolic identifying functional. If identification fails, hedge records the two district sets involved in the failure witness.
CausalGraphs.estimate_id — Function
estimate_id(; a, data, graph, treatment, outcome, [max_levels])Run the general ADMG ID_algorithm and estimate the resulting symbolic functional with the finite-support plug-in estimator.
The return value uses the :IDPlugin key. This is an automatic estimator for discrete ID functionals. It includes a finite-support delta-method EIF and Wald confidence interval for the plug-in functional. This is not a general TMLE/EIF estimator for arbitrary continuous ADMG functionals.
When sample_weights are supplied, integer-like weights are treated as frequency weights for the IDPlugin standard error by default. Non-integer weights use Kish effective sample size. Set frequency_weights=true or false to override this behavior.
CausalGraphs.id_plugin_a — Function
id_plugin_a(; a, data, graph, treatment, outcome, [id_result, max_levels])Estimate E[outcome(a)] from a symbolic ADMG ID expression using a finite-support plug-in estimator.
This estimator enumerates the observed support of the graph variables and evaluates the ID functional using empirical conditional probabilities. It is intended for discrete variables. It also computes a finite-support delta-method EIF and Wald confidence interval for the plug-in functional. For continuous variables, use one of the specialized semiparametric estimators when the graph is a-, p-, or nested-fixable.
When sample_weights are supplied, integer-like weights are treated as frequency weights for the IDPlugin standard error by default. Non-integer weights use Kish effective sample size. Set frequency_weights=true or false to override this behavior.
CausalGraphs.estimate_causal_npcausal — Function
estimate_causal_npcausal(; a, data, graph=nothing, vertices, di_edges,
bi_edges, treatment, outcome, kwargs...)Identify an effect with CausalGraphs.jl and estimate supported effects with NPCausal.jl.
This optional bridge is loaded only when NPCausal.jl is also loaded in the Julia session. It delegates to NPCausal.admg_estimate_causal, which routes backdoor/a-fixable effects to NPCausal.ate, p-fixable effects to NPS TMLE, nested-fixable effects to ANIPW, and finite-support discrete ID-algorithm functionals to :IDPlugin.
CausalGraphs.fixing_sequence — Function
fixing_sequence(g, nodes)Try to fix nodes by repeatedly applying the ADMG fixing criterion. Returns (fixable, fixing_order, graph).
CausalGraphs.nested_fixability — Function
nested_fixability(g, treatment, outcome)Run the package's One-Line-ID style nested-fixability check for a total-effect query. The result includes the SWIG ancestor set ystar, the induced graph, the nested topological order, and per-district reachable-closure diagnostics.
CausalGraphs.is_nested_fixable — Function
is_nested_fixable(g, treatment, outcome)Return true when nested_fixability(g, treatment, outcome) identifies the effect by the package's nested/fixing check.
CausalGraphs.estimate_causal — Function
estimate_causal(; a, data, graph=nothing, vertices, di_edges, bi_edges,
treatment, outcome, [superlearner_Y, superlearner_A,
crossfit, K, sample_weights, kwargs...])Auto-routing causal effect estimator for ADMGs.
Identification is determined automatically:
- a-fixable (backdoor): returns TMLE, Onestep, Gcomp, IPW
- p-fixable (front-door / NPS): returns TMLE, Onestep
- nested-fixable: returns ANIPW, NIPW
- general ID-algorithm identifiable: returns a finite-support ID plug-in estimator with finite-support EIF confidence intervals for discrete variables
a may be a scalar for E[Y(a)] or a length-2 vector [a1, a0] for the ACE.
Example — backdoor (a-fixable)
g = make_graph(vertices=[:A,:Y,:X],
di_edges=[(:X,:A),(:X,:Y),(:A,:Y)])
res = estimate_causal(a=[1,0], data=df, graph=g, treatment=:A, outcome=:Y)
res[:TMLE].ACEExample — front-door (p-fixable)
g = make_graph(vertices=[:A,:M,:Y],
bi_edges=[(:A,:Y)],
di_edges=[(:A,:M),(:M,:Y)])
res = estimate_causal(a=[1,0], data=df, graph=g, treatment=:A, outcome=:Y)Example — nested-fixable (with SuperLearner)
res = estimate_causal(a=[1,0], data=df, graph=g, treatment=:A, outcome=:Y,
superlearner_Y=true, superlearner_A=true)CausalGraphs.superlearner — Function
superlearner(; metalearner=nothing, binary=false)Return an MLJ stacked ensemble (SuperLearner). binary=true for propensity score (classifier), binary=false for outcome regression.
CausalGraphs.compute_missing_weights — Function
compute_missing_weights(mdag, data; ID=nothing, law=:target,
indicators=nothing, complete_cases_only=false,
normalize=false, kwargs...)Given a CausalGraphs.jl MDAG and a DataFrame with missing-indicator columns (0/1), run the missing-data identification algorithm and estimate propensity scores, then return inverse-probability weights for complete-case estimation.
By default the returned vector has one entry per row of data, with zero weight on incomplete rows. If complete_cases_only=true, only weights for rows where all requested indicators equal 1 are returned; this is useful when passing dropmissing(data) to estimate_causal.
Example
using CausalGraphs, DataFrames
mdag = make_mdag(
obs_variables=["A","Y"],
missing_variables=["X"], missing_indicators=["Rx"],
di_edges=[("A","Y"),("X","A"),("X","Y"),("X","Rx")]
)
ID = ID_algorithm(mdag)
wts = compute_missing_weights(mdag, data; ID=ID, complete_cases_only=true)
result = estimate_causal(a=[1,0], data=dropmissing(data), ..., sample_weights=wts)