Accepted for/Published in: JMIR Medical Informatics
Date Submitted: Jul 21, 2025
Date Accepted: Nov 26, 2025
Machine Learning Prediction of Pharmacogenetic Test Uptake Among Opioid-Prescribed Patients Using Electronic Health Records: A Retrospective Cohort Study
ABSTRACT
Background:
Opioids are a widely prescribed class of medication for pain management. However, they have variable efficacy and adverse effects among patients, due to complex interplay between biological and clinical factors. Pharmacogenetic (PGx) testing can be utilized to match patients’ genetic profiles to individualize opioid therapy, improving pain relief and reducing the risk of adverse effects. Despite its potential, PGx uptake—utilization of PGx testing—remains low due to a range of barriers at the patient, health care provider, infrastructure, and financial levels. Since testing typically involves a shared decision between the provider and patient, predicting likelihood of patient undergoing PGx testing and understanding the factors influencing that decision can help optimize resource use and improve outcomes in pain management.
Objective:
To develop machine learning (ML) models, identifying patients’ likelihood of PGx uptake based on their demographics, clinical variables, medication use, and social determinants of health (SDoH).
Methods:
We utilized electronic health records (EHR) data from a single center healthcare system to identify patients prescribed opioids. We extracted patients’ demographics, clinical variables, medication use, and social determinants of health (SDoH) and developed and validated machine learning (ML) models, including neural networks (NN), logistic regression (LR), random forests (RF), gradient boosting (XGB), naïve bayes (NB), and support vector machines (SVM) for PGx uptake prediction based on procedure codes. We performed 5-fold cross validation (CV) and created an ensemble probability-based classifier using the best-performing ML models for PGx uptake prediction. Various performance metrics, uptake stratification analysis, and feature importance analysis were employed to evaluate the performance of the models.
Results:
The ensemble model using XGB and SVM-RBF classifiers had the highest C-statistics at 79.61%, followed by XGB (78.94%), and NN (78.05%). While XGB was the best-performing model, the ensemble model achieved a high accuracy (67.38%), recall (76.50%), specificity (67.25%), and negative predictive value (99.49%). The uptake stratification analysis using the ensemble model indicated that it can effectively distinguish across uptake probability deciles, where those in the higher strata are more likely to undergo PGx in real-world (6.59% in the highest decile compared to 0.12% in the lowest). Furthermore, SHAP value analysis using the XGB model indicated age, hypertension, and household income as the most influential factors for PGx uptake prediction.
Conclusions:
The proposed ensemble model demonstrated a high performance in PGx uptake prediction among patients using opioids for pain. This model can be utilized as a decision support tool, assisting clinicians in identifying patients’ likelihood of PGx uptake and guiding appropriate decision-making.
Citation
Request queued. Please wait while the file is being generated. It may take some time.
Copyright
© The authors. All rights reserved. This is a privileged document currently under peer-review/community review (or an accepted/rejected manuscript). Authors have provided JMIR Publications with an exclusive license to publish this preprint on it's website for review and ahead-of-print citation purposes only. While the final peer-reviewed paper may be licensed under a cc-by license on publication, at this stage authors and publisher expressively prohibit redistribution of this draft paper other than for review purposes.