Electrocardiogram (ECG) morphology is influenced by demographic and genetic factors. Disentangling them is crucial for cardiovascular disease (CVD) modeling to prevent misinterpreting normal variations as pathology. While Autoencoders (AEs) are widely used, previous studies have neither explicitly disentangled these factors nor included Polygenic Risk Scores (PRS) as inputs. Integrating PRSs remains challenging as weak genetic signals emerge only at distribution extremes. We aimed to develop an AE capable of disentangling these variables, yielding a confounder-corrected ECG representation (latent vector z-rest) while overcoming extreme PRS modeling barriers.
We analyzed the 8 independent leads from standard resting ECGs from 40,039 healthy UK Biobank individuals, developing an AE using auxiliary classifiers to segment latent vectors into demographic (sex, age) and genetic (QT, QRS, PR-interval PRSs) subvectors, as well as a purified latent vector z-rest that captures all unexplained morphology. To capture weak genetic signals without discarding data, we applied selective masking: the model learned general morphology from the full cohort while restricting the model's training on genetic effects to extreme percentiles (<5th, >95th). Cross-prediction validated latent purity: vectors could not predict unassigned covariates, guaranteeing minimal information leakage.
Target predictions from corresponding subvectors achieved high accuracy (Sex AUC=0.971, Age MAE=5.494, PRS AUCs: QT=0.865, QRS=0.785, PR=0.801). Conversely, non-targeted predictions (e.g., sex from the age subvector z-age) fell to random level (AUC ≈ 0.50) and failed age regression, confirming robust disentanglement and validating z-rest as a latent vector free from information leakage.
By employing a novel selective masking strategy, our AE successfully disentangles demographic and genetic confounders. The resulting purified baseline (latent vector z-rest) prevents the misinterpretation of healthy inter-subject variations, paving the way for more accurate CVD risk predictions.