SAS

Analyzing my FitBit data by Emily Randall

I bought a FitBit Charge a few months ago and I love it. It tracks my heart rate, steps, distance traveled, floors climbed, calories burned, and various sleep metrics. The smart phone app gives me day-by-day graphs and stats, and the weekly progress report e-mail shows my weekly stats and overall averages. But I wanted to see what I could do with my data in Excel and SAS. (For discussion of similar analyses using R see http://www.r-bloggers.com/hey-fitbit-my-data-belong-to-me/).

I downloaded my FitBit data from the website under “account settings.” You can only export up to 31 days of data at a time, so if you want a longer range you’ll have to do multiple exports and merge them together. For this study, I stuck with my most recent month of data. Unfortunately you can’t export heart rate, which is disappointing. I’d like to graph my average heart rate for every minute of the day across a 1- or 3-month period, but no dice (for now).

I exported my data as a .csv file and cleaned it up in Excel. I didn’t think I’d have to clean it at all, but, of course, I did, due to my desire for more accurate sleep stats. FitBit does pretty well tracking sleep, but it’s not perfect. I noticed in the exported data that my sleep was underreported on certain days. This is because I woke up in the middle of the night, or early in the morning, and wasn’t able to go back to sleep for some time. I almost never used to do this. But lately I’ve been stressed. There were also a few days during the study period when my dog had “the runs” and woke me up in a panic to go outside at 2 am (fun fun).

The FitBit did record all my chunks of sleep (it records any sleep period lasting longer than 60 minutes), and it added them together to display a sleep total in the smart phone app. But FitBit only exported the larger sleep chunk in the export data file. So I had to go into the raw data file (in Excel) and add in the missing sleep data. (I did not include any daytime naps in my sleep stats, of which I had only three for the month in question). This brought my average nightly sleep up by 30 minutes to 7.5 hours per night – not quite the recommended 8 hours, but close enough.

Excel graph

Excel graph

Looking at my activity data, I averaged 6,596 steps per day (SD = 1,735.7; median=6,633). I’d definitely like to increase that number. I was also interested in my time spent in various activity level zones (based on heart rate), and I was aghast to see that I was sedentary 76% of my waking time this past month, as shown in the pie chart below, with very little time spent fairly or very active. In my defense, I’ve been working diligently to relocate to Chicago and to make myself a more competitive job candidate (learning SAS, writing amazing blog posts, etc.), which has required a lot of seated computer work. And although there are very nice walking trails here in NC, I commute everywhere by car. I can’t wait to move to Chicago in late December/early January, where I’ll be walking more often and relying more on public transportation. (By the way, my best daily performance since getting the FitBit was 20,000 steps, achieved while sightseeing in Savannah, GA).  

The activity level (according to heart rate zone) of my waking minutes, 10/22/15-11/21/15

The activity level (according to heart rate zone) of my waking minutes, 10/22/15-11/21/15

The FitBit sleep data is interesting, because the device tracks moments of wakefulness (getting up to go to the bathroom) and restlessness (tossing and turning) and adds them together for a total number of “awakenings.” It also calculates time spent in these moments as “awake (while in bed)” minutes, which are not included in “asleep” minutes. I averaged 16 awakenings (time awake or restless) per night. I’d like to get this number down, because I’ve noticed that when it’s lower, I wake up feeling more refreshed (presumably because I’m getting more slow wave sleep).

I was curious whether my daytime activity had any effect on my sleep. Perhaps more steps or active minutes during the day correlate with better sleep quality or quantity at night. I decided to examine these correlations in SAS. But then I realized that the FitBit calculates sleep at the beginning of the day and not at the end, for example starting at 11 pm on the previous night to 7 am that morning. So in order to pair the activity that occurred prior to sleep with the subsequent sleep, I had to calculate correlations between Day 1 activity and Day 2 sleep. I decided to take care of this in Excel by shifting my sleep data values up by 1 row and importing the modified data into SAS.

I looked at correlations and did not test for cause and effect. But if I want to explore the possibility of cause and effect I have to pair the variables this way to get the chronology right. If I paired Day 1 activity with Day 1 sleep, I’d get information about the possible effect of sleep quality and quantity on activity, rather than the other way around. So, after the modifications, the N for my sleep data was 30 rather than 31.

SAS output

SAS output

As shown in the SAS output, I didn’t find any significant (p < .05) correlations between the activity and sleep metrics EXCEPT for floors climbed (mean=12.2) and minutes awake while in bed (mean=27.9; r = 0.51, p = .004). This indicates that the more floors I climbed during the day, the more restless I was at night (or the more I had to get up and pee). This is very surprising, and I’m not sure what to make of it. I do have a touch of restless leg syndrome, but I would hope that floors climbed would calm this condition, not exacerbate it. There were no correlations between steps or distance and the sleep metrics (not shown). I’m going to keep an eye on this finding and explore it later with regression analysis.