From confounding to trajectories

Did the treatment help, or were the patients who received it simply healthier to begin with? An interactive demo on simulated cancer cohorts where the true answer is known, so every method can be graded against it instead of against the others.

What this demo is about

A hospital looks back through its records and asks the question every clinician wants answered: did the patients who received this treatment live longer because of it? The records alone cannot say, because the treated patients were never like the untreated ones. Doctors offer treatment to the patients they judge fit enough to benefit, so the treated group starts out healthier, and any survival gap between the groups mixes the effect of the treatment with the head start of the people who received it. That mixing is called confounding, and pulling the two apart is the problem this page is about.

What the demo is for

Every patient here is simulated, so unlike a real study this one comes with an answer key: the true survival benefit of treatment at every point in follow-up, drawn as the solid black curve. Each method can therefore be graded against the truth rather than against the other methods, which is the one comparison no real study can run. The goal is not to crown a winner. It is to show what each method quietly assumes, and to let you watch it break when that assumption fails.

What it analyzes, and what it delivers

The setting is ordinary observational survival data: a registry extract, a pull from electronic health records, a single-institution series. One row per patient, carrying the treatment given, how long the patient was followed, whether they died or were last seen alive, and the characteristics recorded at the start. What comes out is not one summary number but a curve over time: out of 100 treated patients, how many more are alive at each point in follow-up than would have been without the treatment, with an uncertainty band around it.

Why the familiar tools fall short

Comparing the groups directly measures the treatment plus the head start, so it answers the wrong question. Cox regression does adjust for the recorded characteristics, but it compresses all of follow-up into a single hazard ratio, which is only right if the benefit holds steady over time. Many do not: a benefit can take months to appear, or peak and fade, or turn into a harm late. Averaging an early benefit against a late harm returns roughly "no effect", which is wrong at every point in time. Machine-learning survival models predict well, but a good prediction is not a causal answer.

What no method can fix

Adjustment only works on what somebody wrote down. If a factor drives both who gets treated and who survives, and nobody recorded it, every method here is pulled off the truth in the same direction at once while the usual warning signs still look healthy: recorded characteristics balanced, intervals narrow, nothing complaining. The second control above the figure turns exactly that on, and because these patients are simulated, the page can show you what it costs.

The methods on the figure, and why each one is here

Naive comparison
Survival in the treated group minus survival in the untreated group, with no adjustment at all. It is here to show how large the problem is, not as a serious contender.
Cox regression
The survival workhorse most readers already know: it adjusts for the recorded characteristics and reports one hazard ratio for all of follow-up. It is a fair benchmark rather than a straw man, because on one of the two effect shapes the simulated biology really does hold steady over time, so Cox is the right model there and usually wins.
Random survival forest, in two arrangements
A machine-learning model that predicts how long patients survive. The S-learner treats "was this patient treated" as one feature among many, while the T-learner fits a separate model per group and compares them. Both show that predicting survival well is not the same as measuring what treatment did, and that the two arrangements go wrong in two different ways.
Causal survival forest (CSF)
A forest built for the causal question instead of the prediction one. It learns who tends to get treated and who tends to survive, then subtracts the part of the survival gap those two patterns already explain, leaving the treatment's own contribution. It removes confounding without anyone having to specify in advance how each characteristic relates to survival, which is the assumption a regression asks you to make and get right.
CAST
The causal forest gives a separate estimate at each time point, and those estimates wobble against one another. CAST fits one smooth curve through them, allowing for the fact that nearby time points rise and fall together, and turns the result into numbers a clinician can read off: how large the benefit gets, and when it arrives. It is the method this site exists to demonstrate.
The simulated cohorts in detail

Every cohort on this page is simulated, so unlike a real study this one comes with an answer key: the true average treatment effect (ATE) at every horizon, drawn as the solid black curve. Each method can therefore be judged against the truth rather than against the other methods.

We estimate the between-group difference in the probability of surviving past each fixed time horizon, i.e. the survival-probability difference, formally P(T>t | treated) − P(T>t | control). Horizons run from 12 to 108 months, and the control arm of the synthetic cohort has a median survival near 47 months.

Two effect shapes are available, and both are simulated. Under plateau, treatment helps at every horizon, so the survival gap widens, peaks, and then slowly narrows as both arms approach low survival. Under reversal, treatment helps early and harms after about four years, so the survival curves cross and the gap turns negative. The reversal is drawn sharper than most real crossings, to make each estimator’s response to it easy to see.

Every cohort also carries four confounders: age, stage, performance status and comorbidity count, all of which drive both prognosis and treatment assignment. Alongside them sits one covariate that worsens survival but has no bearing on who gets treated (smoking, a prognostic non-confounder), two that affect nothing at all (sex and ethnicity, negative controls), and one unmeasured confounder: a latent fitness factor that both improves survival and raises the chance of being treated, and that no fitted model ever sees.

Set the two confounding controls and switch methods on and off to watch each estimator move while the black truth curve stays where it is.

1 · The confounding problem

Healthier patients (younger, earlier-stage, better performance status, fewer comorbidities) are preferentially selected into treatment (confounding by indication). The Naive unadjusted survival-probability difference then measures treatment effect plus baseline prognosis, so it is biased upward and overstates benefit. At zero confounding it matches the truth; turn confounding up and it diverges.

2 · CSF adjusts for measured confounding

The Causal Survival Forest orthogonalizes against a propensity model and a censoring model (Neyman-orthogonal, like double machine learning), recovering the true ATE at each horizon under mild-to-moderate confounding and substantially reducing (though not fully removing) the bias under strong confounding, where treatment propensities are pushed toward 0 or 1 and overlap is stressed (a positivity limit; see the strong-confounding figures, where CSF sits above the truth but far below the naive curve). Two non-orthogonalized ML baselines are shown for contrast: the RSF S-learner (one survival forest with treatment as a feature), which can ignore treatment when splitting and so attenuates the effect toward zero even with no confounding, and the RSF T-learner (separate per-arm forests), which avoids that attenuation but, lacking a propensity model, extrapolates across arms and stays biased under confounding.

3 · Every baseline has a regime where it breaks

None of these estimators is uniformly worst. Cox gives one hazard ratio for all time; here the plateau simulation is itself a proportional-hazards model, so Cox is correctly specified and wins on those panels, and the same model then flattens to near-zero on the reversal it cannot represent. The S- and T-learner survival forests predict survival well but give no principled causal contrast, and fail in two different ways (effect attenuation versus cross-arm extrapolation). The lesson is not a ranking but a map of which assumption each method needs.

4 · What no method can fix

Adjustment only works on what you measured. Push the unmeasured-confounding control and a latent fitness factor starts driving both survival and treatment while staying invisible to every model. The measured covariates remain balanced, the overlap diagnostics stay clean, the confidence intervals stay narrow, and every estimator, CSF and CAST included, drifts away from the truth together. The oracle refit in the card above measures exactly how much, which is the one thing a real analysis can never do.

5 · CAST extends CSF to a trajectory

CSF gives correlated point estimates across horizons. CAST forms the cross-horizon covariance from the CSF influence-function scores, stabilizes it with Ledoit–Wolf shrinkage, and fits a smooth quadratic in time. The point fit is generalized least squares β̂ = (XᵀΣ̂⁻¹X)⁻¹XᵀΣ̂⁻¹y, which engages automatically because the survival-probability horizons make Σ̂ well-conditioned (it falls back to weighted least squares when they do not), and the 95% band is a covariance-aware sandwich that propagates Σ̂. The result is a smooth effect trajectory whose clinical metrics (peak effect, time-to-peak) are model-based summaries of the per-horizon causal estimates rather than separately identified causal quantities.

Failure modes at a glance

Every estimator on the plot fails in its own characteristic way. Set the confounding levels and switch effect shapes to watch each one break against the known truth.

Naive (unadjusted)

Confounding by indication. The unadjusted survival-probability difference measures the treatment effect plus the baseline prognostic gap between arms. Because healthier patients are preferentially treated, it is biased upward and overstates benefit, and the bias grows as confounding rises. It matches the truth only under randomization (γ = 0) with no latent confounder.

RSF S-learner

Treatment-signal dilution. With treatment entered as just one of many covariates, the survival forest can split on the other features and rarely on treatment, so the estimated contrast shrinks toward zero. This attenuation appears even at zero confounding, where the S-learner sits well below the truth. Watch for the panels where that downward pull happens to cancel an upward confounding bias and the S-learner lands on the truth for the wrong reason.

RSF T-learner

Cross-arm extrapolation. Separate per-arm forests each see only their own arm's covariate distribution, then predict counterfactual survival for everyone, extrapolating into regions never observed in that arm. Without a propensity model it avoids the S-learner's attenuation but stays biased under confounding, drifting upward with the naive curve.

Cox (marginal)

Proportional-hazards misspecification. A single time-constant hazard ratio cannot represent a time-varying effect. It is confounder-adjusted, so measured confounding does not bias it, and on the plateau shape it is the correctly specified model and the most accurate curve on the plot. On the reversal shape the one hazard ratio averages the protective-early and harmful-late phases toward 1, and the marginal curve flattens to near zero. The proportional-hazards test flags this (p < 0.0001 on every reversal panel).

CSF (causal survival forest)

Positivity / overlap stress. Orthogonalizing against a propensity and a censoring model removes confounding under good overlap, but when strong confounding pushes treatment propensities toward 0 or 1, overlap degrades and a residual bias remains (the points sit above the truth at strong confounding, though far below the naive curve). CSF also returns correlated per-horizon points with no smooth trajectory, and here it is scored in-sample, so its accuracy is optimistic.

Every method at once

Unmeasured confounding. The one failure no estimator on this page escapes. A latent factor that drives both survival and treatment assignment biases the naive comparison, the forests, the Cox model, CSF and CAST alike, and leaves every visible diagnostic looking healthy: measured covariates balanced, overlap fine, intervals narrow. Only the oracle refit, available here because the data are simulated, reveals the size of the gap.

CAST (trajectory)

Trajectory-shape misspecification. CAST smooths the CSF points into a quadratic in time; when the true effect is not quadratic, such as the reversal's sharp early peak, the smooth fit underfits the peak and its error can exceed the per-horizon CSF points. Its peak time and effect are model-based summaries of the per-horizon causal estimates, not separately identified causal quantities, and the band is conditional on the fitted forests.

Method provenance. CAST is the work of Yang et al. (arXiv:2505.06367); this site demonstrates it and is not the analysis code of that paper. The CSF fits use grf::causal_survival_forest (survival.probability target). The CAST layer (ledoit_wolf_shrinkage, the cross-horizon influence-function covariance, and the covariance-aware quadratic trajectory fit) is adapted from the CAST pipeline of the applied glioma study. The versioned code, not the papers, defines the exact implementation. All cohorts are simulated, with no patient data.

Source code. Every number and figure on this page is reproduced by the R pipeline at github.com/ishuryak/cast_demo_website, which also documents the full data-generating model, the provenance of every simulation parameter, and the known limitations of this demo.