Development of Machine Learning Algorithms for Prediction of Sustained Postoperative Opioid Prescriptions After Total Hip Arthroplasty

J Arthroplasty. 2019 Oct;34(10):2272-2277.e1. doi: 10.1016/j.arth.2019.06.013. Epub 2019 Jun 13.


Background: Postoperative recovery after total hip arthroplasty (THA) can lead to the development of prolonged opioid use but there are few tools for predicting this adverse outcome. The purpose of this study is to develop machine learning algorithms for preoperative prediction of prolonged opioid prescriptions after THA.

Methods: A retrospective review of electronic health records was conducted at 2 academic medical centers and 3 community hospitals to identify adult patients who underwent THA for osteoarthritis between January 1, 2000 and August 1, 2018. Prolonged postoperative opioid prescriptions were defined as continuous opioid prescriptions after surgery to at least 90 days after surgery. Five machine learning algorithms were developed to predict this outcome and were assessed by discrimination, calibration, and decision curve analysis.

Results: Overall, 5507 patients underwent THA, of which 345 (6.3%) had prolonged postoperative opioid prescriptions. The factors determined for prediction of prolonged postoperative opioid prescriptions were age, duration of opioid exposure, preoperative hemoglobin, and preoperative medications (antidepressants, benzodiazepines, nonsteroidal anti-inflammatory drugs, and beta-2-agonists). The elastic-net penalized logistic regression model achieved the best performance across discrimination (c-statistic = 0.77), calibration, and decision curve analysis. This model was incorporated into a digital application able to provide both predictions and explanations (available at

Conclusion: If externally validated in independent populations, the algorithms developed in this study could improve preoperative screening and support for THA patients at high risk for prolonged postoperative opioid prescriptions. Early identification and intervention in high-risk cases may mitigate the long-term adverse consequence of opioid dependence.

Level of evidence: III.

Keywords: arthroplasty; machine learning; opioid use; orthopedic surgery; prediction; total hip arthroplasty.

Publication types

  • Evaluation Study

MeSH terms

  • Aged
  • Algorithms
  • Analgesics, Opioid / administration & dosage*
  • Arthroplasty, Replacement, Hip / rehabilitation*
  • Female
  • Humans
  • Logistic Models
  • Machine Learning*
  • Male
  • Middle Aged
  • Opioid-Related Disorders
  • Pain, Postoperative / drug therapy*
  • Postoperative Period
  • Prescriptions / statistics & numerical data*
  • Retrospective Studies
  • Risk Assessment / methods


  • Analgesics, Opioid