For the last last year I have tracked my sleep with the app Sleep as Android. The app tracks my sleep duration, movement, snoring, and deep sleep among other things. It also has an option to export the data as a .csv file. As a Data Scientist I was curious to learn more about my sleep patterns by analyzing this data.
I have to main goals I want to accomplish here:
- What is my optimal sleep duration?
- What is my optimal fall-asleep hour?
The first challenge I faced is the fact that data is incredibly dirty. I’m sure the developers of Sleep as Android had a reason for saving the data in this way but it’s very inconvenient for those hoping to use it.
Once I got the data cleaned up my next step was to combine the duration variables by date. Sleep as Android tracks the duration as bedtime to first alarm, and starts a new entry each time I hit snooze. I hit snooze a lot. This led to a lot of entries for some days.
By adding the sum of all sleep times for each day I calculated the total amount of sleep I got that day. Once I had that done I was able to produce this graph which shows my sleep duration for each day:
Let me give some quick insight into the patterns you see here. Before day 200 I had a job with very sporadic hours so my sleep patterns varied wildly from night to night. Also that back to back spike of 18 hours followed shortly by 13 hours involved me being very, very sick. In fact, the two days between those entries I didn’t even log all of my sleep due to the illness. Let’s just say over those four days I was asleep much more than I was awake.
After moving halfway across the country around day 200, I made an effort to fix my bad sleep habits. While I am definitely not doing perfect, as you can see in the graph my average sleep duration has gone up noticeably. Let’s take a look at my average sleep duration per week over time:
One thing to note: The two extremely low weeks were my vacations where I forgot to track sleep…whoops. So it did rise by about an hour following the move, but my progress didn’t last long. I corrected some of the extreme variance in my sleep habits though, right? I’ll let the data paint the picture. Let’s check the variance in the duration variable on days pre-200 and post-200.
Now that I’ve looked through some of the characteristics of the data, I want to know the answer to my first goal. What is my optimal sleep duration? I’ll compare the length of my sleep duration to the percentage of deep sleep I got.
According to the Institute of Medicine (US) Committee on Sleep Medicine and Research¹ the recommended amount of deep sleep is between 13–23%. Let’s take the mean sleep duration for each deep sleep percentage between 13–23%:
From this data I can determine my optimal sleep duration: just above 6.3 hours or ~6:20. Either I’m accidentally doing something right, or maybe it’s my natural sleeping pattern, but this directly coincides with my average sleep duration of 6.32 hours.
As the graph below helps illustrate, the sleep entries that fall within half an hour on either direction of the mean duration make up 28% of the total entries. While that is a significant portion of the total entries, it should not skew the results due to a low sample size.
Finally I want to find out my optimal fall-asleep hour. I’ll follow the same method I just used and plot the fall-asleep hour against the deep sleep percentage. First though, I want to plot my mean Fall Asleep Hour (FAH) for each week:
As you can tell, I’m a night owl. I prefer staying up late into the night reading or watching YouTube over going to bed early. My next step will be to find out what FAH will get me the optimal amount of deep sleep. Here I will plot my fall asleep hours that produce deep sleep percentages in the optimal range.
From this data the optimal fall asleep hour for me is approximately 1:45am. Contrary to the duration calculation, I do believe that the data spread is skewing the results. I simply haven’t gone to sleep between 11pm and 1am regularly enough to get a better data spread. One experiment I would like to carry into the future is going to bed earlier so that I can have a better spread of samples for my fall-asleep hour findings.
In conclusion, I was able to use my sleep data to find my optimal sleep duration as well as my optimal fall-asleep hour. This research has caused me to think a lot more about my sleep patterns and habits and will help me get better, healthier sleep.
- Institute of Medicine (US) Committee on Sleep Medicine and Research; Colten HR, Altevogt BM, editors. Sleep Disorders and Sleep Deprivation: An Unmet Public Health Problem. Washington (DC): National Academies Press (US); 2006. 2, Sleep Physiology. Available from: https://www.ncbi.nlm.nih.gov/books/NBK19956/