Formative
Quantitative reasoning made simple (but not easy). A Python library for causal estimation, refutation and decision-making, built around explicitly stated assumptions.
$ pip install formative-dsExample
example.py
from formative.causal import DAG, OLSObservational
from formative.game import minimax, maximax, maximin
# ---- Causal estimation (with heterogeneous effects) ----
dag = DAG()
dag.assume("ability").causes("education", "income")
dag.assume("segment").causes("income")
dag.assume("education").causes("income")
result = OLSObservational(
dag,
treatment="education",
outcome="income",
effect_modifier="segment", # effect estimated per segment
).fit(df)
print(result.summary())
# ---- Refutation ----
print(result.refute(df).summary())
# ---- Decisions ----
decision = result.decide(cost=2.5, benefit=1.0)
print(decision)
for level, d in result.decide_by_group(cost=2.5, benefit=1.0).items():
print(level, "→", d.optimal) # different segments
# ---- Decisions via game theory ----
outcomes = decision.to_outcomes()
print(minimax(outcomes).solve()) # pessimistic choice
print(maximax(outcomes).solve()) # high risk, high reward
print(maximin(outcomes).solve()) # best worst-caseFind a method
Answer a few questions to find the right approach for measuring cause and effect in your situation.
Methods
1
Can you decide who receives the intervention?
Do you have the ability to choose or control who gets the treatment?