Friday, July 15, 2011

Ruby, oAuth and BodyMedia

I am very pleased to bring to you today the very first Human System Debugging guest post!  

Miriam works with me at the CREATE Lab at CMU and is, among many other things, the guru I call on when I'm in over my head trying to do things in Ruby on Rails.  I am honored that she joined me in figuring out how to take this next big step in developing our ability to access data from self-quantification devices, and am very pleased that she chose to share this experience with the Human System Debugging community.

  -- Anne, Human System Debugger

Recently, Anne and I spent some time figuring out how to connect to BodyMedia's FIT Data API using the ruby-oauth gem. We ran into some confusing snafu's, so I figured I'd blog about it for posterity, in case someone out there runs into similar problems.

Here is BodyMedia's super-duper straightforward and uncomplicated explanatory diagram:

I'm going to walk you through how we navigated this graph.

Step 1

First you must sign up with BodyMedia and apply for a Consumer Key and Consumer Secret. Information on doing that can be found here.

Step 2

You can now use your key/secret pair to generate a Request Token:

Step 3

Now we must get the user's authorization. Using our API_KEY and API_SECRET, we can construct the following URL:

Following this link, we get to a page that looks like this:

Anne signed in with her BodyMedia credentials and we got redirected to localhost.

Step 4

Now we can exchange our Request Token for an Access Token, which we will use to make requests (yeah, that confused me)

Step 5

Finally, we can use the Access Token to make requests, like so:

Two important things to note here:
  1. You have to pass a full URI to make your request and that the domain is different than the one you used to get your tokens
  2. You must pass your API_Key in the GET, even though it is also being sent by the oauth gem in the header

These two points had us stuck for a while!

So there you have it. Hope someone out there can avoid a headache..

Saturday, June 4, 2011

The Fallacy of Labels

Its been a long time since I have tried to post here, but I have been re-energized to do so after participating in the amazing Quantified Self Conference last weekend.  I've had all sorts of ideas I want to share, but didn't have a clear enough picture of who would care to have the confidence to put them down in blog posts.  Now that I have a concrete community in mind that I think would get it and care (those clustering around the idea of Quantified Self), here goes:

I think as a culture our thinking is badly tainted by what I call the "fallacy of labels."  This is the oversimplification that all things to which a given label has been applied are thereafter indistinguishable from one another and alike in all relevant ways.  This is particularly pernicious with nutrition studies, where the label "high fat" gets applied to a test diet of processed carbohydrates + varying amounts of margarine or crisco, yet hype around the study assumes that it somehow proves it's unhealthy to eat any type of fat.   In fact, "high fat" may not have been the most significant contributor to the damage seen in the test rats/monkeys/humans.  They might have gotten different results with different diet composition, such as whole foods with grass fed butter, despite that also falling under the same "high fat" label.  Peter Dobromylskyj's Hyperlipid and Stephen Guyenet's Whole Health Source blogs are particularly eloquent on this point.  

Just this morning I saw a twitter post from @bulletproofexec who I met at the QS conference making this pointing about another such study here:
Eating a high-fat diet during pregnancy increases the chance of stillbirth, according to new research at Oregon Health & Science University. The new data show eating a typical American diet, which is high in fat, decreases blood flow from the mother to the placenta, the temporary organ that nourishes the unborn fetus. Prior to this study, exactly how a fatty diet contributes to stillbirth was unclear. The findings are published in the June edition of the journal Endocrinology.

The study was conducted at the OHSU Oregon National Primate Research Center. Because the placental structure of the Japanese macaque is very similar to that in humans, cause and effect can be better established. The researchers hope their work will inform expectant moms and their physicians about the inherent dangers of a high-calorie, high-fat diet.

Nowhere in this article does it say what exactly what was in the diets they fed the monkeys.  Did the test diet differ from the control diet in trans-fats?  Fructose?  Wheat?  Linoleic Acid?  Any of those could be highly relevant, yet researchers may not even think about or control for such other possibilities if infected by the meme that the "high fat" label tells you everything that matters.  It may or may not even be possible to find such details in the paper itself (I haven't tried on this particular one, but Peter and Stephen are good at digging into that sort of thing).  

Another example is debates about whether the "SCD diet" works for "Crohns".  There are a variety of ways of eating and diverse people's biochemical situations to which those labels get applied but which are not equivalent.  As I understand it, "Crohns" relates to a person's immune/inflammatory system getting pissed off and taking it out on the lining of their guts.  There are a diversity of potential mechanisms which may be driving this process and really no good way to know which pathways might be significant players for a given individual.  There are also a diversity of ways in which the dietary changes a given individual makes when pursuing the strategy of "SCD diet" might play out beyond the ideological reasoning that went into designing it.  

For particular individuals in which there's a good match between the specific dietary inputs they choose after making the decision to follow the "SCD diet" and what their body needs at that point in time to be able to calm down on the inflammation/autoimmune processes and heal (call them "group A"), it can work incredibly well.  For others, despite similar labeling, maybe not (call them "group B").  If you're just randomly selecting individuals labeled "Crohns", you'll most likely you'll get a preponderance of group B in your sample and claim it doesn't work.  However, that doesn't mean that it wouldn't help people with the potential to be in group A.  There's no way to know which group a given person may fall in at a given point in time short of actually doing the experiment.

Secondly there's the question of sophistication and discipline of adherence.  Giving someone a half-assed summary of what the diet means isn't likely to work even if they have the potential to be in group A.  Most likely they will just make the minimal changes to sort of mostly adhere to their initial understanding of that summary for a limited time (this would particularly tend to be the case in study situations).  You've got to be pretty desperate and dedicated to do it strictly and constantly go back and question your current implementation.  It's also key to reach the point of discerning a difference before you lose your initial interest/zeal.  The feedback loop doesn't work until and unless you can experience the carrot of decreased suffering when you hit on a practice of eating that works for you, and the stick of continuing pain.  At that point your lower level limbic and motivational systems can kick in, and they're better at that sort of thing than your cortex.  That doesn't happen for everyone, and you particularly can't make it happen just by assigning someone randomly to a test group.  The people who do get to that point and see improvements often fall into another fallacy of labeling trap: assuming that everyone with their same diagnosis label would experience the same results if pointed at the same diet label, which is likely also not true.

Thirdly, the explicit claim about the mechanism of action for a given diet may not actually be what's responsible for helping any particular individual that it does help.  The SCD claims that it works by restricting the types carbohydrate which favor pathological strains of gut bacteria and increasing ingestion of certain specific strains of probiotic bacteria that can then outcompete the bad guys.  That may be true, though it's hard to tell for sure (I really really wish we had access to ways to quantify gut flora makeup over time!).  However, other parameters also tend to get altered when changing from typical standard American diet to strictly adhering to their protocol, and these may in fact be more significant to particular portions of group A folk.  Candidate factors include reduced consumption of processed/restaurant foods, more cooking at home from scratch, reduced antinutrients (gluten, lectins, phytates, etc. -- particularly relevant for undiagnosed celiac/wheat sensitive individuals), reduced chemical additives of various sorts, reduced nightshade (no potatoes), potentially improved omega 3/6 ratio and fat soluble vitamins (A/D/K2), increased freshness of ingredients (ayurveda would call it "prana") etc. etc.  It's hard to know to what extent any of those may/or may not be relevant to particular individuals, but they all potentially help.  Other diet philosophies, such as Paleo, Michael Pollan's Food Rules, Ayurvedic vata balancing diet, macrobiotics, Weston Price Foundation, etc. also share similar features and seem to help in similar ways for certain folks.

So, my take on it is that we really need to break free of labels and give people tools (both technological and cultural) to help track the specific details of their intake and wellness over time in enough detail that they can go back and reanalyze the observations through various lenses, try out various ideas, and iterate towards something that works for them.  One of the simplest, most powerful techniques to get started with this is photographing everything before you ingest it with a camera that does timestamping.  Various other ideas and efforts presented at the Quantified Self Conference, such as Quantified Doctor and BodyTrack are all about trying to foster social changes and tool development to make that dream a reality.  

It's like buying pants, if you have a 34 inch waist you wouldn't assume that all pants with "34 waist" written on them would be right for you.  Instead you try them on, look in the mirror, walk around the store in them, ask your friend if they make your butt look fat, and so on.  We understand that acquiring appropriate pants is a high-dimensional problem which is not fully captured by the waist size.  We know that other parameters -- leg length, waist/hip ratio, sense of style, context we want to wear them in, etc. --all factor in.  To get it right, we close the feedback loop of how they look, feel, and perform (to steal a phrase from Robb Wolf) on our particular body at this particular moment.  Why in the world do we act as if the impact of food (and other inputs) on wellness were of lower dimensionality and amenable to open-loop label based cookie cutter solutions?