Deep learning survival analysis with time-varying covariates: extending PyCox to assess COVID-19 antiviral treatments and long-COVID associations.
Journal:
JAMIA open
Published Date:
Sep 4, 2026
(3)
Abstract
OBJECTIVES: To extend the PyCox to accommodate time-varying covariates using counting process data, addressing immortal time bias in survival analysis. MATERIALS AND METHODS: We modified PyCox to support counting process data structures for time-varying covariates and applied it to 2 246 913 Medicare beneficiaries aged ≥65 with COVID-19 (January-September 2022; 2 785 807 longitudinal records). We compared traditional Cox regression, original PyCox, and modified PyCox in estimating associations between early antiviral treatment (nirmatrelvir or molnupiravir) and long-COVID. Performance metrics included concordance index (C-index), integrated Brier score (IBS), and integrated negative binomial log-likelihood (IBLL) and time-dependent Area Under the Receiver Operating Characteristic Curve (AUC), Brier score, and permutation importance. RESULTS: Among patients, 19.5% received nirmatrelvir, 2.6% received molnupiravir, and 14% developed long-COVID. Traditional Cox and modified PyCox produced concordant hazard ratios (HR) for nirmatrelvir (0.874 and 0.878) and molnupiravir (0.909 and 0.918); original PyCox estimated stronger associations (HR = 0.822 and 0.879). The treatment-effect difference formed a gradient: 3.5-4.0 percentage-points for time-varying models, 4.6 for time-fixed Cox, and 5.7 for time-fixed PyCox. Discrimination, calibration, and fit were comparable overall; modified PyCox showed higher time-dependent AUCs (0.536-0.609) than time-fixed PyCox (0.481-0.519) and relied on largely different top predictors. Modified and original PyCox trained in 1 min 14 s and 3 min 18 s, vs 5 min for traditional Cox. DISCUSSION: Treatment-contrast magnitude and covariate importance varied by models, suggesting temporal covariate structure and modeling approach jointly influence treatment-effect estimates. CONCLUSION: Extending PyCox to accommodate time-varying covariates improves computational efficiency while maintaining estimation accuracy comparable to standard time-varying methods.
Authors
Keywords
No keywords available for this article.