Abstract
In fields such as healthcare and insurance, predicting the timing of an event—survival analysis—is often more critical than predicting its occurrence alone. While modern machine learning (ML) models like Random Survival Forests and Deep Learning offer superior predictive accuracy over traditional statistical methods, their "black box" nature limits their utility in high-stakes environments. This paper introduces survex, an R package that provides a unified, model-agnostic framework for explaining complex survival models. By addressing the unique challenges of survival data, such as censoring and time-dependent outputs, survex enables both local and global interpretations of complex predictive algorithms.
Introduction
Survival analysis is a cornerstone of clinical research and risk assessment. However, the transition from interpretable models like the Cox Proportional Hazards model to high-performance ML models has created a transparency gap. Standard Explainable AI (XAI) tools, such as the original SHAP or LIME, are generally ill-equipped for survival data for two primary reasons:
- Censoring: Survival studies often involve individuals who leave the study before an event occurs, creating "missing" data that requires specific mathematical handling.
- The Time Dimension: Unlike standard regression, survival models output a survival function (a curve over time) rather than a single scalar value.
survex fills this gap by providing a comprehensive ecosystem to explain any survival model, making powerful ML tools transparent enough for clinical and research applications.
The survex Framework
The core of survex is the explainer object, a model-agnostic wrapper that unifies over 30 different survival model types from various R packages (e.g., ranger, survival, mlr3proba) and even Python-based models via the reticulate interface. This architecture ensures that as new survival algorithms emerge, they can be integrated into the survex ecosystem with minimal effort.
Local and Global Explanations
survex introduces several sophisticated techniques tailored for time-to-event data:
- SurvSHAP(t): An evolution of SHAP values that calculates variable contributions at every specific time point. This allows researchers to observe how a risk factor’s importance may fluctuate over the duration of the study.
- SurvLIME: A local explanation method that fits a simple, interpretable Cox model to the neighborhood of a specific prediction to explain its rationale.
- Global Explanations: The package implements Partial Dependence (PD) and Accumulated Local Effects (ALE) plots tailored for survival curves. ALE plots are particularly valuable as they provide a more accurate reflection of variable effects when features are highly correlated, a common occurrence in real-world data.
Performance and Diagnostics
Beyond interpretability, survex includes a suite of survival-specific performance metrics and diagnostic tools. These include the time-dependent Brier score, C-index, and Cumulative/Dynamic AUC. It also supports residual analysis through Cox-Snell, Martingale, and Deviance residuals, allowing for thorough model validation.
Applications and Utility
While survex is a software-focused contribution, its utility has been demonstrated in several recent real-world studies:
- Oncology: Identifying the relative importance of variables in sporadic pancreatic cancer survival models.
- Medical Imaging: Analyzing partial dependence plots of body composition parameters extracted from CT scans.
- Clinical Operations: Detecting and explaining model bias in predicting hospital length of stay.
Key Insights
A fundamental shift introduced by survex is the treatment of explanations as functions rather than scalars. In survival analysis, a feature's impact is rarely static; it may be critical for short-term survival but irrelevant for long-term outcomes. By acknowledging this time-dependency, survex provides a more nuanced and honest representation of model behavior.
Limitations and Future Work
Currently, survex primarily handles right-censored data with a single event type. The authors have identified several avenues for future development:
- Competing Risks: Extending support to models where multiple types of events can occur (e.g., death from a specific disease vs. other causes).
- Counterfactuals: Integrating counterfactual explanation methods to answer "what-if" questions, such as how a patient's survival curve might change if a specific clinical marker were improved.
Conclusion
survex represents a significant step forward in making machine learning survival models accessible and trustworthy. By providing a cohesive, user-friendly ecosystem that integrates with major R packages and ggplot2 for visualization, it empowers researchers to move beyond black-box predictions toward actionable, interpretable insights.
Summary updated