Apple Health Data - Export, Analyze and Visualize with R

Datetime:2016-08-23 01:46:28          Topic: R Program           Share

Problem

The Apple Healthkit App dashboard is not useful beyond a daily snapshot of your steps, miles, and flights climbed.

How to export, analyze and visualize Apple Health Kit Steps data using R?

Actions

  • Export Apple HealthKit data from your iPhone.
  • Run R Script for analysis and visualizations.

Explanation (resolution)

How to Export Apple Health App Data

1) Launch the Apple Health App on your iPhone. The app icon is a heart.

2) Tap the Health Data icon in the bottom navigation. This will launch a list of all your Apple Heath data. In the List view, tap the “All” item which is the first item in the list.

3) Tap the send arrow icon in the top right. This will launch an alert that says “Exporting Health Data Preparing…” The export preparation took 4 minutes for my health data, so be patient.

4) Once the data is ready to send you’ll see an overlay where you can select how to send the health data export. I chose to send the file via email. The file name is export.zip.

How to use R to Analyze and Visualize your Apple Health Data

1) Make sure to install the packages used in the R script if you don’t already have them installed

> install.packages(c("dplyr","ggplot2","lubridate","XML"))

2) Run the R Script

3) Page through the 4 plots and see the R Console for data tables.

A boxplot showing my steps data by month and a bar graph showing my steps data by month are shown below.

My summary monthly steps statistics for 2015 are shown below. This data is output to the R Console.

month  |   mean    |  sd | median  | max |  min  |    25%  |   75%|
 ------ | --------- | ----|-------- | --- | ------|-------- | ---- | 
 chr |  dbl |  dbl |  dbl| dbl| dbl  |  dbl |  dbl|
 01 | 6928.45| 3499.36|  5924.0| 15173|  2286|  4007.00|  8581.0|
 02 |12000.07| 5727.69| 11977.5| 22675|  4097|  6853.25| 15649.5|
 03 |11271.26| 2579.44| 11662.0| 15199|  6269|  9723.50| 12667.0|
 04 |14846.27| 5825.21| 14257.0| 25357|  4445| 10925.75| 19322.0|
 05 |13119.45 |5139.61| 12405.0| 25031|  2971|  9829.50| 16222.0|
 06 |11457.70 |5083.92|  9904.5| 25643|  4301|  7424.25| 14225.0|
 07 |16419.06 |7369.98| 14750.0| 35582|  4546| 11243.50| 20911.5|
 08 |13968.32 |6855.27| 12189.0| 32019|  2897| 10469.00| 14561.0|
 09 |13096.07 |5272.44| 12753.0| 29838|  5737| 10155.50| 15987.0|
 10 |12150.16 |5163.45| 11227.0| 27174|  3906|  8952.00| 15359.5|
 11 |10442.80 |4405.78|  9476.5| 22683|  3814|  8233.75| 12669.5|
 12  |8331.03 |3933.16|  8098.0| 15450|  1556|  5192.00| 11396.5|

References

Full Post on ryanpraski.com

If you have any questions or hit me up on Twitter @ryanpraski





About List