Sleep and Activity Prediction for Type 2 Diabetes Management Using Continuous Glucose Monitoring
Abstract
Continuous glucose monitors (CGMs) generate frequent glucose measurements, and numerous studies suggest that these devices may improve diabetes management.
These devices give people with diabetes visibility into how lifestyle factors, i.e., meals, physical activity, sleep, stress, and medication adherence, impact their glucose levels.
While earlier studies have shown that individual’s actions can influence their CGM data, it has not been clear whether CGM data can provide information about these actions.
This is the first study to show on a large cohort that CGM can provide information about sleep and physical activities (as aggregated from an activity tracker).
We first train a neural network model to determine the sequence of daily activities from CGM signals, and then extend the model to use additional data, such as individual demographics and medical claims history.
Using data from 6,981 participants in a Type 2 diabetes (T2D) management program, we show that a model combining an individual’s CGM, demographics, and claims data is highly predictive of sleep (AUROC 0.947, AUPRC 0.884), and moderately predictive of physical activity or certain indicators of physical activity (AUROCs/AUPRCs up to 0.817/0.401), as inferred by an activity tracker.
These results show that CGM may have wider utility in diabetes management than previously known.
Introduction
As of 2021, an estimated 536.6 million people worldwide had diabetes, and the number is expected to increase [1].
Among people with diabetes, as many as 90-95% have T2D [2], which appears to be caused by complex interactions between genetic, environmental, and lifestyle factors.
Daily actions, such as physical exercise, healthy eating, and sufficient sleep, are important factors in both preventing or delaying the onset of T2D as well as its management.
In this paper, we demonstrate the strong connection between daily activities and continuous glucose monitor (CGM) output by showing that the sequence of daily activities (sleep, walking, and elevated heart rate, as aggregated from an activity tracker) can be predicted directly from the CGM signal.
In addition, this can be used to analyze CGM and activity jointly to better understand their relationship and effects on health outcomes.
We then develop the model further to include demographic information as well as medical claims data, and we show that this additional information further improves the prediction results.
There have been several studies using CGM data in predictive models.
The most common use of this data is to predict if a person with type 1 diabetes will develop hypoglycemia [3]–[7] or hyperglycemia
In addition, CGM data has been used to determine additional insulin dose requirement at mealtimes [8].
A few studies have also used CGM data to determine people’s daily actions.
For example, CGM data has been used to determine a person’s adherence to their daily insulin injection [9], and other studies have detected eating activities [10][11].
To the best of our knowledge, there has been only one study using CGM data to predict physical activity [12].
However, that study was limited to 11 people with type 1 diabetes, and its generalizability is therefore limited.
Methods 2.1 Dataset and Preprocessing
Our dataset consisted of de-identified CGM and fitness tracker data collected from participants in a commercial diabetes care program.
Participants in this program had type 2 diabetes at the time of program enrollment.
All participants were given the same CGM device and fitness tracker. As some participants did not wear the devices consistently, we ensured data quality by only using data for calendar days where the participant had at least 22 hours of overlapping CGM and fitness tracker data.
In addition, we required them to have at least 1 hour of sleep during that day to ensure the fitness tracker was collecting data accurately.
We used data for all participants who had at least one day of data.
The resulting dataset consisted of 6,981 participants with an average of 65.1 days of data (median 28.0, standard deviation (SD) 85.6).
The mean age of participants was 54.3 years (SD 9.1), distribution of female/male was 51.3%/48.7%, and the mean body mass index (BMI) was 34.8 (SD 8.6).
Glucose level was measured using a CGM device which provided interstitial glucose measurements every 5 minutes, and physical activity and sleep were tracked using a fitness watch which reported average heart rate and step count once a minute, as well as the intervals when the participant was determined to be asleep based on their heart rate and accelerometer data.
Due to the difference in time sampling frequencies, the fitness tracker data was aggregated for each 5-minute time block to match the CGM.
Heart rates were categorized using the fitness tracker’s personalized heart rate zones into resting, fat burn, and cardio zones.
Walking activity was binarized using a threshold ofsteps per five minutes, which is slightly below a typical moderate-intensity walking cadence [13].
To reduce noise, we filtered out individual positive values from the labels, thereby requiring each activity to last for at least 10 minutes at a time.
After these preprocessing steps, the average prevalence of sleep activity was 30.7%, fat burn zone was 21.0%, cardio zone was 0.8%, and walking was 0.6%.
In addition, we accounted for participants’ medical history by means of their medical claims data.
This data included the information necessary for the reimbursement of medical services including
International Classification of Diseases (ICD10) diagnosis codes [14], and service dates.
In addition, we grouped similar ICD codes together by only considering the first 3 letters/numbers of each code.
On average, participants had 188.2 (SD 178.2) ICD codes in their claims data, with 40.7 (SD 23.8) unique codes.
2.2 Model
Our model was based on the U-Net architecture (see Figure 1) [15], which was originally designed for medical image segmentation.
Modified versions of the U-net architecture have been shown to be effective for a wide variety of tasks, such as volumetric medical image segmentation [16], [17], image denoising [18]–[21], audio source separation [22]–[24], speech enhancement [25], [26], and physiological signal imputation [27]–[30].
As our goal was to transform a sequence of glucose measurements to a sequence of daily activities, we modified the original model to use 1-dimensional convolutions instead of 2-dimensional convolutions.
The input matrix X was a sequence of 288 glucose measurements (24 hours * 12 measurements/hour) along with the rate of change computed by the CGM device.
These two values were combined as separate channels, i.e., X ∈ R 2 × 288 .
Prediction targets included four activities: sleeping, walking, elevated heart rate (Fat burn zone), and high heart rate (Cardio zone).
These values were measured at the same time intervals as the glucose values and treated as separate channels, therefore the target matrix Y ∈ R 4 × 288 .
The prediction was treated as a multi-label classification task, i.e., multiple target values were allowed to be positive simultaneously (e.g., walking and high heart rate). [Figure] S i g n
[Figure] A c t i v i t y P r e d i c t i o n s
Medical Claims, Demographics
[Figure]
Next, to incorporate claims data into the model, we converted the ICD codes that occured prior to the current time window into vectors x icd ∈ R 300 .
This conversion was done using pretrained ICD2Vec embeddings [31].
As our hypothesis was that some ICD codes might be more relevant for the prediction task than others, we wanted the model to be able to learn which ICD codes to use.
In addition, we wanted the model to be able to distinguish between acute and chronic diseases, as acute diseases might be relevant only for a few days or weeks while chronic ones could have effects across many years.
Including ICD codes into the model was implemented using a multi-head attention layer [32], as shown in Figure 2.
Time was first converted into larger time blocks to avoid overly sparse time values using conversion f ( t ) =
⌊ log ( t ) ⌋ , where t is the number of days between the current time window and the claim.
This time block was then converted into a vector t ∈ R 50 using step encoding shown in [32] and concatenated to the ICD vector x icd .
The sequence of combined ICD and time vectors was used as both the key k and value v for the attention layer while a constant vector was used as the query q .
[Figure] We evaluated including the combined ICD representations in three locations within the U-Net model: in the input layer, between encoder and decoder, as well as before the last convolutional layer.
These vectors were concatenated with the U-Net’s internal representation and passed through a convolution with size 1 and a rectified linear unit (ReLU) layer.
The resulting vector was then returned to the same location of the U-Net model where the original vector was.
Demographics (age, gender, height, weight, BMI) were standardized and combined with the internal representations the same way
. 2.3 Training
Participants were randomly divided 60%-20%-20% to training, validation, and test sets respectively, such that all data for one participant belonged to only one set.
Models were trained using AdamW [33] algorithm for 35 epochs, which was enough to reach convergence.
In each training epoch, a random day of data was chosen for each participant such that each participant appeared exactly once in each epoch, but different epochs might have used different time windows for participants.
In validation and test phases, one day of data was randomly chosen for each participant but this same day was used in every epoch and experiment.
This ensured that the results were consistent across different experiments and each participant had an equal impact on the results.
Experiments and Results
We evaluated our model with and without using demographics and ICD codes.
We also compared the predictive performance when changing the location where demographics and ICD codes were incorporated into the model.
Results of these ablation experiments are shown in Table 1.
As the results show, including ICD codes and demographics improved heart rate zone and walk predictions.
Overall, including demographics and ICD codes later in the model provided better results than including them early or between the encoder and decoder.
Sleep predictions were not affected by demographics or ICD codes.
Due to the significant class imbalance, we also evaluated area under precision-recall curve (AUPRC) scores, which show a similar pattern.
The highest AUPRC score for sleep prediction was 0.884 (2.9 times higher than prevalence), for fat burn zone prediction 0.401 (1.
times higher than prevalence), for cardio zone prediction 0.026 (3.0 times higher than prevalence), and for walk prediction 0.052 (8.7 times higher than prevalence).
added into the model
[Table] Figure 3 shows an example of predictions made for an individual participant.
The model was typically very confident in the sleep predictions except in the beginning and end of the sleep period.
The lower confidence in both ends can be partially explained by the noise in the ground truth data, as the sleep times were estimated by the fitness tracker based on movement and heart rate patterns.
Walking probabilities were skewed toward zero because of the rarity of the event, but despite the miscalibration the model did give higher probabilities when the participant was truly walking.
However, the probability sometimes increased slightly at other times also, possibly when the participant was doing other physical activities which had a similar impact on the glucose measurements as walking.
Similarly, heart rate predictions often had higher values when the heart rate was elevated, but the predictions were slightly noisy. [Figure] Trend [Figure]
Conclusion and Future Work
In this paper [Figure] we have shown for the first time using a large cohort of people with T2D that CGM data is highly predictive of sleep and moderately predictive of physical activity or certain indicators of physical activity, as inferred by an activity tracker.
To do so
[Figure]
we developed a neural network architecture for predicting daily activities using CGM, demographics [Figure] and claims data.
We first modified the U-Net architecture so that it can be used with 1-dimensional CGM signals [Figure] and then incorporated claims data using an attention layer which allowed the model to learn which claims were important for the task.
A limitation of our study is that the data used for ground truth is collected by an activity tracker as opposed to the gold standard measurements, such as polysomnography. Since activity tracker data may sometimes be an inaccurate predictor of sleep, our model may capture different information than sleep, and rather capture what is perceived by the activity tracker as sleep. Thus, comparing CGM to a gold standard sleep activity measurement remains an important direction for future work. Our work should also be taken into account in the context of T2D patients, and future work is needed to understand whether the results are generalizable to the entire population.
In our future work, we will investigate using alternative approaches to determine physical activity, such as combining heart rate and walking into a more informative label, as neither of these labels is a perfect measure of physical activity on its own.
For example, walking is not the only type of physical activity for many people and it might have a similar CGM pattern as other physical activities.
On the other hand, estimated heart rate zones can be imprecise for some of the participants.
We expect these changes to improve our physical activity predictions even further.
Our results open new possibilities for the utilization of CGM devices for diabetes management and allow us to gain a better understanding of CGM signal during activities.