Hostname: page-component-7b7567c8c-tnzcf Total loading time: 0 Render date: 2026-11-13T05:33:03.586Z Has data issue: false hasContentIssue false

Temporal stability of an electronic health record-driven machine learning model predicting type 2 diabetes among patients with mental illness

Published online by Cambridge University Press:  13 November 2026

Frida Hæstrup
Affiliation:
Center for Humanities Computing, Aarhus University, Aarhus, DenmarkDepartment of Clinical Medicine, Aarhus University, Aarhus, DenmarkDepartment of Affective Disorders, Aarhus University hospital, Aarhus, Denmark
Andreas Aalkjær Danielsen
Affiliation:
Department of Clinical Medicine, Aarhus University, Aarhus, DenmarkPsychosis Research Unit, Aarhus University hospital, Aarhus, Denmark
Søren Dinesen Østergaard*
Affiliation:
Department of Clinical Medicine, Aarhus University, Aarhus, DenmarkDepartment of Affective Disorders, Aarhus University hospital, Aarhus, DenmarkInstitute for Mental and Physical Health and Clinical Translation (IMPACT), Deakin University, Geelong, VIC, Australia
*
Corresponding author: Søren Dinesen Østergaard; Email: soeoes@rm.dk
Rights & Permissions [Opens in a new window]

Abstract

Objectives:

We previously trained and tested a machine learning model to predict incident type 2 diabetes (T2D) in patients with mental illness using electronic health record (EHR) data from routine clinical practice. This hyperparameter-tuned XGBoost model – based on information on sex, age and mean HbA1c within the past two years – predicts whether a patient will meet criteria for T2D in the two years following each contact to psychiatric services. The performance of such a model may drift over time due to changes in standards of care, baseline risk, registration procedures, etc. Therefore, we set out to examine its temporal stability.

Methods:

In the present study, we fitted the model described above on EHR data from January 1, 2013 to December 31, 2017, and examined its stability in predicting T2D two years into the future for patients with contacts in 2018, 2019, 2020, 2021, 2022, and 2023, respectively. Performance was quantified using the area under the receiver operating characteristic curve (AUROC).

Results:

The model showed good discriminative performance across all years (AUROC for 2018 = 0.84, 2019 = 0.83, 2020 = 0.87, 2021 = 0.80, 2022 = 0.84, 2023 = 0.80), with a linear model estimating a decrease in AUROC for T2D prediction of only 0.004 per year (95%CI: –0.024; 0.016). Secondary analyses suggested that models trained on recent data (past year) may achieve similar or better discrimination than models trained on longer historical periods.

Conclusions:

The temporal stability of the T2D prediction model supports its potential for clinical implementation, facilitating early detection and tailored interventions, while highlighting the importance of continued evaluation.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BYCreative Common License - NCCreative Common License - ND
This is an Open Access article, distributed under the terms of the Creative Commons Attribution-NonCommercial-NoDerivatives licence (https://creativecommons.org/licenses/by-nc-nd/4.0/), which permits non-commercial re-use, distribution, and reproduction in any medium, provided that no alterations are made and the original article is properly cited. The written permission of Cambridge University Press or the rights holder(s) must be obtained prior to any commercial use and/or adaptation of the article.
Copyright
© The Author(s), 2026. Published by Cambridge University Press on behalf of Scandinavian College of Neuropsychopharmacology
Figure 0

Figure 1.Figure 1 long description.Extraction of data and outcome, dataset splitting, prediction time filtering, specification of predictors and flattening, model training, testing and evaluation. (A) Data was extracted from the electronic health records. (B) Potential T2D was identified. (C) The dataset obtained is split into an independent training dataset (2013-2017) and six test datasets respective to the years 2018, 2019, 2020, 2021, 2022, and 2023. (D) Prediction times were removed if their lookbehind window extended beyond the start of the dataset or their lookahead extended beyond the end of the dataset. Prediction times were also removed after a patient developed T2D. (E) Predictors for each prediction time were extracted by aggregating the variables within the lookbehind (preceding two years) with multiple aggregation functions. As a result, each row in the dataset represents a specific prediction time with a column for each predictor. (F) The model was trained using the training configuration from the original study and subsequently evaluated on the six independent test sets. True positive predictions were those with predicted probabilities above the decision threshold and the patient developing T2D within the lookahead window. False positive predictions were those where the model’s predicted probability was above the decision threshold, but where none of the T2D criteria were satisfied within the lookahead window. False negatives had predicted probabilities below the threshold, but the T2D criteria were met within the lookahead window. True negatives had predicted probabilities below the threshold, and the patient did not satisfy T2D criteria within the lookahead window. The figure was modified from Bernstorff et al. (2025).

Figure 1

Table 1.Descriptive statistics for (A) contacts and (B) patients that were eligible for prediction for training (2013–2017) and evaluation years (2018–2023)Table 1 long description.

Figure 2

Figure 2.Discrimination on unseen data over time. Points represent yearly AUROC values from 2018 to 2023. The inset depicts the same points zoomed in on the area marked by the dashed grey lines. The solid blue line on the inset shows a fitted linear regression (weighted by number of contacts in each year), and the shaded area displays the 95% confidence intervals for the regression-predicted mean AUROC at each year.

Figure 3

Table 2.AUROC values across the three secondary analysesTable 2 long description.

Figure 4

Figure 3.Model performance across training approaches (different look behind windows). Points represent yearly AUROC values. Black, empty points represent the original model, trained on data from 2013 to 2017. Grey, solid points represent the annually updated model, trained on all preceding data (2013-evaluation year). Dark blue, solid points represent the one-year models, trained only on data from the previous year.

Supplementary material: File

Hæstrup et al. supplementary material

Hæstrup et al. supplementary material
Download Hæstrup et al. supplementary material(File)
File 3.5 MB