How easy is it to predict sleep from only heart rate data?

Kimberly McManus
3 min readMar 29, 2020

Heart beats are fascinating.

We all have beating hearts. They are not only essential, but also uniquely identifying. Heart beats could one day be used as passwords or in place of facial recognition. They are one of the most fundamental vital signs of most large organisms on Earth. Output is dependent on a vast array of input signals — fitness, BMI, time of day, mental health, disease, etc.

It is crazy how much can be learned about a human by just one number. Did your teenager really fall asleep at 10pm? Did your sister really go running for an hour? Did your friend really only have 2 drinks last night? All of this can be inferred from a stream of heart rate measurements.

In this post, I’m combining heart rate measurements with another essential vital sign, sleep, and asking “How easy is it to predict sleep from only heart rate data?”

Why infer sleep from heart rate data? Sleep is incredibly important for human survival and happiness. Understanding how we sleep is the first step toward improving sleep. I’m wondering if it is possible to correlate sleep with other signals to encourage behavior change: Do you tend to have poor sleep on days you wake up early? When you don’t exercise the previous day? When you slept too much the night before?

TL;DR Inferring sleep from heart rate is easy.

Analysis details

Disclaimer: I am not a sleep or heart expert. This is just for fun.

True positives: I assume Fitbit’s inference is the gold standard, and convert the sleep stages to binary sleep & awake states. Anecdotally, Fitbit’s inferred states look accurate to me.

Data: My personal Fitbit heart rate data from 2020-Jan-12 to 2020-Mar-08. Data was thinned to one hr reading per minute.

Model: Two state (awake & asleep) hidden Markov model with Gaussian emissions. The parameters were inferred via the Baum Welch algorithm, and the forward-backward algorithm was used to infer the state at each minute.

Results: My naive model has a 0.89 concordance with Fitbit’s readings. Fitbit’s model is more complicated of course. They infer three types of sleep (light, deep, and REM), and also use movement as a signal. Fitbit also says they use a heuristic where you must be not moving for ~1 hour before inferring sleep, which gates against accidentally assuming you fell asleep for 5 minutes.

Figure 1: Heart rate and inferred sleep/wake state during January 13, 2020. (Top) Blue: My heart rate, Green: Fitbit’s inferred sleep stages. (Bottom) Blue: My heart rate, Red: My inferred sleep stages via a two state HMM

Final Thoughts

Personalization: My sleep inference model was optimized for my heart rate data. You would probably need a separate model per person, since heart rate and heart rate variability is different for each person.

Models: Is an HMM an appropriate model? Given the simplicity of a heart rate time series, HMMs seem like reasonable models. In the future, I’m interested in exploring more complicated models, and finally delving into some deep learning. It isn’t clear that would help here though.

Population level inference: Fitbit’s business model is based on providing individual level insights; however, wearables can also provide invaluable, realtime population level data on health and activity level.

Code & Jupyter notebooks: https://github.com/kimberlymcm/digitalhealth_project

--

--