Main content

Home

Menu

Loading wiki pages...

View
Wiki Version:
--- # Apple Health Data Extractor ## Installation This m script is self contained and can be run directly from MATLAB. ## Citation If you use `Apple Health Data Extractor` to extract step count or distance data for your publication, please cite it as indicated on the main OSF page (https://osf.io/cngrj/). ## Summary With the increased interest in activity monitoring, especially step counting, the ability to accurately measure and record steps is imperative. Commonly-available commercial products such as FitBit, Jawbone and ActiGraph can be worn to measure steps in addition to other activitys. These devices have been shown to be accurate in step-counting studies. However, they require that - subjects remember to wear the device at all times, - researchers purchase and maintain enough devices to run a large-scale study - subjects periodically upload their data in a long-term study A solution to these problems is to leverage a device that many subjects will already own and is already counting their steps: an iPhone. The Apple Health app is, by default, counting steps and distance traveled. Subjects own their own device, need not install any software and will likely remember to have it with them all the time. The difficult part in research studies is collecting and analyzing the data from the phone. Subjects can export the data to an xml file contained within a zip file that contains their movement data. The data is structured in time epochs of several minutes of step and distance data. This program extracts daily step and distance data from the exported zip file from the Apple Health app. In this version, a single zip file can be selected and analyzed. A loop can be written around the script to automate the extraction process in a batch. Apple Health writes the data in epochs of various lengths of time. Data in epochs that pass through midnight local time are counted all in the second day. The script produces two two-column matrix variables: `steplist` and `distlist`. `steplist` is a two-column vector with the date in YYYYMMDD format as the first column and the number of steps recorded that day as the second. `distlist` is a two-column vector with the date in YYYYMMDD format as the second column and the distance traveled (in miles) recorded that day as the second. For visualization and spot-checking, the script will also produce histograms of the two metrics. An example health data file from an iPhone 6 running iOS 11.3 is included in the archive as [example.zip][1] The output of this example file produces the two matrices in the workspace and the following histograms: ![histogram][2] ### Retreiving the raw data file from the iPhone 1. Open or search for the “Health” app from your home screen. ![step1][3] 2. Once the app opens, you will see the screen below. Tap on the red profile icon in the top right of the app. ![step2][4] 3. The screen below will then open. Scroll down to “Export Health Data” and click on the button. It will ask you if you are sure, click “Export”. Select how you want to get the data file. You can email it to using “Mail” or “Gmail” (whatever you use to check your email) or save it to a cloud service like Dropbox. The file will be in zip format and, by default, called “export.zip”. ![step3][5] Do note that the xml file within the zip file will contain *all* the Apple Health data from an individual so there is the potential for private health data other than step counts to be exported. However, the script will extract only the step data. *Updated Notes (3/28/2021):* *- I have tested the script with the output from an iPhone 8 and it is still working correctly* *- I am working updating the script to be a less crudely coded version that will run faster for larger files. I am attempting to use the Matlab XML parser, but it does not seem to work well with the data exported from Apple* *- This script can be easily modified to work on batch data but is currently set up to work on a single exported file* [1]: https://mfr.osf.io/render?url=https://osf.io/9pe45/?action=download&mode=render [2]: https://mfr.osf.io/export?url=https://osf.io/xa6yr/?action=download%26mode=render%26direct%26public_file=True&initialWidth=848&childId=mfrIframe&parentTitle=OSF+%7C+hist.png&parentUrl=https://osf.io/xa6yr/&format=2400x2400.jpeg [3]: https://mfr.osf.io/export?url=https://osf.io/fv9yb/?action=download%26mode=render%26direct%26public_file=True&initialWidth=848&childId=mfrIframe&parentTitle=OSF+%7C+step1.png&parentUrl=https://osf.io/fv9yb/&format=2400x2400.jpeg [4]: https://mfr.osf.io/export?url=https://osf.io/cg3ra/?action=download%26mode=render%26direct%26public_file=True&initialWidth=848&childId=mfrIframe&parentTitle=OSF+%7C+step2.png&parentUrl=https://osf.io/cg3ra/&format=2400x2400.jpeg [5]: https://mfr.osf.io/export?url=https://osf.io/x5v7w/?action=download%26mode=render%26direct%26public_file=True&initialWidth=848&childId=mfrIframe&parentTitle=OSF+%7C+step3.png&parentUrl=https://osf.io/x5v7w/&format=2400x2400.jpeg
OSF does not support the use of Internet Explorer. For optimal performance, please switch to another browser.
Accept
This website relies on cookies to help provide a better user experience. By clicking Accept or continuing to use the site, you agree. For more information, see our Privacy Policy and information on cookie use.
Accept
×

Start managing your projects on the OSF today.

Free and easy to use, the Open Science Framework supports the entire research lifecycle: planning, execution, reporting, archiving, and discovery.