This analysis was for a request from reddit. See here.
The request concerned health data collected from an apple watch and iphone. There are different types of data to play with:
We can ask a lot of questions with this data, but to start off I’ll look at the connection between sleep patterns and heart rate, as per request. So lets get started.
We have a lot of measurements per hour, day, etc. Therefore, to get an overall impression I will lower the resolution by aggregating the data.
Make a summary plot of the heart rate
As expected we see a drop in heart rate over night and not a lot of variation depending on the month of the year. There seems to be a slightly higher heart rate in the winter months (november to february), but whether that means anything is unclear so far. A healthy heart rate at rest is between 50/60-100 bpm according to the American Heart Foundation. More info wikipedia.
There also doesn’t seem to be a big difference between the weekdays. Again we see the lowest heart rate at night between midnight and 7 am.
Now lets have a look at the sleep data before combining the two.
## # A tibble: 6 x 15
## `In bed at` Until Duration Asleep `Time awake in ~
## <dttm> <dttm> <time> <time> <time>
## 1 2016-12-21 00:30:00 2016-12-21 07:23:00 06:53 05:15 01:38
## 2 2016-12-23 02:45:00 2016-12-23 07:30:00 04:45 04:45 00:00
## 3 2016-12-24 02:45:00 2016-12-24 08:00:00 05:15 04:45 00:30
## 4 2016-12-25 03:45:00 2016-12-25 07:15:00 03:30 03:30 00:00
## 5 2016-12-26 00:25:00 2016-12-26 09:47:00 09:22 07:57 01:25
## 6 2016-12-27 03:22:00 2016-12-27 09:14:00 05:52 05:51 00:01
## # ... with 10 more variables: `Fell asleep in` <chr>, `Quality
## # sleep` <chr>, `Deep sleep` <chr>, Heartrate <dbl>, day <date>,
## # month <fct>, weekday <fct>, from <int>, to <int>, advised <dbl>
Let’s have a look at the average sleep duration per weekday in each month. The average eight hours of sleep advised are also indicated. The sleep data uses the asleep values as indicators for the night sleep.
We see that there is quite a variation on sleep times over all. All the plots in one way or another show that on average, the 8 hours of advised sleep are not reached. Now how does this connect to the heart rate data we looked at previously.
To get an idea about the heart rate during sleep we can check the heart rate times on the specific day in the hours in bed. Some sleep entries have a heart rate number (probably average at night) , but not all. To get more information, we’ll look at the original heart rate measurements and extract them. This give a few more values and also a range (sd) over night.
Let’s plot this.
There doesn’t seem to be a correlation at all between average heart rate and duration of sleep. There is a bit of a trend to higher heart rate during shorter nights, but it’s not yet clear. There is also no trend visible for the year. In the warm months (june and July) night sleep seemed to be a bit shorter, but we don’t have many measurements.
Let’s have a look at another measurement, calories burned.
## # A tibble: 6 x 6
## date kcal weekday month yr yrM
## <dttm> <dbl> <fct> <fct> <dbl> <chr>
## 1 2016-04-01 00:00:00 51.0 Fri Apr 2016 16-04
## 2 2016-04-02 00:00:00 129 Sat Apr 2016 16-04
## 3 2016-04-03 00:00:00 185 Sun Apr 2016 16-04
## 4 2016-04-04 00:00:00 125 Mon Apr 2016 16-04
## 5 2016-04-05 00:00:00 88.5 Tue Apr 2016 16-04
## 6 2016-04-06 00:00:00 144 Wed Apr 2016 16-04
This overview of the burned kcals during activity shows a spike around end 2016 - beginning 2017, though on average the active calories burned are between 100 and 200 kcals per day. The errorbar indicates the confidence interval, i.e. how reliable is the calculated average.
The spike is interesting. We could check if the heart rate is different around that time and if we see more steps. The step count was done with the watch and can be seen as a measure of exercise/ movement.
Since we only have the total active kcals burned per day, we should also look at the total step count per day. For the heart rate that’s a bit less straight forward. Most likely the active energy burned is connected to activities during the day and sport measurements. So heartrate during sleep could be neglected for now.
This looks a lot like what we saw for active calories burned. So the total amount of steps we take might be a good estimate for the amount of calories that were burned that day.
This is interesting. While there is a correlation between amount of steps and kcals burned, there seems to be a split at the higher step counts. Some instances show lower calories burned despite a higher step count. There seems to be another factor that affects the calories.
Let’s check, if the average heart rate during the day can give some indication.
There is also a relationship between average heart rate and calories burned. If we go back to the previous plot, but color the dots by heart rate, we can see if the assumption could make sense.
##
## Call:
## lm(formula = kcal ~ heartrate * steps, data = stepsKcal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -360.92 -51.38 -11.69 38.73 373.17
##
## Coefficients:
## Estimate Standardized Std. Error t value Pr(>|t|)
## (Intercept) -3.181e+02 0.000e+00 1.022e+02 -3.113 0.001952 **
## heartrate 4.627e+00 1.765e-01 1.118e+00 4.139 4.07e-05 ***
## steps -2.744e-02 -5.196e-01 1.733e-02 -1.583 0.114015
## heartrate:steps 6.503e-04 1.242e+00 1.814e-04 3.585 0.000368 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 84.73 on 523 degrees of freedom
## Multiple R-squared: 0.7239, Adjusted R-squared: 0.7223
## F-statistic: 457.1 on 3 and 523 DF, p-value: < 2.2e-16
This shows that the burned calories are indeed dependent on the average heart rate on top of the activity that was performed. It’s still not fully explained, though this gives a good indication how the calories, total activity and heart rate are connected.
Lastly, can we see better sleep after higher activity?
We can’t see any relationship between the amount of sleep and the activity levels as indicated by burned calories.