FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Causal Inference

Estimate intervention effects by stating an estimand, drawing a causal graph, choosing an identified adjustment set, and testing its assumptions.

Freshness: current•13 min read•Probabilistic and Causal Methods
Full Technical Reference Document

Mental model

Causal inference estimates how outcomes change under a specified intervention, not how two observed variables merely co-vary. A directed acyclic graph makes assumptions about cause and effect visible, helping determine whether an effect is identifiable from available data and which baseline variables to adjust. Estimation follows identification; it cannot repair an unsupported graph or a missing confounder.

Theory

A causal question names a treatment or exposure A, an outcome Y, a population, and a contrast such as the average treatment effect. An observational comparison estimates P(Y∣A=a)P(Y \mid A=a): the outcome distribution among units that happened to receive level aa. An intervention asks for P(Y∣do(A=a))P(Y \mid do(A=a)), the distribution if a process externally set A to a. These distributions need not match when common causes influence both treatment assignment and outcome.

A directed acyclic graph (DAG) records a proposed causal structure. If baseline risk C affects both whether a customer receives onboarding help A and whether that customer remains active Y, the path A←C→YA \leftarrow C \rightarrow Y is a backdoor path. Conditioning on a sufficient set of pre-treatment common causes can block that path. The backdoor criterion also rules out adjusting for descendants of A; controlling for a mediator would remove part of the total effect, and conditioning on a collider can create an association that was absent before selection.

Identification is a property of the question, graph, and available measurements. The backdoor formula is valid only under assumptions such as consistency, conditional exchangeability given C, and positivity: each target stratum must have a chance of receiving each treatment level. An estimator can compute a precise number even when those assumptions fail. Randomization, sensitivity analysis, negative controls, and explicit DAG review provide different evidence about the assumptions; none can prove away every unmeasured cause.

A confounder can reverse the raw comparison

Suppose an onboarding program is adopted more often by customers with high baseline churn risk. In a target population, 60% are low-risk and 40% high-risk. Within low-risk customers, retention is 84% with the program and 80% without it; within high-risk customers, it is 60% versus 52%. Standardizing both treatment groups to the same target mix gives 0.6(0.84−0.80)+0.4(0.60−0.52)=0.0560.6(0.84-0.80)+0.4(0.60-0.52)=0.056, or a 5.6 percentage-point difference under the stated assumptions.

Now imagine 80% of treated customers are high-risk but only 20% of untreated customers are. The raw treated rate is 0.2(0.84)+0.8(0.60)=0.6480.2(0.84)+0.8(0.60)=0.648; the raw untreated rate is 0.8(0.80)+0.2(0.52)=0.7440.8(0.80)+0.2(0.52)=0.744. The unadjusted difference is -9.6 points, even though both within-risk differences favor the program. The reversal comes from treatment selection, not from a paradox in arithmetic. The calculation is an illustration: real analyses need uncertainty intervals and a justified target population.

ATE⁡=∑c(E[Y∣A=1,C=c]−E[Y∣A=0,C=c])P(C=c)\operatorname{ATE} = \sum_c \left(\mathbb{E}[Y\mid A=1,C=c]-\mathbb{E}[Y\mid A=0,C=c]\right)P(C=c)

Here A is the binary intervention, Y is the binary retention outcome, and C is a measured pre-treatment risk stratum. The conditional expectations are retention probabilities; P(C=c) is the target-population share, so the ATE is a probability difference, often reported in percentage points. This standardization formula requires exchangeability and positivity within the chosen strata.

Define treatment, outcome, and target population
Draw a DAG and mark pre-treatment common causes
Check a valid backdoor set and treatment overlap
Standardize the outcome contrast with uncertainty
Run sensitivity and negative-control checks before a decision
Conceptual teaching model synthesized from:pearl-causality-2009,pearl-causal-calculus-1995

Implementation pattern

This pandas example computes the same stratified standardization from aggregate counts. The target shares must describe the population the result is meant to represent. It does not test exchangeability for you; include only pre-treatment covariates justified by the causal graph, and do not treat the output as identified when a stratum lacks either treatment level.

python
import pandas as pd
​
cells = pd.DataFrame([
{"risk": "low", "treated": 1, "retained": 84, "n": 100},
{"risk": "low", "treated": 0, "retained": 80, "n": 100},
{"risk": "high", "treated": 1, "retained": 60, "n": 100},
{"risk": "high", "treated": 0, "retained": 52, "n": 100},
])
cells["rate"] = cells["retained"] / cells["n"]
rates = cells.pivot(index="risk", columns="treated", values="rate")
target_share = pd.Series({"low": 0.60, "high": 0.40})
if set(rates.index) != set(target_share.index):
raise ValueError("target strata do not match the observed rates")
if not {0, 1}.issubset(rates.columns) or rates[[0, 1]].isna().any().any():
raise ValueError("positivity failure: a stratum lacks a treatment arm")
target_share = target_share.reindex(rates.index)
if abs(target_share.sum() - 1.0) > 1e-9:
raise ValueError("target shares must sum to one")
ate = ((rates[1] - rates[0]) * target_share).sum()
print(f"standardized retention difference: {ate:.3f} ({100 * ate:.1f} percentage points)")

Trade-offs

A randomized experiment usually gives treatment assignment independent of baseline causes in expectation, but it can be costly, slow, or unethical for some interventions. An observational study can answer questions about existing operations, yet it depends more strongly on measurement and graph assumptions. Standardization is easy to explain when the adjustment set is small; inverse-probability weighting can target other estimands but becomes unstable when estimated treatment probabilities approach zero or one. Flexible outcome models can reduce functional-form bias, but more model capacity does not create identification.

Doubly robust estimators combine outcome and treatment models and can remain consistent if one of those models is correctly specified under the identification assumptions. They do not protect against unmeasured confounding, poor overlap, invalid treatment definitions, or data leakage. Report the estimand, adjustment set, overlap diagnostics, uncertainty, and sensitivity analysis together so an operational reviewer can see what the numerical estimate does and does not claim.

Failure modes and misconceptions

  • Adjusting for a mediator: Controlling for an event caused by treatment changes a total-effect question into a direct-effect question. Define the estimand before selecting covariates.
  • Conditioning on a collider: Selecting only customers who completed a downstream workflow can open a spurious path between treatment and outcome. Draw the selection process into the DAG.
  • No overlap: If a risk stratum has only treated units, the untreated potential outcome there is unsupported by data. Restrict the target population or redesign data collection rather than extrapolating silently.
  • Unmeasured confounding: A large sample narrows sampling error but does not remove bias from a missing common cause. Use domain review, negative controls, or sensitivity bounds.
  • Treatment-version mismatch: “Received onboarding” may combine materially different sessions. Specify the intervention and test implementation fidelity.
  • Interference: If one customer’s treatment changes another customer’s outcome, a unit-level no-interference assumption fails. Consider cluster assignment and a group-level estimand.

Decision scenario

A product team reports that customers who watched a new onboarding lesson retain at a higher rate, and proposes making it mandatory. Lesson completion is more common among customers who were already active during their first week. Before deciding, define whether the question is the effect of offering the lesson or completing it, draw the paths from prior activity to completion and retention, and check whether both completion levels occur across the target activity strata. If the data support the offer but not completion, estimate the offer effect or run a randomized rollout; do not adjust for post-lesson engagement and call the result a total effect.

Learning outcomes

  • Distinguish an observational conditional from an interventional distribution.
  • Use a DAG and the backdoor criterion to justify adjustment, and recognize when overlap is inadequate.
  • Calculate and communicate a standardized treatment contrast with its assumptions and limitations.
Reflect before revealing the guide

Prerequisites & Related Concepts (2)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-102LLM Systems Foundations

Build a connected mental model from tokens through retrieval evaluation security and operations.

24 concepts~18h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.