Abstract Objective 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 minute 14 seconds and 3 minutes 18 seconds, versus 5 minutes 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.
更多