v0.2.0Python 3.11+ · Apache-2.0
From data
to a causal effect.
Learn a causal graph from your data, check that the effect you want is identifiable, and estimate it with an interval. Every program on this site is tested: most run on bundled data, and those that need a Welt key run against a fake Welt service.
Your first causal effect
Full walkthroughInstall
sh
pip install "ergodic"
sh
uv add "ergodic"
Run
Step by stepfirst_effect.pyDownload
from ergodic import discover, estimate_effect, identify_effect
from ergodic.datasets import load_earthquake
# 1. Load 10,000 rows sampled from the burglar-alarm network.
alarm = load_earthquake(n=10_000, seed=0)
rows = alarm.data.to_pandas()
print(rows.shape)
print((rows == "True").mean().round(3))
# 2. Learn the graph from the data alone.
graph = discover(alarm.data, method="pc").graph
for edge in sorted(edge.glyph() for edge in graph.edges):
print(edge)
# 3. Ask whether the data can answer the question.
identification = identify_effect(graph, "Burglary", "JohnCalls")
print(identification)
# 4. Estimate the effect of a burglary on John calling.
estimate = estimate_effect(graph, alarm.data, "Burglary", "JohnCalls", treated="True")
print(estimate)
Recorded output
(10000, 5)
Burglary 0.011
Earthquake 0.022
Alarm 0.017
JohnCalls 0.067
MaryCalls 0.022
dtype: float64
Alarm --> JohnCalls
Alarm --> MaryCalls
Alarm <-- Burglary
Alarm <-- Earthquake
Identification(adjustment: P(JohnCalls | do(Burglary)) = sum_z P(JohnCalls | Burglary, z) P(z), with z = {Earthquake})
EffectEstimate(aipw, analytic: ate=0.7982, se=0.0333, 95% CI [0.733, 0.863], n=10000)
What do you want to do?
Discover a graphLearn a causal graph from data, with domain knowledge.Check whether an effect is identifiableAsk a graph for the formula before you estimate.Estimate an average effectAdjust for confounders and read the interval.Forecast with causal driversForecast series whose drivers you can name.Map a process from an event logSee a workflow, then measure what slows it.Discover in Welt, estimate in ergodicRun Welt's hosted models from ergodic.