Abstract
Background
Postoperative pulmonary infection (PPI) is a common and serious complication in older adults undergoing hip fracture surgery, leading to prolonged hospitalization, increased costs, and increased mortality. However, simple and reliable preoperative predictors remain limited. Therefore, this study aimed to develop and validate a hematology-based machine learning model for the early prediction of PPI in older hip fracture patients.
Methods
A total of 3,944 patients aged ≥ 60 years who underwent hip fracture surgery were retrospectively enrolled from three cohorts: the discovery cohort (n = 1,745, Shanghai Xuhui Central Hospital, 2016–2020), the internal validation cohort (n = 1,306, 2021–2024), and the external validation cohort (n = 893, Shanghai Putuo People’s Hospital, 2016–2024). Twenty-four preoperative hematologic variables were analyzed. Six supervised machine learning algorithms were compared via fivefold cross-validation. Model performance was evaluated by the area under the receiver operating characteristic curve (AUC), accuracy, sensitivity, specificity, F1 score, calibration, and decision curve analysis (DCA).
Results
Patients who developed PPI were generally older and exhibited a neutrophil-dominant inflammatory profile, characterized by higher white blood cell counts, neutrophil, monocyte, platelet, and C-reactive protein levels, and lower lymphocyte, eosinophil, and basophil percentages (all p < 0.001). Among the evaluated algorithms, the extreme gradient boosting (XGBoost) model achieved the best overall performance, with AUCs of 1.00, 0.96, and 0.98 in the discovery, internal, and external cohorts, respectively. Calibration curves suggested good agreement between predicted and observed probabilities, and DCA indicated favorable clinical net benefit across threshold probabilities.
Conclusions
A hematology-based XGBoost model was developed to predict in-hospital PPI in older adults following hip fracture surgery. The model demonstrated good discriminative performance and interpretability in this study cohort, suggesting its potential utility as a supplementary tool for cost-effective perioperative risk stratification. However, further prospective validation in diverse populations and healthcare settings is required to confirm its generalizability and clinical applicability.
Supplementary Information
The online version contains supplementary material available at https://doi.org/10.1186/s12877-026-07906-9.
Keywords: Postoperative pulmonary infection, Hip fracture, Hematology, Older adults, Machine learning, XGBoost, Prediction
Background
Postoperative pulmonary infection (PPI) is one of the most frequent and clinically significant complications following hip fracture surgery in older adults [1, 2]. The reported cumulative incidence ranges from 8% to 25%, and it is strongly associated with prolonged hospitalization, increased healthcare costs, and higher short-term mortality rates [3, 4]. Early identification of patients at high risk for PPI is therefore essential to optimize perioperative management and improve clinical outcomes.
Hip fracture is a common and devastating injury in the elderly population, often leading to substantial morbidity, mortality, and healthcare burdens [5]. Although surgical repair remains the standard treatment to restore mobility and reduce long-term complications, frail older patients are particularly susceptible to postoperative infectious complications, especially pulmonary infections [1, 2].
Recent advances in data-driven and computational approaches have further highlighted the potential of integrating multi-dimensional biomedical information for disease risk prediction and mechanism exploration [6–9], particularly in infection-related and complex clinical conditions. Routine blood tests (complete blood count, CBC) are among the most widely available, cost-effective, and reproducible laboratory examinations in clinical practice [10]. In addition to their diagnostic value in systemic inflammation, several hematologic indices derived from CBC—such as the neutrophil-to-lymphocyte ratio (NLR), platelet-to-lymphocyte ratio (PLR), and lymphocyte-to-monocyte ratio (LMR)—have emerged as reliable markers of immune and inflammatory responses [11–13]. These indices have demonstrated prognostic relevance in various surgical and infectious settings, including cardiovascular surgery, abdominal surgery, and orthopedic trauma [14, 15]. However, evidence regarding their predictive value for PPI following hip fracture surgery in older adults remains limited and inconsistent. For example, in geriatric hip fracture patients, NLR demonstrated only modest discrimination for postoperative outcomes (the area under the receiver operating characteristic curve, AUC = 0.59) [16]. In contrast, Chang Lv et al. [17] reported that red blood cell distribution width was an independent risk factor for postoperative pulmonary infection in elderly patients with hip fracture.
Given the distinct physiological characteristics of geriatric patients—immunosenescence, malnutrition, and frequent comorbidities—the systemic inflammatory response to surgery and infection may differ substantially from that in younger populations [18, 19]. Therefore, evaluating whether preoperative and early postoperative hematologic parameters can serve as early indicators of pulmonary infection risk is of significant clinical importance. Such predictive models based on routine blood tests could enable timely preventive strategies, optimize perioperative management, and ultimately reduce morbidity and mortality in this vulnerable patient population.
Methods
Study cohort definition
This retrospective multicenter study was approved by the Ethics Committee of Shanghai Xuhui Central Hospital and the Ethics Committee of Shanghai Putuo People’s Hospital (Shanghai, China). The study was conducted in accordance with the principles of the Declaration of Helsinki and was approved by the institutional ethics committee. As this was a retrospective study using routinely collected clinical data, written informed consent had been obtained at the time of hospital admission as part of standard clinical practice, allowing the use of de-identified data for research purposes.
The cohort division was primarily based on an independent temporal validation strategy using available consecutive clinical data from two participating centers. A total of 4,306 older patients (≥ 60 years) who underwent hip fracture surgery between January 2016 and December 2024 were initially screened. After applying the inclusion and exclusion criteria, 3,944 patients were categorized into three cohorts:
The discovery cohort included 1,745 patients from Shanghai Xuhui Central Hospital between January 2016 and December 2020, including 158 patients with PPIs and 1,587 noninfected controls.
The internal validation cohort included 1,306 patients from Shanghai Xuhui Central Hospital (different admission periods or wards) between January 2021 and December 2024, including 133 PPI cases and 1,173 controls.
The external validation cohort included 893 patients from Shanghai Putuo People’s Hospital, including 112 PPI patients and 781 controls.
All patients underwent surgical treatment for hip fracture—either internal fixation or hip arthroplasty—under general or spinal anesthesia. A detailed flowchart of patient selection and exclusion is shown in Fig. 1.
Fig. 1.

Flowchart of patient enrollment and cohort allocation. Older patients (≥ 60 years) who underwent hip fracture surgery between January 2016 and December 2024 were screened from two tertiary hospitals. The flow diagram summarizes the screening and exclusion process for each cohort
Inclusion and exclusion criteria
Patients were eligible for inclusion if they met the following criteria:
diagnosis of hip fracture confirmed by imaging (X-ray or CT);
age ≥ 60 years;
underwent surgical treatment (internal fixation or joint replacement);
complete preoperative routine blood test results available;
preoperative blood tests were obtained within 24 hours before surgery;
detailed clinical and hospital observation period information retrievable from the hospital information system.
The exclusion criteria were as follows:
pathological fractures or multiple fractures;
evidence of active infection within 14 days prior to admission, defined as clinically diagnosed infection requiring antimicrobial treatment or documented infection in medical records;
incomplete laboratory or clinical data;
perioperative death unrelated to pulmonary infection (e.g., acute myocardial infarction or stroke); patients who developed PPI and subsequently died were retained in the study population;
receipt of long-term immunosuppressive therapy, defined as continuous use of systemic corticosteroids or other immunosuppressive agents for ≥3 months prior to admission;
those presenting with fever, respiratory symptoms, or radiological evidence of infection before surgery.
After applying these criteria, a total of 362 patients were excluded.
Data collection
Demographic and perioperative variables were extracted from the electronic medical records of the participating hospitals. PPI was defined according to the Centers for Disease Control and Prevention (CDC) criteria [20], requiring at least two of the following: new pulmonary infiltrates on chest imaging, fever (> 38 °C), purulent sputum, and positive sputum or bronchoalveolar lavage cultures. These diagnostic criteria were applied consistently across all participating centers to ensure uniform outcome definition. Chest imaging was performed when clinically indicated, particularly in patients presenting with fever or purulent sputum, in accordance with routine clinical practice.
The outcome assessment period was defined as the interval from surgery to hospital discharge or the occurrence of PPI during hospitalization, whichever occurred first. The outcome in this study was limited to in-hospital PPI, and no post-discharge follow-up was performed.
Laboratory analysis
In our study, all hematological predictors were derived from strictly preoperative laboratory tests collected within a defined time window before surgery. Specifically, venous blood samples (2 mL) were obtained in ethylenediaminetetraacetic acid (EDTA) tubes via standard antecubital venipuncture within 24 h prior to surgery, ensuring consistency across all included patients. Routine blood parameters were analyzed via an automated hematology analyzer (Mindray BC-6800, Shenzhen, China) within 30 min of collection. The following hematologic indices were recorded:
The white blood cell system was as follows: white blood cell count (WBC), neutrophil count (NEUT#), lymphocyte count (LYMPH#), monocyte count (MONO#), eosinophil count (EOS), basophil count (BAS), and their corresponding percentages (NEUT%, LYMPH%, MONO%, EOS%, BAS%).
Red blood cell system: Red blood cell count (RBC), hemoglobin concentration (HG), hematocrit (HCT), mean corpuscular volume (MCV), mean corpuscular hemoglobin (MCH), mean corpuscular hemoglobin concentration (MCHC), and red cell distribution width (RDW-CV).
Platelet system: Platelet count (PLT), mean platelet volume (MPV), plateletcrit (PCT), platelet distribution width (PDW), and platelet–large cell ratio (PLCR); and C-reactive protein (CRP).
Internal quality control was performed daily, and the coefficient of variation (CV) for the measured parameters remained within 3–6% throughout the study period.
Data preprocessing
A total of 24 CBC features were incorporated to construct predictive models for PPI in older patients undergoing hip fracture surgery. Prior to modeling, all variables were examined for data completeness and multicollinearity.
Continuous variables were standardized using z-score normalization to ensure comparability across algorithms. Normalization was performed separately within the discovery cohort, internal validation cohort, and external validation cohort to prevent data leakage and ensure model reproducibility. Specifically, the mean and standard deviation were calculated separately within each cohort and used for within-cohort standardization.
Missing data handling
In our study, for each participant, if more than 20% of the 24 laboratory variables were missing (i.e., ≥ 5 variables), the participant was excluded from the analysis. Participants with ≤ 20% missing values (i.e., ≤ 4 variables) were retained, and missing values were imputed using median imputation to preserve distributional robustness. Importantly, the 24 laboratory variables included in this study were derived from routine complete blood count tests, which are simultaneously generated by automated hematology analyzers. Therefore, missingness at the level of individual variables was rare. According to the predefined inclusion and exclusion criteria, patients with substantial missing data were excluded prior to analysis. As a result, the final analytic cohort contained complete laboratory profiles for all included variables, with minimal or no missingness. Furthermore, all 24 variables were routinely measured parameters derived from standard complete blood count tests, generated simultaneously by automated hematology analyzers. Therefore, all available routine hematology variables were included a priori without additional feature selection based on univariate screening or model-driven selection, in order to preserve clinical interpretability and avoid selection bias.
Machine learning (ML) model development
Model development was conducted using the discovery cohort (Shanghai Xuhui Central Hospital, January 2016 to December 2020). To capture both linear and nonlinear relationships between predictors and outcome, six machine learning algorithms were evaluated, including logistic regression (LR), decision tree (DT), k-nearest neighbors (KNN), support vector machine (SVM), random forest (RF), and extreme gradient boosting (XGBoost).
To ensure robust model training and prevent overfitting, a 5-fold stratified cross-validation strategy combined with stratified bootstrapping was implemented within the discovery cohort. Hyperparameter optimization was performed using an integrated approach combining grid search and Bayesian optimization, with the objective of maximizing the mean AUC across cross-validation folds. Importantly, the entire hyperparameter tuning process was fully embedded within the cross-validation framework, ensuring strict separation between training and validation folds and preventing information leakage.
Model calibration was subsequently optimized using Platt scaling or isotonic regression depending on algorithm-specific calibration performance, and calibration was further assessed using calibration plots. Model performance was compared using the DeLong test to evaluate differences in AUC across models.
The final model was selected based on its overall discrimination performance in the discovery cohort. It was then independently evaluated in two external datasets: the internal validation cohort (Shanghai Xuhui Central Hospital, January 2021 to December 2024), representing a temporally distinct population, and an external validation cohort from Shanghai Putuo People’s Hospital, representing an independent institutional dataset.
All analyses were performed in Python (version 3.11) using the scikit-learn and xgboost packages. A uniform decision threshold was applied across all cohorts to ensure comparability of model evaluation. All final model parameters are reported in Supplementary Table S1.
Model performance evaluation
The discriminative ability of each model was assessed in the discovery, internal, and external validation cohorts via multiple quantitative metrics: accuracy, precision, sensitivity, specificity, F1 score, positive predictive value (PPV), and negative predictive value (NPV). Global classification performance was further quantified via AUC and the area under the precision–recall curve (AUPRC).
Differences in AUCs between models were compared via the DeLong test, a nonparametric approach for correlated ROC curves. The optimal cutoff probability for classification was defined by the maximum Youden index (sensitivity + specificity − 1).
To evaluate the clinical utility and generalizability of the models, calibration curves were plotted to assess the agreement between the predicted and observed infection probabilities, and decision curve analysis (DCA) was applied to estimate the net clinical benefit across a range of threshold probabilities.
Finally, the relative contribution of each hematologic feature to model prediction was visualized via SHapley Additive exPlanations (SHAP) values, enabling transparent interpretation of feature importance and directionality.
Web-based model deployment
We utilized the Streamlit framework to deploy the final model as a web-based tool. This platform supports interactive data entry and provides automated outcome forecasting, including probability scores and classification results.
Sensitivity analysis
To evaluate the robustness of the model to different missing-data scenarios, sensitivity analyses were performed by simulating varying degrees of feature missingness. Specifically, in the external validation cohort, model evaluation was repeated under alternative missingness settings, in which 1 to 3 laboratory variables were artificially set as missing.
The selection of variables for missingness simulation was informed by SHAP-based feature importance ranking in the discovery cohort. Accordingly, four missing-data scenarios were constructed: [1] missing WBC; [2] missing WBC and NEUT#; and [3] missing WBC, NEUT#, and MONO#.
Statistical analysis
Statistical analyses were performed via SPSS 26.0 (IBM, Chicago, IL, USA) and GraphPad Prism 9.0 (La Jolla, CA, USA). Continuous variables are expressed as the mean ± standard deviation (SD) or median (interquartile range, IQR) depending on the data distribution, which was tested via the Kolmogorov–Smirnov test. Between-group comparisons were conducted via the independent-samples t test or Mann–Whitney U test for continuous variables and the chi-square test or Fisher’s exact test for categorical variables. The predictive performance of blood-derived indices was evaluated via receiver operating characteristic (ROC) curves, and AUC, sensitivity, specificity, and optimal cutoff values (Youden indices) were calculated. A two-sided p value < 0.05 was considered statistically significant.
Results
Study population and cohort selection
A total of 4,306 older patients (≥ 60 years) who underwent hip fracture surgery were initially screened from two tertiary hospitals between January 2016 and December 2024. After applying the inclusion and exclusion criteria, 3,944 patients were ultimately enrolled and categorized into three cohorts (Fig. 1). The median hospital observation period was 12 days in patients without PPI and 3 days in those who developed PPI.
In the discovery cohort (Shanghai Xuhui Central Hospital, 2016–2020), 1,886 patients were screened, and 141 were excluded. The remaining 1,745 patients included 158 patients with PPI and 1,587 noninfected controls.
In the internal validation cohort (Xuhui Central Hospital, 2021–2024), 1,429 cases were screened, and 123 were excluded. A total of 1,306 patients were analyzed, including 133 PPI patients and 1,173 noninfected patients.
The external validation cohort included 893 patients from Shanghai Putuo People’s Hospital (2016–2024) after the exclusion of 98 patients. This cohort included 112 PPI patients and 781 noninfected patients.
Overall, the incidence of PPI across all cohorts was 10.2% (403/3,944). It was 9.05% (158/1,745) in the discovery cohort, 10.18% (133/1,306) in the internal validation cohort, and 12.54% (112/893) in the external validation cohort. There was a statistically significant difference in PPI incidence across the three cohorts (P = 0.040).
Summary of baseline hematologic findings
Baseline comparisons between patients with and without PPI revealed consistent hematologic differences across all three cohorts (Tables S2–S4).
Patients who developed PPI were significantly older than noninfected controls were (all p < 0.05). Across all cohorts, infected patients presented markedly greater total WBC counts, NEUT#, and NEUT%, together with lower LYMPH% and EOS% proportions, indicating a neutrophil-dominant inflammatory response and relative lymphopenia (p < 0.001 for all). Platelet indices, including the PLT and PCT, were significantly greater in infected patients (p < 0.001), whereas the EOS% and BAS% were lower, supporting a shift toward innate immune predominance.
Among the red-cell parameters, MCV was slightly reduced in the PPI group in the discovery and internal validation cohorts (p < 0.05), whereas HG, HCT, and MCHC were not significantly different. The RDW-CV was marginally greater in infected patients but not consistently significant. Finally, CRP was markedly elevated in the PPI patients across all cohorts (p < 0.001).
Collectively, these findings suggest that PPIs are associated with a systemic proinflammatory hematologic phenotype characterized by neutrophilia, lymphopenia, thrombocytosis, and elevated CRP, providing the biological foundation for subsequent machine learning model development.
Model construction in the discovery cohort
Using 24 preoperative hematologic features, six supervised machine learning algorithms were developed to predict PPIs in older patients undergoing hip fracture surgery. All the models were trained via fivefold cross-validation in the discovery cohort and optimized via a grid search with Bayesian fine-tuning to achieve the best mean AUC (Table S5, Figure S1).
Across all algorithms, the XGBoost model demonstrated the highest discriminative power, achieving a mean AUC of 1.00 ± 0.00 in fivefold cross-validation (Fig. 2A; Table 1) and an AUC of 0.99 in the precision–recall (PR) analysis (Fig. 2B; Table 1). The confusion matrix (Fig. 2C) indicated an accuracy = 98.7%, sensitivity = 93.5%, and specificity = 99.4%, correctly identifying 29 of 31 infected cases with only four total misclassifications. Based on the maximization of the Youden index, the optimal decision threshold was determined to be 0.6.
Fig. 2.

Model construction and feature interpretation in the discovery cohort. A Receiver operating characteristic (ROC) curves from fivefold cross-validation consistently show perfect discrimination (mean AUC = 1.00 ± 0.00). B Precision–recall (PR) curve with an AUC of 0.99 confirming high sensitivity for detecting PPI cases. C The confusion matrix illustrates excellent classification accuracy (accuracy = 98.7%, sensitivity = 93.5%, specificity = 99.4%). D SHapley Additive exPlanations (SHAP) summary plot ranks the most influential hematologic predictors, including white blood cell count (WBC), neutrophil count (NEUT#), monocyte count (MONO#), mean corpuscular hemoglobin concentration (MCHC), and lymphocyte percentage (LYMPH%). Red indicates a positive SHAP contribution (increased infection risk), and blue indicates a negative contribution (protective effect)
Table 1.
Predictive performance of the machine learning model for predicting postoperative pulmonary infection in three independent cohorts
| AUC | Sensitivity | Specificity | PPV | NPV | Accuracy | F1-score | |
|---|---|---|---|---|---|---|---|
| Discovery cohort | 1.0 | 0.94 | 0.99 | 0.94 | 0.99 | 0.99 | 0.94 |
| Internal validation cohort | 0.96 | 0.83 | 0.97 | 0.78 | 0.98 | 0.96 | 0.8 |
| External validation cohort | 0.98 | 0.73 | 0.99 | 0.89 | 0.96 | 0.96 | 0.8 |
AUC area under the receiver operating characteristic curve, PPV positive predictive value, NPV negative predictive value
In contrast, the alternative models showed slightly lower performance, with mean AUC values ranging from 0.75 to 0.99 (Table S5, Figure S1). Pairwise DeLong tests demonstrated that the AUC of the XGBoost model was significantly greater than those of the DT, RF, SVM, KNN, and LR models (p < 0.05 for all comparisons, Table S6), confirming its superior discriminative capacity and stability. Consequently, the XGBoost model was selected as the final predictive model for subsequent validation analyses.
Model interpretability was further evaluated via SHAP values (Fig. 2D). The most influential predictors for PPI were WBC, NEUT#, MONO#, MCHC, LYMPH%, and NEUT%, followed by CRP and PCT. Higher WBC, NEUT#, and NEUT% values were positively associated with infection risk, whereas elevated LYMPH% and MCHC values were protective. These findings suggest that hematologic inflammatory imbalance—marked by neutrophilia and lymphopenia—is a critical determinant of PPI in elderly hip fracture patients and that the XGBoost algorithm effectively captures these nonlinear relationships.
Model validation across cohorts
In the internal validation cohort, XGBoost model discrimination remained excellent, with an AUC of 0.96 (Fig. 3A; Table 1). The confusion matrix (Fig. 3B) revealed an accuracy = 95.2%, sensitivity = 83.5%, and specificity = 97.3%, correctly identifying 111 of the 133 PPI patients.
Fig. 3.

Internal and external validation of the predictive model. A–B Model performance in the internal validation cohort (Shanghai Xuhui Central Hospital, 2021–2024).The ROC curve had an AUC = 0.96, with high specificity (97.3%) and sensitivity (83.5%). C–D Model performance in the external validation cohort (Shanghai Putuo People’s Hospital, 2016–2024). The ROC curve demonstrated an AUC = 0.98, with accuracy = 95.9%, sensitivity = 73.2%, and specificity = 98.7%.Confusion matrices display the distribution of true versus predicted labels for infected and noninfected patients, confirming strong model generalizability across hospital populations
In the external validation cohort, the XGBoost model maintained strong performance, with an AUC of 0.98 (Fig. 3C; Table 1). As shown in the confusion matrix (Fig. 3D), accuracy = 95.9%, sensitivity = 73.2%, and specificity = 98.7%.
Although sensitivity decreased slightly in the independent dataset, both the PPV (0.89) and NPV (0.96) remained high, confirming model robustness and generalizability across hospital populations.
To assess the robustness of the model under different missing-data scenarios, sensitivity analyses were performed by progressively introducing missingness in key hematologic variables. As shown in the ROC curves (Figure S2), model performance remained consistently high across all simulated conditions, although a gradual decline in discrimination was observed with increasing levels of missingness. Specifically, when WBC was excluded, the model achieved excellent discrimination with an AUC of 0.973. When both WBC and NEUT# were missing, the AUC decreased to 0.931. A further reduction in available features (missing WBC, NEUT#, and MONO#) resulted in an AUC of 0.892.
Model interpretation
To further elucidate how individual hematologic variables contribute to the prediction of PPI, model interpretability was assessed via SHAP force plots (Fig. 4). These plots display the contribution of each variable to the model’s prediction for representative positive (infected) and negative (noninfected) cases.
Fig. 4.

Model interpretability on the basis of SHAP force plots. A Example of a correctly predicted infected patient, where elevated WBC and NEUT# strongly contributed to a positive prediction. B Example of a correctly predicted noninfected patient, where low WBC and NEUT# suppressed infection probability. Red bars represent positive SHAP contributions increasing infection risk, whereas blue bars indicate negative contributions favoring noninfection. C A web-based application using the Streamlit framework
In the infected case (Fig. 4A), markedly elevated WBC (11.16 × 10⁹/L) and NEUT# (7.43 × 10⁹/L) had the strongest positive SHAP effects (+ 0.89 and + 0.01, respectively), decisively shifting the prediction toward “infection.” Slightly increased MONO# and CRP values also made modest positive contributions, whereas a higher EOS% exerted a minor negative effect (− 0.01).
In contrast, for the noninfected case (Fig. 4B), relatively lower WBC (7.6 × 10⁹/L) and NEUT# (4.59 × 10⁹/L) values resulted in strong negative SHAP values (− 0.09 and − 0.01), driving the model prediction toward the “noninfection” outcome. Other hematologic variables, such as MCHC, LYMPH%, and NEUT%, exhibited near-zero SHAP effects, indicating minimal influence on the prediction in this individual.
Overall, the SHAP-based interpretability analysis provides mechanistic insight into the model’s decision process, highlighting that subtle yet quantifiable hematologic changes—detectable through routine preoperative blood tests—underlie the risk stratification for PPI in older hip fracture patients.
To facilitate clinical translation, the optimized XGBoost model was deployed as an interactive web-based platform (Fig. 4C). This tool allows clinicians to input requisite parameters and receive real-time, automated risk assessments for PPI. The application is publicly accessible at https://ppi-risk-assessment.streamlit.app/. Importantly, this web-based tool is intended for research and educational purposes only and should not yet be used as a standalone clinical decision-making tool until further prospective validation is performed.
Clinical utility and calibration of the model
The clinical applicability and calibration of the XGBoost model were evaluated via DCA and calibration plots in both validation cohorts (Fig. 5A–D).
In the internal validation cohort (Fig. 5A), DCA demonstrated that the model provided a consistently greater net clinical benefit than either the “treat-all” or “treat-none” strategies across a wide range of threshold probabilities (0.05–0.75). Similarly, in the external validation cohort (Fig. 5B), the DCA curve of the model remained above the reference strategies, confirming robust clinical utility and generalizability in an independent hospital population.
Fig. 5.

Clinical utility and calibration of the XGBoost model in the validation cohort. A–B Decision curve analysis (DCA) showing that the model (blue line) yields greater net benefit than the “treat-all” (red dashed line) or “treat-none” (green dashed line) strategies across a range of threshold probabilities in both the internal (A) and external (B) validation cohorts. C–D Calibration plots illustrating close alignment between the predicted and observed probabilities for postoperative pulmonary infection in the internal (C) and external (D) cohorts, demonstrating good model calibration and generalizability
Calibration plots further demonstrated good agreement between the predicted probabilities and observed incidence of PPI in both the internal and external validation cohorts (Fig. 5C–D). In the internal validation cohort, the calibration curve of the XGBoost model closely followed the 45° reference line, indicating good agreement without significant systematic deviation. The calibration intercept was − 0.025, and the calibration slope was 0.97. The Brier score was 0.08, suggesting good overall accuracy of probabilistic predictions. Similarly, in the external validation cohort, the model demonstrated robust calibration performance, with a calibration intercept of − 0.05 and a calibration slope of 0.94. The corresponding Brier score was 0.075, further indicating reliable probability estimation and good model generalizability across independent datasets. Minor deviations were observed at the higher predicted probability range (> 0.8), which may be attributed to the relatively small number of high-risk cases in this region. However, these deviations did not materially affect overall calibration performance, as reflected by consistently low Brier scores across both cohorts.
Taken together, these analyses indicate that the XGBoost model not only achieves excellent discrimination but also demonstrates favorable calibration and clinical benefit, supporting its potential application as a preoperative risk assessment tool for predicting PPI in older patients undergoing hip fracture surgery.
Discussion
In this multicenter study, we evaluated the predictive value of preoperative hematologic indices for PPI in older patients undergoing hip fracture surgery. Using three independent cohorts from Shanghai Xuhui Central Hospital and Shanghai Putuo People’s Hospital, we demonstrated that routine blood test parameters were significantly associated with PPI risk. By integrating these biomarkers into machine learning models, we developed and externally validated a robust predictive framework with good discrimination, calibration, and clinical utility.
Our findings are consistent with previous studies showing that systemic inflammatory markers derived from complete blood counts are associated with postoperative infection risk in elderly surgical patients [11, 12, 21]. In particular, elevated NLR and PLR have been reported as potential predictors of infectious complications, reflecting neutrophil-driven inflammation and lymphocyte suppression [2].
However, evidence regarding the predictive value of NLR remains inconsistent, with some studies reporting only modest discrimination (AUC ≈ 0.59) in geriatric hip fracture populations [16], while others demonstrate moderate associations with substantial heterogeneity [16, 22–24]. These discrepancies likely reflect differences in study design, patient characteristics, infection definitions, and perioperative management. This highlights the limitation of single biomarkers and supports the need for integrated multi-parameter models.
Unlike traditional single-marker approaches, our model integrates multiple hematologic variables using machine learning, capturing nonlinear interactions and improving predictive performance compared with conventional logistic regression. Although the discovery cohort achieved very high performance (AUC = 1.00), this likely reflects cohort homogeneity and the strong resampling-based cross-validation strategy rather than overfitting alone, as confirmed by consistent performance in internal and external validation cohorts. Nevertheless, prospective validation is still required to confirm robustness under real-world conditions.
The association between hematologic markers and PPI can be explained by immunosenescence and chronic low-grade inflammation in older adults, characterized by neutrophil activation and lymphocyte dysfunction [19].
A modest but significant difference in PPI incidence was observed across cohorts, with a higher rate in the external validation cohort. This may be related to temporal changes in perioperative management and infection prevention strategies, as well as differences in institutional practice patterns and patient case-mix between centers. Despite these variations, the model maintained stable performance in the external cohort, suggesting robustness to moderate differences in outcome distribution and supporting its generalizability.
To contextualize our findings, traditional scoring systems such as APACHE II and POSSUM-P have shown only moderate predictive performance in elderly hip fracture patients (AUC ~ 0.78–0.79) [25]. More recent models incorporating clinical risk factors report AUCs of 0.84–0.89 [26]. In comparison, our hematology-based model demonstrates superior discrimination while relying solely on routinely available laboratory data.
The present study underscores the clinical utility of routine blood tests as inexpensive, noninvasive, and universally accessible tools for the early identification of patients at high risk for PPI. Distinct from imaging or culture-based diagnostics, CBC-derived indices allow for preoperative assessment and longitudinal monitoring throughout the perioperative period. By integrating these markers into predictive algorithms or electronic health record systems, our model facilitates real-time risk stratification to guide targeted interventions-such as respiratory physiotherapy and early mobilization-thereby reducing morbidity and mortality in frail older populations. From a translational perspective, the model is designed for immediate clinical adoption, leveraging standard laboratory parameters available at admission without requiring additional infrastructure or costs. To bridge the gap between algorithmic development and bedside application, we developed a Streamlit-based web tool that enables immediate, individualized risk estimation. This intuitive interface supports timely clinical decision-making and holds particular promise for resource-limited settings, ensuring that high-performance risk assessment is accessible at the point of care.
A key methodological consideration in this study is the temporal structure of the cohorts. The discovery cohort (2016–2020) was used for model development, while the internal (2021–2024) and external (2016–2024, independent center) validation cohorts were used to assess robustness and generalizability. This design reflects a real-world scenario in which predictive models are applied to future and temporally distinct patient populations. We acknowledge that this temporal stratification may introduce heterogeneity due to changes in clinical practice, perioperative management, infection prevention strategies, and laboratory systems over time, which could influence both outcome incidence and predictor distributions. Despite these potential secular trends, the model demonstrated consistently strong performance across both temporally separated and externally independent cohorts, suggesting robustness to temporal variation. This indicates that routine hematological parameters may capture relatively stable physiological and inflammatory signals associated with infection risk. Nevertheless, temporal drift remains a limitation. Future studies with prospective design and dynamic model updating or recalibration will be needed to ensure sustained performance and long-term clinical applicability.
Nevertheless, several limitations should be acknowledged. First, as a retrospective study, residual confounding from unmeasured variables (e.g., nutritional status, frailty index, and intraoperative ventilation parameters) cannot be excluded. We also acknowledge that, as a retrospective study, blinding of outcome assessors was not feasible. However, to minimize potential classification bias, outcome identification was based on standardized clinical records, including documented diagnoses, laboratory findings, and radiographic evidence, in accordance with CDC definitions. Second, despite rigorous data quality control, single-time-point hematologic measurements may not fully capture dynamic inflammatory changes throughout the perioperative course. Third, although external validation was performed, both centers were located within Shanghai, and future prospective multicenter studies across different regions are warranted to confirm broader applicability. Fourth, our models focus exclusively on preoperative laboratory and demographic variables; integration with postoperative physiological parameters and radiological findings may further improve prediction accuracy. Fifth, although the model achieved better predictive performance using hematologic variables, it did not incorporate established clinical risk factors such as age, comorbidities, chronic obstructive pulmonary disease, frailty status, ASA classification, nutritional indicators (e.g., albumin), anesthesia type, and surgical-related variables. The absence of these parameters may introduce residual confounding and limits direct comparison with traditional clinical risk models. Future studies integrating both laboratory biomarkers and structured clinical variables are warranted to further improve model interpretability and clinical applicability. Sixth, the outcome of this study was restricted to in-hospital postoperative pulmonary infection occurring before discharge. Therefore, infections developing after discharge or during post-acute care or rehabilitation were not captured. Given that elderly hip fracture patients remain at elevated risk for delayed pulmonary complications after hospitalization, this may lead to underestimation of the true incidence of postoperative infection. Future prospective studies with extended follow-up across different care settings are needed to evaluate the predictive performance of the model for long-term postoperative outcomes. Finally, a limitation of this study is that patients undergoing different surgical procedures (internal fixation versus hip arthroplasty) were analyzed together without explicitly assessing whether surgical type modifies the predictive performance of the model. Given that these procedures differ in operative trauma, duration, and perioperative management, they may influence the risk of postoperative pulmonary infection and potentially interact with hematologic predictors. Future studies with larger sample sizes should perform stratified analyses or incorporate interaction terms to evaluate the potential modifying effect of surgical type on model performance.
Conclusion
In summary, this study suggests that routine blood test parameters may have predictive value for in-hospital PPI in older patients undergoing hip fracture surgery. The findings indicate potential utility for supporting perioperative risk assessment; however, further prospective studies and external validation in diverse populations are needed. Future work may also explore the development of real-time risk monitoring systems based on electronic medical records to support earlier clinical intervention and potentially improve surgical outcomes in geriatric orthopedics.
Supplementary Information
Acknowledgements
None.
Abbreviations
- AUC
Area under the receiver operating characteristic curve
- AUPRC
Area under the precision–recall curve
- BAS
Basophil count
- BAS%
Basophil percentage
- CBC
Complete blood count
- CRP
C-reactive protein
- CT
Computed tomography
- CV
Coefficient of variation
- DCA
Decision curve analysis
- DT
Decision tree
- EDTA
Ethylenediaminetetraacetic acid
- EOS
Eosinophil count
- EOS%
Eosinophil percentage
- F1-score
Harmonic mean of precision and recall
- HCT
Hematocrit
- HGB
Hemoglobin
- IQR
Interquartile range
- KNN
k-nearest neighbors
- LMR
Lymphocyte-to-monocyte ratio
- LR
Logistic regression
- LYMPH#
Lymphocyte count
- LYMPH%
Lymphocyte percentage
- MCH
Mean corpuscular hemoglobin
- MCHC
Mean corpuscular hemoglobin concentration
- MCV
Mean corpuscular volume
- ML
Machine learning
- MONO#
Monocyte count
- MON%
Monocyte percentage
- MPV
Mean platelet volume
- NEUT#
Neutrophil count
- NEUT%
Neutrophil percentage
- NPV
Negative predictive value
- NLR
Neutrophil-to-lymphocyte ratio
- PCT
Plateletcrit
- PDW
Platelet distribution width
- PLCR
Platelet–large cell ratio
- PLR
Platelet-to-lymphocyte ratio
- PLT
Platelet count
- PPI
Postoperative pulmonary infection
- PPV
Positive predictive value
- PR
Precision–recall curve
- RBC
Red blood cell count
- RDW-CV
Red cell distribution width–coefficient of variation
- RF
Random forest
- ROC
Receiver operating characteristic curve
- SD
Standard deviation
- SHAP
SHapley Additive exPlanations
- SVM
Support vector machine
- WBC
White blood cell count
- XGBoost
Extreme gradient boosting
Authors' contributions
Zhen Xu: Writing – original draft, Validation, Methodology, Investigation, Formal analysis, Data curation. Jinyu Liu: Validation, Data curation. Fei Chen: Visualization, supervision, conceptualization. Yunxiao Song: Writing – review & editing, supervision, project administration, conceptualization. Yinwang Zhang: Writing – review & editing, supervision, project administration, conceptualization. Tianyao Zhou: Investigation, Data curation. Zhengjian Qu: Investigation, Methodology. Fuhai Liu: Resources, Supervision. Jingyuan Zhang: Visualization, Clinical consultation.
Funding
The authors have no funding to report.
Data availability
Data will be made available upon request.
Declarations
Ethics approval and consent to participate
This retrospective multicenter study was approved by the Ethics Committee of Shanghai Xuhui Central Hospital and the Ethics Committee of Shanghai Putuo People’s Hospital (Shanghai, China). The study was conducted in accordance with the principles of the Declaration of Helsinki, and written informed consent was obtained from all participants or their legal guardians.
Consent for publication
Not applicable.
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Zhen Xu, Jinyu Liu and Fei Chen contributed equally to this work.
Contributor Information
Yunxiao Song, Email: xzxsh@sina.com.
Yinwang Zhang, Email: zhangyw1211@sina.com.
References
- 1.Tong X, Ci C, Chen J, Sun M, Zhao H, Wei H, Yu T, Wang H, Yang W. Incidence and risk factors for postoperative nosocomial pneumonia in elderly patients with hip fractures: A single-center study. Front Surg. 2023;10:1036344. 10.3389/fsurg.2023.1036344. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 2.Tian Y, Zhu Y, Zhang K, Tian M, Qin S, Li X, Zhang Y. Incidence and risk factors for postoperative pneumonia following surgically treated hip fracture in geriatric patients: a retrospective cohort study. J Orthop Surg Res. 2022;17:179. 10.1186/s13018-022-03071-y. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 3.Yao W, Sun X, Tang W, Wang W, Lv Q, Ding W. Risk factors for hospital-acquired pneumonia in hip fracture patients: a systematic review and meta-analysis. BMC Musculoskelet Disord. 2024;25:6. 10.1186/s12891-023-07123-0. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 4.Mitsutake S, Lystad RP, Okuba T, Long JC, Braithwaite J, Hirata T, Mitchell R. Effect of hospital-acquired complications on hospital length of stay and cost for older adults after a hip fracture in New South Wales, Australia. Osteoporos Int. 2025;36:1267–75. 10.1007/s00198-025-07536-8. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 5.HIP ATTACK Investigators. Accelerated surgery versus standard care in hip fracture (HIP ATTACK): an international, randomised, controlled trial. Lancet. 2020;395:698–708. 10.1016/S0140-6736(20)30058-1. [DOI] [PubMed] [Google Scholar]
- 6.Yan S, Han Z, Wang T, Wang A, Liu F, Yu S, Xu L, Shen H, Liu L, Lin Z, et al. Exploring the Immune-related Molecular Mechanisms Underlying the Comorbidity of Temporal Lobe Epilepsy and Major Depressive Disorder through Integrated Data Set Analysis. Curr Mol Pharmacol. 2024;17:e18761429380394. 10.2174/0118761429380394250217093030. [DOI] [PubMed] [Google Scholar]
- 7.Wang G, Yan S, Zhang L, Lin L, Liu R, Han Y, Zhao Y. Machine Learning-Driven PCDI Classifier for Invasive PitNETs. Curr Gene Ther. 2025. 10.2174/0115665232399193250529074831. [DOI] [PubMed] [Google Scholar]
- 8.Roy AA, Pokale R, Mukharya A, Nikam AN, Dua K, Rao BSS, Seetharam RN, Mutalik S. Synergizing CRISPR-Cas9 with Advanced Artificial Intelligence and Machine Learning for Precision Drug Delivery: Technological Nexus and Regulatory Insights. Curr Gene Ther. 2025;25:467–96. 10.2174/0115665232342293241120033251. [DOI] [PubMed] [Google Scholar]
- 9.Gomase VS, Dhamane SP, Kemkar KR, Kakade PG, Sakhare AD. Immunoproteomics: Approach to Diagnostic and Vaccine Development. Protein Pept Lett. 2024;31:773–95. 10.2174/0109298665342261240912105111. [DOI] [PubMed] [Google Scholar]
- 10.Foy BH, Petherbridge R, Roth MT, Zhang C, De Souza DC, Mow C, Patel HR, Patel CH, Ho SN, Lam E, et al. Haematological setpoints are a stable and patient-specific deep phenotype. Nature. 2025;637:430–8. 10.1038/s41586-024-08264-5. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 11.Yao W, Wang W, Tang W, Lv Q, Ding W. Neutrophil-to-lymphocyte ratio (NLR), platelet-to-lymphocyte ratio (PLR), and systemic immune inflammation index (SII) to predict postoperative pneumonia in elderly hip fracture patients. J Orthop Surg Res. 2023;18:673. 10.1186/s13018-023-04157-x. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 12.Hong S-W, Jeong H-C, Kim S-H. The Neutrophil-to-Lymphocyte Ratio and Preoperative Pulmonary Function Test Results as Predictors of In-Hospital Postoperative Complications after Hip Fracture Surgery in Older Adults. J Clin Med. 2022;12:108. 10.3390/jcm12010108. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 13.Shaukat W, Baig AM, Ali Z, Kumari K, Tariq T, Soomro AK, Flemming A, Hamayun Khan MT. Prognostic Value of C-reactive Protein and Neutrophil-to-Lymphocyte Ratio in Predicting Postoperative Infections After Gastrointestinal Surgery: A Meta-Analysis. Cureus. 2025;17:e91123. 10.7759/cureus.91123. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 14.He Y-M, Liu X, Zhong S-Y, Fu Q-H. Neutrophil-to-lymphocyte ratio in relation to trauma severity as prognosis factors in patients with multiple injuries complicated by multiple organ dysfunction syndrome: A retrospective analysis. Immun Inflamm Dis. 2023;11:e1031. 10.1002/iid3.1031. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 15.Tzikos G, Alexiou I, Tsagkaropoulos S, Menni A-E, Chatziantoniou G, Doutsini S, Papavramidis T, Grosomanidis V, Stavrou G, Kotzampassi K. Neutrophil-to-Lymphocyte Ratio and Platelet-to-Lymphocyte Ratio as Predictive Factors for Mortality and Length of Hospital Stay after Cardiac Surgery. J Pers Med. 2023;13:473. 10.3390/jpm13030473. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 16.Forget P, Dillien P, Engel H, Cornu O, De Kock M, Yombi JC. Use of the neutrophil-to-lymphocyte ratio as a component of a score to predict postoperative mortality after surgery for hip fracture in elderly subjects. BMC Res Notes. 2016;9:284. 10.1186/s13104-016-2089-0. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 17.Lv C, Chen S, Shi T, Jia M. Risk Factors Associated With Postoperative Pulmonary Infection in Elderly Patients With Hip Fracture: A Longitudinal Study. Clin Nurs Res. 2022;31:1454–61. 10.1177/10547738221114713. [DOI] [PubMed] [Google Scholar]
- 18.Theodorakis N, Feretzakis G, Hitas C, Kreouzi M, Kalantzi S, Spyridaki A, Kollia Z, Verykios VS, Nikolaou M. Immunosenescence: How Aging Increases Susceptibility to Bacterial Infections and Virulence Factors. Microorganisms (2024) 12:2052. 10.3390/microorganisms12102052 [DOI] [PMC free article] [PubMed]
- 19.Fu Y, Wang B, Alu A, Hong W, Lei H, He X, Shi H, Cheng P, Yang X. Immunosenescence: signaling pathways, diseases and therapeutic targets. Signal Transduct Target Ther. 2025;10:250. 10.1038/s41392-025-02371-z. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 20.Guidelines for Preventing Health-Care–Associated Pneumonia. 2003. https://www.cdc.gov/mmwr/preview/mmwrhtml/rr5303a1.htm?utm_source=chatgpt.com [Accessed October 28, 2025].
- 21.Tang W, Yao W, Wang W, Ding W, Ni X, He R. Association between admission albumin levels and 30-day readmission after hip fracture surgery in geriatric patients: a propensity score-matched study. BMC Musculoskelet Disord. 2024;25:234. 10.1186/s12891-024-07336-x. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 22.Golsorkhtabaramiri M, Mckenzie J, Potter J. Predictability of Neutrophil to Lymphocyte Ratio in preoperative elderly hip fracture patients for post-operative short-term complications: a retrospective study. BMC Musculoskelet Disord. 2023;24:227. 10.1186/s12891-023-06211-5. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 23.Qian B, Zheng Y, Jia H, Zheng X, Gao R, Li W. Neutrophil-lymphocyte ratio as a predictive marker for postoperative infectious complications: A systematic review and meta-analysis. Heliyon. 2023;9:e15586. 10.1016/j.heliyon.2023.e15586. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 24.Liu C, Zheng J, Bai Y, Gan L, Gu Y. Neutrophil-to-lymphocyte ratio for predicting postoperative mortality after hip fracture surgery: a systematic review and meta-analysis. J Orthop Surg Res. 2025;20:1072. 10.1186/s13018-025-06495-4. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 25.Bujakovic T, Delibegovic S. The possibility of using the APACHE II score in prognosis of the development of postoperative complications in the elderly with hip fractures. Eur J Orthop Surg Traumatol. 2025;35:193. 10.1007/s00590-025-04302-8. [DOI] [PubMed] [Google Scholar]
- 26.Huang J, Ge H, Zhu X, Xue C, Su Q, Chen X, Cheng B. Risk factors analysis and nomogram construction for postoperative pulmonary infection in elderly patients with hip fractures. Aging Clin Exp Res. 2023;35:1891–9. 10.1007/s40520-023-02480-1. [DOI] [PMC free article] [PubMed] [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
Data will be made available upon request.
