Predicting the risk of postoperative constipation in middle-aged and elderly patients with lower limb fractures using machine learning algorithms
Xiaoyan Yang, Wenqiang Li, Qin Xiao, Shiyun Du, Xi Wang, Ying Zhang, Sulian Li

TL;DR
This study uses machine learning to predict postoperative constipation risk in older patients with lower limb fractures, aiming to improve clinical prevention and early intervention.
Contribution
A novel machine learning-based predictive model for postoperative constipation in elderly lower limb fracture patients is developed and validated.
Findings
The logistic regression model showed the best predictive performance for postoperative constipation risk.
Age, femoral fracture, hospital stay length, nutritional risk, and chronic gastritis were identified as key risk factors.
The model can be integrated into clinical systems to flag high-risk patients and guide personalized interventions.
Abstract
To construct and validate a predictive model for the risk of postoperative constipation in middle-aged and elderly patients with lower limb fractures based on machine learning algorithms, so as to provide decision-making support for clinical prevention and early intervention. This study conducted a retrospective analysis of clinical data of 1,128 middle-aged and elderly patients who underwent lower limb fracture surgery between January 2020 and May 2024, with data collection occurring from October to December 2024. Whether constipation occurred or not was used as the outcome variable. Eight machine learning algorithms, namely logistic regression (LR), extreme gradient boosting (XGBoost), random forest (RF), decision tree classifier (DT), complement naive bayes (CNB), multilayer perceptron (MLP), support vector machine (SVM), and K-Nearest neighbors (KNN), were employed to construct…
Genes, proteins, chemicals, diseases, species, mutations and cell lines named across the full text — each resolved to its canonical identifier and authoritative record.
Click any figure to enlarge with its caption.
Fig 1
Fig 2
Fig 3
Fig 4- —http://dx.doi.org/10.13039/501100016350Sichuan Provincial Administration of Traditional Chinese Medicine
- —http://dx.doi.org/10.13039/501100016350Sichuan Provincial Administration of Traditional Chinese Medicine
- —http://dx.doi.org/10.13039/501100016350Sichuan Provincial Administration of Traditional Chinese Medicine
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsGastrointestinal motility and disorders · Machine Learning in Healthcare · Enhanced Recovery After Surgery
Introduction
With the accelerating global aging process, fractures caused by bone fragility have emerged as a significant public health concern. It is projected that the global annual incidence of fractures will reach 5.91 million cases by 2050 [1,2]. In addressing this public health challenge, the management of postoperative complications has become a pivotal factor influencing clinical outcomes. Current evidence indicates that 71.7% of femoral neck fracture patients and 50% of orthopedic surgery patients develop postoperative constipation [3]. This complication not only lead to gastrointestinal discomfort symptoms such as abdominal distension, loss of appetite, and nausea but may also induce severe secondary conditions ranging from electrolyte imbalances to cardiovascular and cerebrovascular events [4]. Consequently, it directly results in prolonged hospital stays, increased medical costs, and exacerbates the socioeconomic burden. Therefore, particular attention should be paid to postoperative constipation in middle-aged and elderly patients with lower extremity fractures. Although existing studies have identified scattered risk factors such as age and postoperative bed-rest time [5], there is a lack of systematic prediction tools. Machine learning technology is triggering a paradigm shift in the medical field. Compared to traditional statistical models, artificial intelligence (AI) models possess unique advantages in handling high-dimensional variables and the complex interactions and non-linear relationships among variables. Their dynamic learning mechanisms enable continuous optimization of predictive accuracy as sample sizes increase. Furthermore, advancements in interpretability techniques (e.g., SHAP [SHapley Additive exPlanations]) have significantly mitigated the “black box” problem [6,7]. Multiple model algorithms, including Logistic regression, random forest (RF), and support vector machine (SVM), have been widely applied in disease diagnosis and risk model prediction [8–10]. In the orthopedic field, previous studies have successfully employed random forest to predict deep vein thrombosis [11]. However, there remains a significant research gap in developing prediction models for postoperative constipation-a highly prevalent complication among middle-aged and elderly patients with lower extremity fractures. In this study, by screening multiple variable factors, the variables with differences were used to construct a predictive model for the risk of postoperative constipation in middle-aged and elderly patients with lower limb fractures using machine learning algorithms and systematically comparing the predictive performance of eight distinct algorithms. Our approach provides quantifiable decision support for Enhanced Recovery After Surgery (ERAS) protocols, enabling more precise preventive interventions through a predictive-to-interventional closed-loop management system. This advancement holds significant potential for improving patient quality of care.
Methods and participants
Study participants
Using convenience sampling, we collected clinical data from 1,128 middle-aged and elderly patients who underwent fracture surgery between January 2020 and May 2024 at a tertiary Grade A hospital in Sichuan Province from October to December 2024. Inclusion criteria: (1) Age ≥ 45 years old; (2) Meeting the diagnostic criteria for lower limb fractures; (3) Patients who underwent surgical treatment after admission. Exclusion criteria: (1) Patients with a history of long-term constipation; (2) Patients with organic intestinal diseases; (3) Patients with incomplete data information; (4) Patients who died during hospitalization. The patient flow screening is shown in Fig 1. This study was approved by the Ethics Committee of Affiliated Hospital of Traditional Chinese Medicine, Southwest Medical University (approval number: BY2024031). As this study is retrospective, patients are exempt from providing informed consent.
The patient selection procedure.
Methods
Data collection.
The following data were collected through the hospital’s electronic medical record information system:
(1)Socio-demographic data, including age, gender, body mass index (BMI), occupation, smoking history, and alcohol consumption history.(2)Medical history data: osteoporosis, hypertension, diabetes, coronary heart disease, cerebral infarction, length of hospital stay, fracture site (classified according to postoperative X-ray reports as femoral neck/intertrochanteric/tibiofibular etc.), chronic gastritis (confirmed by gastroscopy reports) and nutritional risk (assessed using the NRS 2002 scale for malnutrition and diagnosed with hypoproteinemia based on blood biochemical indicators).(3)Outcome indicators: Constipation was diagnosed according to the Rome IV criteria [12], and the relevant definition of constipation after orthopedic surgery proposed by Mantegazzi was also referred to [13,14]. Two senior nurses independently evaluated all cases to ensure diagnostic consistency:
① At least one objective symptom:
- No bowel movement for >72 hours postoperatively;
- Difficult defecation (straining >25% of effort);
- Painful defecation. ② ≥ 2 subjective symptoms:
- Reduced stool volume (Bristol Stool Scale type 1–2)
- Abdominal pain (VAS ≥ 4);
- Bloating/distension;
- Loss of appetite
③ If the patient required enema for bowel movement, it was considered that the patient had constipation (documented after 48h of no bowel movement + surgeon approval).
Data preprocessing.
The data preprocessing procedure included data cleaning and feature processing. Variables with missing values exceeding 20% of the total data were removed, while those with less than 20% missing values were imputed. For continuous variables, mean imputation was employed, whereas random imputation was applied for categorical variables. Multiclass categorical variables including gender, education level, and fracture site were independently encoded. Finally, min-max normalization was performed on the dataset to ensure data consistency for subsequent analyses.
Statistical methods.
The data were organized and analyzed using the R statistical software. Data conforming to the normal distribution were expressed as means ± standard deviation (x ± s), data not conforming to the normal distribution were expressed as median, interquartile range (IQR), and count data were expressed as percentage (%). The t-test was used for comparison between groups. In this study, univariate analysis was conducted first. Then, variables with statistical significance (P < 0.05) were screened out through multivariate Logistic regression. Finally, the model was constructed using Python software.
Model development.
Models were constructed based on eight machine-learning algorithms, namely logistic regression (LR), extreme gradient boosting (XGBoost), random forest (RF), Decision Tree, Complement Naive Bayes (CNB), multilayer perceptron (MLP), support vector machine (SVM), and K-Nearest Neighbors (KNN). The hyperparameters for each algorithm are presented in Table 1. First, the dataset was randomly divided into a test set and a training set at a ratio of 8:2. During the training process, the 10-fold cross-validation method was adopted. Each model was evaluated by the receiver operating characteristic curve (ROC curve) and the area under the curve (AUC), sensitivity, specificity, accuracy, and F1-score [15,16]. Shapley Additive Explanation (SHAP) was applied to explain the prediction model with the best performance, and the relevant SHAP values were calculated [17]. Both SHAP value plots and variable importance plots were used to display the contribution of each feature to the model and their respective importance rankings.
Table 1: Parameters of the machine learning algorithms used in the study.
Results
Demographic data
A total of 1,128 middle-aged and elderly patients who underwent lower limb fracture surgery were included, with an age of (70 ± 10) years old. There were 719 females and 409 males. Table 2 shows the baseline data of the patients. According to whether the patients had constipation, they were divided into a constipation group (n = 386) and a non-constipation group (n = 742). Univariate analysis was carried out on the general data of the two groups of patients. There were statistically significant differences in age, body mass index (BMI), fracture site, osteoporosis, chronic gastritis, nutritional risk, cerebral infarction, diabetes, hypertension, and coronary heart disease between the two groups of patients (P < 0.05). There were no statistically significant differences in gender, occupation, surgical history, smoking history, and drinking history (P > 0.05).
Table 2: Comparison of Baseline Data between the Two Groups of Patients.
Logistic multivariate regression analysis
Multivariate logistic regression analysis was performed with postoperative constipation (coded as 0 = no, 1 = yes) in middle-aged and elderly patients with lower extremity fractures as the dependent variable, and factors showing significant differences in univariate analysis as independent variables. As presented in Table 3, age, length of hospital stay, fracture site, chronic gastritis, and nutritional risk were identified as significant influencing factors for postoperative constipation (P < 0.05).
Table 3: Results of Multivariate Logistic Regression Analysis.
Model construction and evaluation
The variables screened out, namely age, length of hospital stay, fracture site, chronic gastritis, and nutritional risk, were used to construct risk prediction models with eight machine-learning algorithms (LR, XGBoost, RF, Decision Tree, CNB, MLP, SVM, KNN). To evaluate the prediction models and prevent overfitting, we employed a 10-fold cross-validation approach for model training and validation. This method partitions the entire dataset into 8 training subsets and 2 validation subsets in each iteration, ensuring all data points are used for both training and testing. Through this process, we calculated the AUC values, accuracy, sensitivity, specificity, and F1-scores for all eight prediction models using confusion matrices (Table 4).
Table 4: Evaluation metrics of the models constructed by each algorithm.
The results demonstrated that in the training set, the AUC values for LR, XGBoost, RF, DT, CNB, MLP, SVM, and KNN algorithms were 0.743, 0.965, 0.992, 0.996, 0.654, 0.647, 0.737, and 0.838, respectively (Fig 2a). Corresponding AUC values in the validation set were 0.736, 0.666, 0.669, 0.567, 0.650, 0.640, 0.732, and 0.666 (Fig 2b). The logistic regression (LR) model showed the smallest performance discrepancy between training and validation sets (ΔAUC = 0.007), indicating superior generalization capability. Moreover, its other metrics (F1 = 0.552, Kappa = 0.304) significantly outperformed other models. Notably, XGBoost, RF, and DT models achieved exceptionally high training AUCs (>0.96) but exhibited substantial performance degradation in validation (ΔAUC>0.25), with DT performing particularly poorly (AUC = 0.567), suggesting overfitting. Comprehensive evaluation incorporating calibration curves (Fig 3a) and decision curve analysis (Fig 3b) from the validation set confirmed that the LR-based model delivered optimal and most stable performance, followed by SVM, XGBoost and KNN algorithms Fig 3.
ROC curves for each model in the training and validation sets.(a) ROC curves in the training set; (b) ROC curves in the validation set.
Calibration curves and DCA curves for each model in the validation set.(a) Calibration curves in the validation set; (b) DCA curves in the validation set.
We used the logistic regression (LR) machine-learning algorithm to build a prediction model, and further calculated the SHAP value of each feature to understand the contribution of features in the prediction model based on the logistic regression (LR) algorithm to the prediction results. Fig 4a shows the importance ranking of each feature according to the mean absolute SHAP value. The larger the absolute value of the SHAP of a feature, the more it implies that the feature has a greater impact on the LR-based prediction model. The results show that four features, namely age, length of hospital stay, fracture site, and nutritional risk, are important variables affecting the outcome. Fig 4b shows the correlation between the value of each feature and the SHAP value. Red dots represent higher values of this feature, while blue dots represent lower values of this feature.
SHAP values and feature interaction scores in logistic regression (LR)-based prediction.(a) Contributing factors were ranked in descending order of importance; (b) The distribution of the impacts of each feature on the model output.
Discussion
Constipation, as a prevalent complication, frequently occurs during the postoperative recovery period of fractures in multiple anatomical sites, including the hip and lower limbs. It is mainly characterized by insufficient defecation or difficult bowel movements, accompanied by abdominal pain and distension [18,19]. The onset of constipation can exert a profound impact on patients [20,21]. Firstly, constipation can impair the gastrointestinal barrier function of patients, elevating the incidence of other gastrointestinal disorders [22]. In extreme cases, it may even trigger cardiovascular and cerebrovascular diseases during forced defecation. Secondly, constipation can further deteriorate the nutritional status of patients, leading to psychological issues such as irritability and anxiety [23]. In severe instances, it may impede fracture healing, prolong the length of hospital stay, and diminish the patients’ quality of life [24,25]. Therefore, systematically predicting the risk of postoperative constipation in middle-aged and elderly patients with lower limb fractures facilitates early detection and timely intervention, thereby reducing the incidence of secondary complications. This is of great significance for improving patients’ prognosis.
In recent years, with the continuous increase in the quantity and complexity of biomedical data, machine-learning (ML) methods are becoming popular tools for creating predictive models in biomedicine [26]. Disease prediction models can combine two or more pieces of relevant patient data to predict clinical outcomes, assist in medical decision-making, and improve clinical work efficiency. In this study, eight machine-learning algorithms were employed to construct models for predicting the risk of constipation after lower limb fracture surgery in middle-aged and elderly patients based on their clinical data. We found that the prediction model based on the LR algorithm showed the best performance. This model’s predicted probabilities were closer to the actual situation, indicating excellent clinical utility [27]. This observation may be attributed to the predominance of binary variables in our dataset and the sample size aligning with LR’s superior performance characteristics for “small-sample, low-dimensional” data. Compared to previous studies developing and validating nomograms for predicting postoperative constipation in elderly patients undergoing hip fracture surgery [14], our machine learning approach not only identified the optimal predictive model through comprehensive algorithm comparison, but also demonstrated higher AUC values in both training and validation sets using the LR model.
Our study employed SHAP analysis to interpret the predictive model, revealing that age, length of hospital stay, fracture site, nutritional risk, and chronic gastritis were significant risk factors for postoperative constipation after fractures. These findings are partially supported by previous research. Notably, several studies have identified constipation as one of the most common complications following osteoporotic fractures. Specifically, compared to patients aged 50–59 years, those in the 70–79 age group demonstrated a significantly higher risk of developing somatic complications [28]. Additionally, constipation represents one of the most prevalent gastrointestinal dysfunctions in middle-aged and elderly populations, with its incidence increasing progressively with age. Age-related neuronal loss mediates alterations in colonic motility and rectal sensitivity, collectively contributing to functional defecation disorders in this demographic [29,30]. Furthermore, advancing age is associated with significant changes in body composition and energy reserves, predisposing individuals to hypoproteinemia and malnutrition through multiple pathological mechanisms [31–33]. Recent studies have identified the Prognostic Nutritional Index (PNI) as a predictive factor for postoperative complications and 2-year mortality in hip fracture patients [34], highlighting the critical role of nutritional status in determining clinical outcomes. The fracture-induced trauma triggers an inflammatory response that reduces serum albumin levels, leading to hypoalbuminemia. Notably, research has demonstrated that low serum albumin serves as an indicator of inflammatory severity [35]. This inflammatory cascade increases intestinal capillary permeability, causing mucosal edema and subsequent malabsorption of nutrients [36]. Extensive evidence confirms that chronic malnutrition is associated with persistently low albumin levels, which has been widely adopted as a biomarker of nutritional status [37]. When patients experience prolonged malnutrition, it results in gastric mucosal atrophy, decreased neuromuscular cellularity, and impaired intestinal motility, collectively exacerbating constipation development. A prospective cohort study [38] demonstrated that dietary dairy supplementation significantly improved self-reported gastrointestinal symptoms (including constipation and bloating) through gut microbiota modulation, suggesting that nutritional intervention represents an effective strategy for constipation prevention. Malnutrition, a well-established risk factor for functional constipation in the elderly populations, has been shown to concurrently increases the incidence of other postoperative adverse events [33,39]. For instance, it can prolong the length of hospital stay, with studies demonstrating an approximately 50% prevalence among inpatients-particularly middle-aged and elderly patients. This risk exhibits a clear duration-dependent relationship, where longer hospital stays correlate with both higher constipation incidence and greater the impact on patients’ quality of life [40]. Notably, constipation is particularly prevalent among middle-aged and elderly in-patients with lower limb fractures, especially those with femoral fractures. It not only affects the rehabilitation efficiency of patients but also reduces the functional recovery of the body after discharge [41–43]. Multiple studies have also indicated that the fracture site directly influences the occurrence of postoperative complications. For example, pulmonary complications are common after hip fracture surgery [44], while infections are more prevalent after ankle fracture surgery [45,46]. Although constipation is a common postoperative complication among middle-aged and elderly patients with lower extremity fractures, its incidence varies significantly depending on fracture location due to differential impacts on mobility duration. Notably, we identified chronic gastritis as an independent risk factor for constipation, consistent with the findings reported by Liu [14]et al. A multicenter Chinese study [47] demonstrated that chronic gastritis—characterized by gastric mucosal inflammation primarily caused by Helicobacter pylori infection—is highly prevalent, with a mean patient age of approximately 50 years. H. pylori infection disrupts gastric microbiota composition, reduces gastric acid secretion, and delays gastric emptying, ultimately impairing intestinal motility and contributing to bowel dysfunction [48]. These findings confirm the clinical and biological plausibility of the predictive factors identified by our algorithm, reinforcing its reliability.
This study demonstrates significant potential for clinical translation through three key applications: First, the predictive model can be integrated into electronic medical record (EMR) systems to enable automated, real-time assessment and risk stratification of postoperative constipation. This implementation would enhance clinical vigilance for high-risk patients by providing immediate access to critical indicators (e.g., age, malnutrition parameters) during admission evaluations. Second, the identified risk factors facilitate targeted interventions, including prophylactic bowel management for elderly patients and nutritional support for those at metabolic risk. Finally, this approach optimizes clinical decision-making and resource allocation, demonstrating dual benefits of reduced healthcare costs and improved patient outcomes-particularly when incorporated into Enhanced Recovery After Surgery (ERAS) protocols. The model’s reliance on routinely collected EMR data ensures immediate implementation feasibility while maintaining alignment with precision medicine initiatives.
Conclusion
This study successfully developed and validated a predictive model for the risk of postoperative constipation in middle-aged and elderly patients with lower limb fractures based on machine learning algorithms, demonstrating that the logistic regression model achieved optimal performance in both predictive accuracy (AUC = 0.736) and clinical applicability. Through interpretability analysis, we identified several clinically significant predictors including advanced age, femoral fracture, prolonged hospital stay, nutritional risk, and chronic gastritis, all of which showed strong concordance with established clinical evidence and can facilitate early risk identification and preventive interventions by healthcare providers. This study has limitations as a single-center retrospective analysis without external validation, which precludes definitive conclusions about the model’s generalizability. Nevertheless, it provides valuable evidence-based insights for postoperative complication prevention. Future research directions include multicenter prospective validation to assess the model’s generalizability and development of an integrated risk monitoring system incorporating dynamic postoperative indicators, ultimately aiming to optimize comprehensive fracture management protocols.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1Clynes MA, Harvey NC, Curtis EM, Fuggle NR, Dennison EM, Cooper C. The epidemiology of osteoporosis. Br Med Bull. 2020;133(1):105–17. doi: 10.1093/bmb/ldaa 005 32282039 PMC 7115830 · doi ↗ · pubmed ↗
- 2She P, Yang J, Xu L, Xiong Y, Zhang Z, Wu Z, et al. The effects of We Chat official account based osteoporosis education for patients with fragility fracture in China. Int J Orthop Trauma Nurs. 2022;47:100975. doi: 10.1016/j.ijotn.2022.100975 36403316 · doi ↗ · pubmed ↗
- 3Park Y-G, Kim BS, Kang K-T, Ha Y-C. Effects of Abdominal Massage for Preventing Acute Postoperative Constipation in Hip Fractures: A Prospective Interventional Study. Clin Orthop Surg. 2023;15(4):546–51. doi: 10.4055/cios 22091 37529190 PMC 10375809 · doi ↗ · pubmed ↗
- 4Martikos K, Greggi T, Faldini C, Vommaro F, Scarale A. Osteoporotic thoracolumbar compression fractures: long-term retrospective comparison between vertebroplasty and conservative treatment. Eur Spine J. 2018;27(Suppl 2):244–7. doi: 10.1007/s 00586-018-5605-1 29675674 · doi ↗ · pubmed ↗
- 5Rao J, Liu SQ, Lin Y. Construction of constipation risk prediction model for hip fracture patients after surgery based on SMOTE. Journal of Nursing Research. 2023;37(02):207–11. doi: 10.12102/j.issn.1009-6493.2023.02.004 · doi ↗
- 6Sarker IH. Machine Learning: Algorithms, Real-World Applications and Research Directions. SN Comput Sci. 2021;2(3):160. doi: 10.1007/s 42979-021-00592-x 33778771 PMC 7983091 · doi ↗ · pubmed ↗
- 7Woodman RJ, Mangoni AA. A comprehensive review of machine learning algorithms and their application in geriatric medicine: present and future. Aging Clin Exp Res. 2023;35(11):2363–97. doi: 10.1007/s 40520-023-02552-2 37682491 PMC 10627901 · doi ↗ · pubmed ↗
- 8Heo J, Yoon JG, Park H, Kim YD, Nam HS, Heo JH. Machine Learning-Based Model for Prediction of Outcomes in Acute Stroke. Stroke. 2019;50(5):1263–5. doi: 10.1161/STROKEAHA.118.024293 30890116 · doi ↗ · pubmed ↗
