Survival Transformers for Longitudinal Data Analysis: Application to Atrial Fibrillation Risk from ECG
Abstract
Atrial fibrillation (AFib) is the most common sustained cardiac arrhythmia and a major risk factor for stroke, yet it often remains undetected until a first clinical event. Existing deep learning approaches typically estimate AFib risk from a single, cross-sectional electrocardiogram (ECG), discarding longitudinal information contained in serial recordings. We propose SurviFormer, a transformer-based survival model that uses sequences of ECG representations to estimate patient-specific risk of first documented AFib over time. The model encodes irregular time gaps between visits as pairwise relative attention biases within a causally masked transformer and predicts a discrete hazard function using multi-landmark training. We train and evaluate SurviFormer on the CODE dataset (approximately 140,000 patients and 517,000 ECGs), comparing it with static and longitudinal survival baselines, including DeepSurv, DeepHit and DynamicDeepHit, with external validation on MIMIC-IV. On the internal test set, SurviFormer achieves a C-index of 0.853, a mean time-dependent AUC (TD-AUC) of 0.867, and an integrated Brier score (IBS) of 0.030; on the external dataset, the corresponding values are 0.805, 0.848, and 0.106. In a controlled comparison with a latest-ECG model, the full-history model achieves similar discrimination (C-index 0.853 vs. 0.853) and more accurate time-resolved absolute-risk estimates (IBS 0.030 vs. 0.038). Demographic and visit-pattern controls perform substantially worse than the ECG-based model, supporting the prognostic value of ECG-derived information. These results suggest that incorporating longitudinal ECG histories improves absolute-risk estimation while preserving discrimination relative to a single recording.