Cardiovascular Comorbidities as Key Drivers of In-Hospital Mortality in Pneumonia: A Machine Learning and Explainability Analysis

Rafael Garcia-Carretero1, Beatriz Valle Borrego1, Clara Peiro-Villalba1, Oscar Barquero-Perez2
1Hospital Universitario Severo Ochoa, 2University Rey Juan Carlos


Abstract

Background: Cardiovascular (CV) comorbidities are highly prevalent in hospitalised pneumonia patients, yet whether their model-based attribution reflects true causal effects remains unexamined. Aims: To quantify the independent contribution of CV comorbidities to in-hospital mortality using explainable ML and counterfactual analysis. Methods:We analyzed a nationwide Spanish registry (CMBD) comprising 431,092 adults hospitalised for pneumonia in Spain (CMBD, 2021; mortality 8.1%). XGBoost predictin model was used using 29 clinical, microbiological, and demographic features. Explainability was assessed using SHAP values and counterfactual Average Treatment Effect (ATE). CVwere examined: heart failure (HF), hypertension (HTN), acute myocardial infarction (AMI), and stroke. Results: XGBoost achieved the highest discrimination (AUC-ROC = 0.790). age (mean|SHAP| = 0.826), malignancy (0.357), and length of stay (0.282) dominated the model. Among CV features, HF ranked highest (0.155), followed by HTN (0.085). Directional analysis revealed a clinically important paradox: HF (SHAP = +0.320) and stroke (SHAP = +0.557) correctly reflected higher crude mortality (12.7% and 14.4%), while HTN showed counterintuitive protective attributions. Counterfactual analysis confirmed the paradox persists: ATE(HTN) = −0.028 and ATE(AMI) = −0.017, with poor SHAP–counterfactual concordance. Four mechanisms explain this: age confounding, survivorship bias, and unmeasured pharmacological confounding by statins and ACE-inhibitors. Conclusions: HF and stroke are the true high-risk CV predictors in pneumonia. The paradoxical protective attribution of HTN and AMI is model-intrinsic and driven by identifiable biases. Joint SHAP–counterfactual reporting help to identify possible confoundings.