Hostname: page-component-77f85d65b8-9nbrm Total loading time: 0 Render date: 2026-03-30T00:42:02.801Z Has data issue: false hasContentIssue false

Predicting the need for electroconvulsive therapy via machine learning trained on electronic health record data

Published online by Cambridge University Press:  13 February 2026

Lasse Hansen
Affiliation:
Department of Clinical Medicine, Aarhus University , Aarhus, Denmark Department of Affective Disorders, Aarhus University Hospital - Psychiatry , Aarhus, Denmark Center for Humanities Computing, Aarhus University, Aarhus, Denmark
Jakob Grøhn Damgaard
Affiliation:
Department of Clinical Medicine, Aarhus University , Aarhus, Denmark Department of Affective Disorders, Aarhus University Hospital - Psychiatry , Aarhus, Denmark Center for Humanities Computing, Aarhus University, Aarhus, Denmark
Robert M. Lundin
Affiliation:
Deakin University, Institute for Mental and Physical Health and Clinical Translation (IMPACT) , Geelong, Victoria, Australia Mildura Base Public Hospital, Mental Health Services, Alcohol and Other Drugs Integrated Treatment Team, Mildura, Victoria, Australia Barwon Health, Drugs and Alcohol Services, Mental Health Drugs and Alcohol Services, Geelong, Victoria, Australia
Andreas Aalkjær Danielsen
Affiliation:
Department of Clinical Medicine, Aarhus University , Aarhus, Denmark Department of Affective Disorders, Aarhus University Hospital - Psychiatry , Aarhus, Denmark Psychosis Research Unit, Aarhus University Hospital - Psychiatry, Aarhus, Denmark
Søren Dinesen Østergaard*
Affiliation:
Department of Clinical Medicine, Aarhus University , Aarhus, Denmark Department of Affective Disorders, Aarhus University Hospital - Psychiatry , Aarhus, Denmark Deakin University, Institute for Mental and Physical Health and Clinical Translation (IMPACT) , Geelong, Victoria, Australia
*
Corresponding author: Søren Dinesen Østergaard; Email: soeoes@rm.dk
Rights & Permissions [Opens in a new window]

Abstract

Objectives:

Electroconvulsive therapy (ECT) is an effective treatment of severe manifestations of mental illness. Since delay in initiation of ECT can have detrimental effects, prediction of the need for ECT could improve outcomes via more timely treatment initiation. Therefore, this study aimed to predict the need for ECT following admission to a psychiatric hospital.

Methods:

This study was based on electronic health record (EHR) data from routine clinical practice. Adult patients admitted to a hospital within the Psychiatric Services of the Central Denmark Region between January 2013 and November 2021 were included in the study. The outcome was initiation of ECT >7 days (to not include patients admitted for planned ECT) and ≤67 days after admission. The data was randomly split into an 85% training set and a 15% test set. On the 7th day of the inpatient stay, machine learning models (extreme gradient boosting (XGBoost)) were trained to predict initiation of ECT and subsequently tested on the test set.

Results:

The cohort consisted of 41,610 patients with 164,961 admissions. In the held out test set, the trained model predicted ECT initiation with an area under the receiver operating characteristic curve of 0.94, 47% sensitivity, 98% specificity, positive predictive value (PPV) of 24% and negative predictive value (NPV) of 99%. The top predictors were the highest suicide assessment score and mean Brøset violence checklist score in the preceding three months.

Conclusions:

EHR data from routine clinical practice may be used to predict need for ECT. This may lead to more timely treatment initiation.

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. Overview of the process for extraction and transformation of dataset and the training and testing of models. (A) data were extracted from the EHRs. (B) data were split into a training and a test set. (C) prediction times occurring after September 22, 2021 and before January 1, 2015 were removed due to lack of follow-up/lookbehind in addition to prediction times preceded by diagnoses of psychotic or personality disorders. (D) linked predictors such as medication class and diagnostic groups were grouped together. (E) predictors for each prediction time were extracted by aggregating the variables within the lookbehind with an aggregation function. As a result, each row in the dataset represents a specific prediction time with a column for each predictor. (F) clinical notes were turned into vectors using TF-IDF models. (G) models were trained and optimised on the training set using 5-fold cross-validation. Hyperparameters were tuned to optimise AUROC. H) The best candidate models were evaluated on the test set. Modified version of the figure from Bernstorff et al., 2025a.

Figure 1

Table 1. Descriptive statistics for prediction times (A) and individual patients (B) that were eligible for prediction

Figure 2

Figure 2. Test set results for the model based only on structured predictors. A: receiver operating characteristics curve for each predictor set. The model using the predictor set with only structured data was used for figures B–D with a PPR of 2%. B: confusion matrix. PPV: positive predictive value. NPV: negative predictive value. C: time (days) from the first positive prediction to the patient initiating ECT at a 2% PPR. The dashed line represents the median time. The plot is truncated at 100 days from first positive prediction to event as few events are predicted later than this. D: sensitivity by days from prediction time to event, stratified by desired PPR. E: temporal stability of the model performance.

Figure 3

Table 2. Top 10 most important predictors (and aggregation method) for the model based only on structured predictors

Figure 4

Figure 3. Robustness across stratifications of the model based only on structured predictors model performance stratified by sex (A), age in years (results for 18-20 years not reported due to too few observations) (B), time since first visit to the psychiatric services in the Central Denmark Region (C), and month of year (D). The black line is the area under the receiver operating characteristics curve (AUROC). Grey bars represent the proportion of prediction times that are present in each group. Error bars are 95%-CIs from 100-fold bootstrap.

Supplementary material: File

Hansen et al. supplementary material

Hansen et al. supplementary material
Download Hansen et al. supplementary material(File)
File 2 MB