SIMULATED DATA / KNOWN EFFECT

Change the conditions. See the problem. Examine the method.

We simulate the data, so we know the treatment effect. Both modules use the same patients and the same completed run.

Shared simulation settings ⌄

The same settings and patients are used in both modules.

Known conditional effect. Below 1 favours A.

What influences treatment choice?

0 = no direct influence. Positive values favour A for the profile below; negative values favour B.

These are log-odds contributions, not percentages. Use ? for an example.

Every patient has a 50% chance of A. Sex, Age, Stage and ECOG still influence prognosis; none influences assignment.

Completed run

Follow-up, prognosis, seed and uncertainty settings are under Guide > Methods & settings.

01 / CONFOUNDING & SURVIVAL

Can a useful treatment look worse?

Change who receives Treatment A. Compare the known effect with the crude and adjusted analyses.

Causal structure

The same four baseline characteristics enter the prognosis and assignment models. Dotted paths are switched off.

Stage distribution

Within-treatment percentages. Open Baseline characteristics for Age, Sex, Stage and ECOG together.

Observed survival

Adjusted survival

Cox predictions averaged over every patient in the same complete cohort. Dotted curves show the known model.

Treatment effect estimates

A vs B - line at HR = 1

Read the estimates

Hover, tap a point or open the values. Diamonds are known-model references; circles are sample estimates.

What happened in this run?

Each example applies its named change and runs both modules. The current seed and population settings are retained.

Compare each estimate with its matching target

Treatment estimates (.csv)

Gap = estimate minus matching reference in HR units. This is a deviation in one sample, not an estimate of repeated-sampling bias.

Survival probabilities and time alive

Median survival

02 / PROPENSITY SCORES & IPTW

Can weighting make the groups comparable?

Start with the patient differences. Apply treatment weights, inspect balance and overlap, then read the estimates.

Treatment effect estimates

A vs B - line at HR = 1

Read the estimates

Hover, tap a point or open the values. Diamonds are known-model references; circles are sample estimates.

IPTW survival

Weighted Kaplan-Meier curves. Dotted curves show the known-model survival for the same complete cohort. Curve intervals are not shown.

Interpret the weighted comparison

A common survival target

Balance before and after IPTW

Closer to zero means less measured imbalance. The 0.10 line is a descriptive flag, not a guarantee.

Propensity-score distributions

Both groups use P(Treatment A). Strong separation means little overlap.

Baseline characteristics

Weight distribution

How much information remains?

Effective sample size describes the concentration of weights. It does not create additional patients and is not a complete measure of outcome information.

Stabilised ATE weights. No trimming, truncation or weight cap. Default HR intervals use robust variance; optional bootstrap intervals refit the propensity model.

SHARED COHORT

Baseline characteristics

The same Age, Sex, Stage and ECOG profiles used in both methods. Changing this view does not rerun the analysis.

Balance statistics (.csv)

Treatment A and Treatment B

Measured imbalance

The before/after markers and all SMD values are identical to the IPTW module.

SHARED COHORT

Patient data

One row per simulated patient. Inspect the characteristics, outcomes, known treatment probabilities, fitted propensity scores and weights.

Filtered rows (.csv)

Filters do not change any analysis. The download uses these controls, not the table's text search.

Completed simulation

Swipe or scroll the table sideways to see all columns.

Variable definitions

Variable Meaning
id Fictional identifier, retained across the implemented modules.
sex Female or Male. Binary coding is a simplifying assumption in this demonstration.
age Age in years at baseline; truncated normal between 30 and 90, rounded to one decimal.
age10 (Age - 65) / 10, used by the treatment and prognosis models.
stage Stage I-IV. Unordered categorical adjustment variable.
ecog Baseline performance status, ECOG 0-4. Higher values represent greater impairment. Categorical in fitted models.
trt Treatment A = 1; Treatment B = 0.
treatment Treatment A or Treatment B.
time Observed time in years from baseline to death, loss to follow-up or study end.
event 1 = observed death; 0 = right-censored.
followup_status Why follow-up ended.
probability_A Known probability of Treatment A from the generating assignment model.
hazard_B Known event hazard under Treatment B for this profile. Used for the simulation reference only.
propensity_score Estimated probability of A in observational mode; known 0.5 in randomised mode.
iptw_weight Stabilised ATE treatment weight. Unavailable when the propensity model is not usable.
WHY THIS MATTERS

A better method starts with a clearer comparison.

The point is not to collect methods. It is to change something, see a problem arise and examine whether the analysis recovers the effect we built into the data.

Why simulate?

In an ordinary study we do not know the treatment effect. Here we choose it before creating the outcomes. That lets us compare an estimate with a known reference, rather than assume that a more complicated analysis must be better.

All patients and all prognosis effects are fictional. The app teaches methods, not treatment recommendations.

Keep the patients in view

Sex, Age, Stage and ECOG describe the patients at baseline. Each can affect prognosis. In observational mode each can also influence treatment choice, with its own strength and direction.

Randomised mode removes those assignment links without removing their prognosis effects. The same seed retains the baseline profiles.

Use the matching reference

The adjusted Cox model targets the conditional treatment HR. Treatment-only crude and IPTW Cox models give population-level summaries. Those HRs can differ even when there is no confounding.

The app calculates a separate population reference from the known model, and also shows survival probabilities and time alive on a common population scale.

Background: Austin [2]; survival documentation [5-6].

Check weighting, not just the HR

Use the baseline table, Love plot, propensity-score distributions, weights and effective sample size together. Weighting is useful only when the required assumptions and data support the comparison.

Low measured SMD is not proof of no unmeasured confounding. Poor overlap can make both weighting and model-based adjustment unreliable.

Background: Austin and Stuart [3]; cobalt documentation [4].

What the current example assumes

All four characteristics are observed without error and sampled independently. There are no additional unmeasured common causes. The conditional treatment HR is constant, treatment starts at baseline, and loss to follow-up is independent.

These choices keep the first two modules focused. Delayed treatment, target trial design, effect modification and missingness are separate planned steps.

One run is not a performance study

A corrected estimate does not have to be closer to the truth in every sample. Use New sample to see that variation. More patients usually improve precision, but do not by themselves remove a design problem.

The displayed gaps are deviations in this run. Formal bias and coverage assessments require many simulated datasets.

Sources and further reading

  1. Hernan and Robins. Causal Inference: What If (2020). Confounding, standardisation, positivity and target trial design.
  2. Austin. Propensity score methods for estimating marginal hazard ratios (2013). Why an IPTW Cox HR and an adjusted Cox HR do not have the same target.
  3. Austin and Stuart. Best practice when using IPTW (2015). Balance, propensity-score distributions, extreme weights and diagnostics.
  4. cobalt documentation. Standardised mean differences. Use the same original-sample denominator before and after weighting.
  5. survival documentation. Cox models and case weights. Weighted Cox models and robust variance estimates.
  6. survival documentation. Predicted survival curves. Predict at explicit patient profiles before averaging survival probabilities.
  7. ECOG-ACRIN. ECOG Performance Status Scale. Meaning of the performance-status scale. This app uses baseline levels 0-4.
  8. Hernan and Robins. Using Big Data to Emulate a Target Trial (2016). The specification behind the planned target trial module.
METHODS & SETTINGS

Keep prognosis and treatment choice separate.

These settings change the generating model for both modules. They are teaching assumptions, not clinical estimates.

Follow-up and prognosis

Reference profile: female, age 65, Stage I, ECOG 0, Treatment B.

Population, reproducibility and intervals

Ages are restricted to 30-90. The observed mean will differ. Stage and ECOG proportions are specified in tools/causal/src/settings.R.

When enabled, refit adjusted Cox and the propensity-weighted analysis in each resample. This replaces their HR intervals with percentile intervals and adds adjusted-curve bands.

Reproduce this run (.R)

Generating model

logit P(A | X) = intercept
  + assignment_sex * male
  + assignment_age * (age - 65) / 10
  + assignment_stage * (stage - 1)
  + assignment_ecog * ECOG

hazard_B = reference_hazard
  * sex_HR^male * age_HR^((age - 65)/10)
  * stage_HR^(stage - 1) * ECOG_HR^ECOG

hazard_A = hazard_B * true_treatment_HR

Randomised assignment: P(A | X) = 0.5

Stage and ECOG are categorical in both fitted models, although their generating contributions use equally spaced log effects. Age is linear on the log-hazard and log-odds scales.

Censoring in the completed run

How the population reference is calculated

For each profile we know the hazards under A and B. We average its survival probability and event density over the complete cohort, then solve the expected treatment-only Cox score for an ideal, unconfounded comparison. The study horizon, dropout distribution and completed treatment share are included.

This numerical reference is a follow-up-specific marginal Cox summary. It is not an extra model fitted to the observed deaths, and it is not a claim that the marginal HR is constant over time.

DEVELOPMENT PLAN

One lab, built in a clear sequence.

The first two modules share the same complete dataset. The next four will reuse the baseline population and common result components, with explicit changes to the data-generating process.

Available now and planned next

Module Status Question
1. Confounding & Survival Available Can different baseline prognosis reverse the crude comparison?
2. Propensity Scores & IPTW Available Can weighting balance the measured characteristics, and is there enough overlap?
3. Immortal Time Bias Planned - not implemented What happens when future treatment is incorrectly assigned from diagnosis?
4. Target Trial Emulation Planned - not implemented Are eligibility, treatment strategies, assignment and time zero aligned?
5. Effect Modification Planned - not implemented Can subgroup effects stay constant while the overall estimate changes?
6. Missing Data Planned - not implemented What changes when Stage or ECOG is missing, and under which assumptions can imputation help?

3. Immortal Time Bias

Diagnosis becomes time zero. Treatment A can start later. A patient timeline will show the period before initiation, and the analysis will compare baseline ever-treated coding with a time-dependent exposure.

The baseline characteristics still affect prognosis. The known reference must refer to the post-initiation treatment effect.

4. Target Trial Emulation

Specify eligibility, treatment strategies, assignment, time zero, follow-up, outcome, causal contrast and analysis. Then vary initiation windows, delays, grace periods and follow-up start.

The correction must match the chosen trial strategy. Simply relabelling a time-dependent Cox model as target trial emulation would not be enough.

5. Effect Modification

Allow the treatment HR to differ by Sex, Age, Stage or ECOG. Compare the known subgroup effects, subgroup estimates and the treatment-by-subgroup interaction.

Changing subgroup proportions can change an overall summary even when the subgroup-specific effects have not changed.

6. Missing Data

Make Stage or ECOG missing in up to 50% of patients. Compare the full-data analysis, complete cases and multiple imputation under specified missingness mechanisms.

The full-data estimate is an estimated benchmark, not the known generating effect itself. A standard MAR imputation model will not automatically correct an MNAR scenario.