Counterfactual prediction of treatment effects on irregular clinical data using Time-Aware G-Transformers

Abstract

Selecting an effective treatment relies on accurately anticipating patient's response to alternative interventions. However, forecasting longitudinal clinical trajectories remains difficult because electronic health records contain heterogeneous, irregularly sampled data over extended time periods. These issues are especially relevant for laboratory measurements, which are central for diagnostics, assessment of therapeutic responses, and tracking disease progression in routine clinical practice. However, existing deep learning methods for counterfactual prediction usually assume regularly sampled data, an assumption incompatible with the irregular, heterogeneous data‑generation processes of real‑world clinical practice. Here we present the Time-Aware G-Transformer, which integrates causal G-computation with time-aware attention to predict counterfactual outcomes on irregular data. By explicitly conditioning on the timing of future observations and encoding measurement patterns, the model captures temporal dynamics that previous methods overlook. Evaluated on synthetic tumor growth data and on 90,753 cancer patient trajectories from an academic medical center, our approach demonstrates superior long-horizon (> 1 day) prediction accuracy and uncertainty calibration compared to state-of-the-art baselines. These results demonstrate that embedding temporal relations directly into the attention mechanism enables robust integration of patient history data for evaluating potential treatment strategies in personalized medicine.

Competing Interest Statement

The authors have declared no competing interest.

Funding Statement

Funding was received from the Helsinki University Hospital VTR funds (grant no. TYH2025370 to R.R) and from Business Finland (grant 4911/31/2024 to R.R.).

Author Declarations

I confirm all relevant ethical guidelines have been followed, and any necessary IRB and/or ethics committee approvals have been obtained.

Yes

The details of the IRB/oversight body that provided approval or exemption for the research described are given below:

HUS Helsinki University Hospital, under Chief Medical Officer Markku Makijarvi, gave ethical approval for this work (permission HUS/223/2023). An updated permission was granted by HUS Helsinki University Hospital under Chief Medical Officer Veli-Matti Ulander (permission HUS/355/2025), transferring registry holdership to the University of Helsinki.

I confirm that all necessary patient/participant consent has been obtained and the appropriate institutional forms have been archived, and that any patient/participant/sample identifiers included were not known to anyone (e.g., hospital staff, patients or participants themselves) outside the research group so cannot be used to identify individuals.

Yes

I understand that all clinical trials and any other prospective interventional studies must be registered with an ICMJE-approved registry, such as ClinicalTrials.gov. I confirm that any such study reported in the manuscript has been registered and the trial registration ID is provided (note: if posting a prospective study registered retrospectively, please provide a statement in the trial ID field explaining why the study was not registered in advance).

Yes

I have followed all appropriate research reporting guidelines, such as any relevant EQUATOR Network research reporting checklist(s) and other pertinent material, if applicable.

Yes

Data Availability

Sensitive patient data from the HUS Helsinki University Hospital cohort cannot be distributed according to Finnish national regulations and EU legislation. All analyses were conducted within the secure HUS Acamedic platform. Synthetic data generation code and model implementation will be made publicly available upon publication.

Comments (0)

No login
gif