When we train a machine-learning model on clinical data, we usually start with a familiar setup: patient characteristics, treatments and observed outcomes. We then try to predict disease progression, treatment response or survival.

But there is a question worth asking before we train anything: how did those observations come to exist?

A patient's outcome depends on their underlying disease, biology, clinical history and potentially the treatment they receive. The treatment they receive, in turn, is often influenced by many of those same characteristics.

These two processes are connected. Understanding that connection is the starting point for causal inference with observational data.

I've been exploring this through a simulated oncology dataset where we can explicitly control how patients develop disease, how treatments are assigned and how outcomes are generated. It helps explain why predicting outcomes and estimating treatment effects require different approaches.

Start with a population of patients

Imagine a dataset of 10,000 fictional patients. Each has baseline characteristics: age, disease stage, biomarker status and comorbidity burden. We'll call these characteristics X.

A real clinical dataset might also contain genomic features, prior treatments, laboratory measurements and other information available before the treatment decision.

These features can influence both prognosis and treatment selection. To understand the data, we'll model those two mechanisms separately.

The disease model: what determines a patient's outcome?

Imagine every patient receives standard care. Some will progress within a year and others will not. We describe each patient's progression probability using a disease model.

In the simulation, age, disease stage, biomarker status and comorbidity burden affect baseline progression risk. But outcomes may also depend on treatment. To estimate treatment benefit we need to describe outcomes under both strategies: standard care (Treatment 0) and a new therapy (Treatment 1).

Consider two hypothetical patient groups:

Patient groupStandard careNew therapy
Group A40% progression risk20%
Group B40% progression risk38%

The baseline risk is the same, but Group A has a much larger expected benefit from treatment. We can design that difference into the simulation, for example by making the therapy more effective in biomarker-positive patients.

This is heterogeneous treatment effect: benefit varies across patient groups.

Importantly, these are probabilities rather than individual outcomes. Even a patient with 20% progression risk may or may not progress.

The assignment model: who receives which treatment?

Now ask how a patient comes to receive one treatment rather than another.

In randomized trials, assignment is controlled by randomization. In observational data, treatment choices are influenced by disease severity, clinician judgment, eligibility, access and patient preferences.

Suppose patients with advanced disease are more likely to be prescribed the new therapy. They may have worse prognosis even before treatment starts.

A treatment-assignment model describes the probability of receiving Treatment 1 given the patient's baseline characteristics. This probability is called the propensity score.

For illustration, we might generate data in which someone with early disease and few comorbidities has a 30% chance of receiving the new therapy, while someone with advanced disease and several comorbidities has an 80% chance.

These probabilities describe treatment selection, not treatment effectiveness.

The disease model describes outcomes. The assignment model describes treatment selection. When the same characteristics influence both, comparing observed outcomes between treatment groups can be confounded.

Putting the two processes together

How patient characteristics affect both potential outcomes and treatment assignment.

Our synthetic data-generating process looks like this:

                     Patient characteristics
                  age, stage, biomarker, comorbidity
                           /           \
                          v             v
                    Disease model   Assignment model
                          |               |
                   Progression risk   Treatment choice
                   under 0 and 1        0 or 1
                          \             /
                           v           v
                         Observed outcome
                     under assigned treatment

The disease model gives potential-outcome probabilities for both treatment strategies. The assignment model determines which treatment is observed, and we generate the corresponding outcome.

The mechanisms are distinct but not independent: characteristics such as disease stage influence both. That is the shared cause behind confounding.

A causal graph of treatment selection

The same idea can be represented as a small directed acyclic graph (DAG):

                   Patient characteristics (X)
                     /                  \
                    v                    v
           Treatment choice (W) -----> Outcome (Y)
                          causal effect

Here X represents baseline factors such as disease stage and biomarker status, W is the treatment received and Y is the outcome. The arrow labeled causal effect is the effect we want to estimate. But X also influences both W and Y, creating a backdoor path through shared causes.

This is why simply comparing treated and untreated patients can be misleading. Adjusting for relevant pre-treatment confounders can help block that path, provided important confounders have been measured and the other identification assumptions hold.

Why a helpful treatment can appear ineffective

Suppose the new therapy genuinely reduces progression risk in every patient group in our simulation. But the assignment model preferentially sends high-risk patients to it.

A raw comparison could show a higher observed progression rate in the treated group. That would not necessarily mean the treatment is harmful.

The comparison combines differences in baseline prognosis with differences caused by treatment. This is confounding by indication.

A more sophisticated predictive algorithm alone cannot resolve this. Unmeasured confounding and lack of treatment overlap can make causal effects impossible to identify reliably from the available observations.

Why we need potential outcomes

Ideally, we would compare what happens to the same patient under both treatments. But for a particular treatment decision, we observe only one outcome.

We call the outcomes under standard care and new therapy Y(0) and Y(1). If the patient receives Treatment 1, we observe Y(1) but not their counterfactual Y(0).

In a simulation, we control the probabilities that generate both potential outcomes. This allows us to benchmark causal estimation methods against the true average effect conditional on patient characteristics. Real observational clinical records do not normally give us that ground truth.

The mathematics behind the models

Let X denote baseline characteristics, W the treatment indicator (0 or 1) and Y the observed outcome.

The outcome regression under treatment w is:

mu_w(x) = E[Y | X = x, W = w]

This is the expected observed outcome among patients with characteristics x receiving treatment w. Under appropriate assumptions, it also identifies the corresponding mean potential outcome.

The propensity score is:

e(x) = P(W = 1 | X = x)

The causal target is the conditional average treatment effect (CATE):

tau(x) = E[Y(1) - Y(0) | X = x]

Under consistency, conditional exchangeability and positivity, it can be identified through the outcome regressions:

tau(x) = mu_1(x) - mu_0(x)

Those assumptions are essential. The difference between two outcome predictions is not automatically a causal effect.

What the simulated dataset lets us examine

Our experiment generates 10,000 fictional patients and retains two views.

The observed dataset contains baseline characteristics, treatment assignment and the outcome under the assigned treatment.

The oracle dataset contains both potential-outcome probabilities, true CATE and each patient's treatment-assignment probability. We know these because we wrote the simulator.

With both, we can examine how naive treatment comparisons differ from true effects, what happens under treatment imbalance, how a learner recovers treatment-effect heterogeneity and how estimates fail when we hide a confounder.

Where this leads

The two mechanisms help us distinguish three questions:

What determines a patient's outcome?

What determines which treatment the patient receives?

What would change if we intervened and assigned a different treatment?

The third is different from the first two. It motivates propensity weighting and methods such as S-, T-, X-, R- and doubly robust learners.

Diagrams generated using AI.