Determine your Fitbit stride length using a GPS watch

I have been carrying my Fitbit One for a little over two years with me and it keeps tracking my daily steps. It also tracks my distance covered by multiplying those steps using the stride length which you can either provide explicitly or implicitly setting your heights. In the winter of 2012 I bought my first Garmin Forerunner 410 (replaced by a Garmin Forerunner 920XT) GPS watch to help me track my running (and other outdoor) activities. Since then I have worn it at every activity. Additionally before every running session I started a Fitbit activity to measure my step count. Over the last 18 month I have recorded 69 runs using both, the Fitbit and the watch. I put the data in a csv file so I could load it into R. Then I performed a linear regression to determine my stride length.

<img src="https://i0.wp.com/blog.tafkas.net/wp-content/uploads/FitbitStrideLength.png?resize=600%2C400" alt="Fitbit Stride Length Regression" class="alignnone size-full wp-image-215" srcset="https://i0.wp.com/blog.tafkas.net/wp-content/uploads/FitbitStrideLength.png?w=1200 1200w, https://i0.wp.com/blog.tafkas.net/wp-content/uploads/FitbitStrideLength.png?resize=300%2C200 300w, https://i0.wp.com/blog le viagra de l.tafkas.net/wp-content/uploads/FitbitStrideLength.png?resize=1024%2C683 1024w, https://i0.wp.com/blog.tafkas.net/wp-content/uploads/FitbitStrideLength.png?resize=624%2C416 624w” sizes=”(max-width: 600px) 100vw, 600px” data-recalc-dims=”1″ />

In an ideal world, where the GPS watch would perform with a 100% accuracy and the Fitbit would recognize every single step taken, the regression fit would meet the origin. Unfortunately neither of them is that accurate. Our model gives us an intercept of 398.46m with a slope of 1.00421m and an adjusted R^2 of 0.97505 Based on that I have covered a whole lap of a competitive running track before I made a single step. 😉

I have noticed that the placement of the Fitbit has a huge impact on the amount of steps recorded. Attached to the pocket of my running shorts it seems to miss certain steps. I get much better results attaching it directly at my waist. Overall I am quite satisfied with the accuracy provided by the Fitbit. If you do a lot of interval training or vary your stride from session to session your result will be far more off.

The code for the regression is on Github:
.gist table { margin-bottom: 0; }

Analyzing Sleep with Sleep Cycle App and R

I have been tracking my sleep for almost two years now using my Fitbit. I started with the Fitbit Ultra and then moved on the the Fitbit One after it came out. In October 2013 I found out about the Sleep Cycle (Link) app for the iPhone. For weeks, Sleep Cycle was listed as the best-selling health app in Germany, where currently (as of January 2014) it is in second place. The program promises, to wake you up in the morning without being tired. This is indeed possible if the alarm goes off in light sleep and not in deep sleep. It also allows you to set some kind of sleep music (white noise) to assist you to fall asleep. After reading all the positive reviews on the AppStore I decided to give it a try.

The app promises to wake you up in a time frame up to 30 minutes prior to the alarm you set if it detects your movement in the morning. Even more important to me than the actual smart alarm feature was the possibility to collect some data while sleeping. In the morning you are presented with a chart of your sleep pattern of last night:
Sleep Cycle Screenshot of last night

The app also allows to export the database as a comma separated file containing: time you went to bed, time you woke up, sleep quality in %, wake up mood and user defined sleep notes. This gives you the opportunity to do some more analysis. I decided to fire up R and create my own charts.

So far I have used the app to track 100 nights of sleep and decided to peak into the data. Let’s take a look how long I slept each night:
Sleep Duration over time

It looks like the longer I slept the higher the sleep quality is. A scatter plot of the data gives:
Sleep time vs. sleep quality

The chart takes also the sleep notes into consideration. You can see clearly that sleeping away from home results in lower sleep quality. The same applies for exercising (note: I tagged a sleep with exercising when I worked out late in the evening). On the contrary taking a melatonin (dosage 3mg) increased the sleep quality.

Averaging the sleep quality by month shows, that the January worse than the previous month. One explanation is a vacation I took, where I did not sleep so well at all.
Average sleep quality by month

The R code for the data wrangling and the charts:

Berlin Marathon 2014 Participants

After the 2013 Berlin Marathon sold out in less than four hours, the organizers decided to alter the registration process for 2014. First there was a pre-registration phase followed by a random selection from the pool of registrants to receive a spot. Those who were selected had to register until November 11th, 2013. Any spots that were not confirmed till the 11th would be offered to pre-registered candidates according to the order in which they were randomly selected.

At is a list of all registered participants of the event. Being curious how many runners are on the list I had two options: 1. going through the entire list and counting or 2. download the entire list and let the computer do the math. I chose the latter. If you checked the website already you saw that they present only parts of the list at a time a reload it asynchronously while you scroll down. I wrote a little python script that queries the data and saves the JSON response to a csv file.

Checking the file we see there are only 16,707 participants so far. Sure, there are spots sold to agencies or given to sponsors, but how many will be handed out in the second wave? Until they announce the results let’s look the data:

The distribution of the year of birth shows a bimodal pattern. Most runners are born in the late 60s or early 70s and then there is a second spike a around 1980.
Looking at the top 10 participating nations it is no surprise that Germany stands out by far. Followed by Great Britain and Denmark. The only non-European country in the top 10 are the United States of America:

The code for generating the images:

Update: The official registration period is over and 23,286 runners have signed up.

Five years of Weight Tracking

After I moved back from New Jersey in June 2008 I started to track my body weight more seriously. My routine usually consists of getting up and after finishing the morning bathroom I would step on my scale. That way I try to ensure that the condition for each weighing are as similar as possible. I recorded my weight on paper and eventually would put everything into a spreadsheet for further analysis.

In January 2011 I upgraded my bathroom scale to the Withings WiFi Body Scale. That way I could automate the process of tracking my weight by just stepping on it. No more writing on paper and eventually transferring everything into spreadsheets.

The people at Withings provide an API so external services could access your weight data. A nice way to get better charts is through Trendweight. Just link your Withings account to the web site and they will generate nice JavaScript charts of your weight/body fat/lean mass. Another great feature is the export functionality where you can export a comma separated version of your data including trend values for total weight as well as fat %, fat mass, and lean mass.

Using the exported data we can fire up R to look at the data:

The generated chart shows my weight loss in 2009, where I started cycling again after years of absence. From my lowest in the Fall of 2009 I gradually gained weight throughout 2010, 2011 until 2012, where I hit the 100 kg mark around Christmas time:

Body Weight 2008 - 2013

That was enough and I decided it was time to start working out again. So far, I am at a good downwards trend. I have to keep up that momentum. My next goal is to get between 80 kg and 85 kg and then maintain my weight. The color of the dots reflect my body fat percentage and there seems to be a strong correlation between body fat and my actual weight:

Body Weight vs. Body Fat Percentage

Doing a simple linear regression gives us an adjusted R-squared of 0.8419

Results of the St. Pat’s 10 Miler and 5K

Recently I ran the St. Pat’s 10 Miler in Atlantic City, Nj. It was my first official running event ever and I enjoyed it lot.

Shortly after the race the official results have been posted on the Internet. The data did not only include the number and times of the participants but also gender and age. Looking at the finisher time distribution it shows that most runners finished at around 90 minutes:

Finisher Time Distribution of the St. Pat's 10 Miler and 5K 2008

How does age affect the finishing time?

Finisher Time by Gender and Age of the St. Pat's 10 Miler and 5K 2008

The code to generate the images: