R script of the analysis of Retrospective cohort data to predict HIV treatment Interruption in Ghana.
Predict_IIT — Predicting HIV Treatment Interruption in Ghana
This repository contains all analysis code for the study:
> Kwarah W, da-Costa Vroom FB, Dwomoh D, Bosomprah S.** *Predicting HIV treatment interruption in Ghana: development and evaluation of an individual-level Machine Learning risk model.* BMC Global and Public Health (under review, 2026).
---
## Overview
This project develops and validates a machine learning model to predict Treatment Interruption (TI) — defined as a visit gap of ≥28 days beyond the expected return date (PEPFAR COP 2021) — among people living with HIV (PLHIV) in Ghana. Using routine visit-level data from 33,613 PLHIV across 245 health facilities (2019–2023), an XGBoost model achieved an AUC-ROC of 0.978 on the hold-out test set.
The best model is deployed as an interactive Shiny risk calculator: Predict_TI.
---
Repository Structure
```
HIV_Preatment_Prediction_Ghana/
├──
└── Analysis/
├── TI_Prediction_Analysis_Code.R ← PRIMARY analysis script
```
---
Analysis Script
The script runs end-to-end from raw data to final outputs in 16 sequential sections:
| Section | Description |
|---|---|
| 0 | Libraries and reproducibility seed |
| 1 | Data loading and outcome (TI) derivation from visit-level records |
| 2 | TI prevalence descriptives by calendar year |
| 3 | Feature selection documentation (54 candidates → 33 retained) |
| 4 | Imputation and encoding (KNN imputation, dummy variables, scaling) |
| 5 | Stratified 70/30 train/test split |
| 6 | Model training — 6 algorithms (XGBoost, Random Forest, Logistic Regression, KNN, Naive Bayes, AdaBag) |
| 7 | Cross-validation model comparison |
| 8 | XGBoost hyperparameter tuning via `xgb.cv` |
| 9 | Final model evaluation on hold-out test set (AUC, Sensitivity, Specificity, F1, Kappa with 95% CIs) |
| 10 | Calibration metrics (Brier score, calibration slope/intercept, ECE) |
| 11 | Calibration plot |
| 12 | SHAP global feature importance |
| 13 | Individual-level SHAP waterfal …