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?  

Wednesday, June 3, 2009

Beta blockers: good idea or trap?

For a few months in 2007 I worked very hard at bugging doctors to try to figure out what was going wrong. (A year later I tracked it to a problem with cholinesterase inhibitors, but I didn't know that then.) A neurologist I saw once (and only once) as part of this quest expressed that I was just being overly sensitive and suggested I try beta blockers.

When beta 1 receptors bind to epinephrine they make your heart beat harder and faster. This is what gives you that fluttery messed up feeling when you have to do something like get up and perform in front of a group of people. Beta blockers suppress, or at least attenuate, this effect. They're sometimes used (or abused, depending on your viewpoint) to control physiological symptoms of performance anxiety. This was the basis of his suggestion. Sounds like a good thing, right?

The problem is this: most neurons will adjust their gains and receptor densities to maintain a fairly constant level of input. This is a big part what goes on with things like drug tolerance. In this case, it means that while you're on beta blockers your beta receptors proliferate and ramp their gains to max trying desperately to get the signal level they expect. While the beta blocker levels are stable you feel fine, but when it goes down -- oh man...

I really wish they'd warned me about this when they suggested and/or prescribed the &%^$ things, but I learned this the hard way. I had to stop taking them for a while to do a test. The day after I stopped I felt jumpy, my heart rate was running ~130 just sitting still and ~160-180 if I tried to do anything, and I got really bad cardiac arrhythmia (multiple times per minute -- scary). This was not fun and so, so much worse than what had been happening to me before taking the beta blockers.

I tried to go without them after that, figuring these symptoms would fade and that I'd already paid the worst of the withdrawal symptoms waiting for the stupid test to happen. Months later, when these problems were still much worse than they'd been before and weren't getting any better I gave in and started taking them again. (BTW, the lovely interlude with the generic Ethex Toprol XL described in the last post happened at this point in the story.)

A few months after changing my diet to avoid cholinesterase inhibitors, I started having a different problem: the beta blockers were now too strong. The built up SGA had been keeping the epinephrine level artificially high. Once the level dropped enough, the beta blockers were making my blood pressure go so low I couldn't function.

I was already taking the minimum available dosage. Cutting them in half worked for a few weeks, but they couldn't be subdivided further without destroying the time release. (As described in the last post smooth time release is critical for this stuff.) The only option was go cold turkey and be miserably jumpy, heart racy, and arrhythmic until the beta receptors desensitized back to normal.

I couldn't find any useful info anywhere to help me understand how long that might take. The last experience stopping beta blockers was miserable and ultimately failed, but how much of that was caused by the hypersensitive beta receptors and how much by the high SGA levels?

It wasn't nearly as bad as I'd feared, implying that the SGA levels had been the dominant part of the problem last time. There was a little arryhthmia, but mild, and only for a few days. The jumpiness and heart racing faded slowly over a couple months.

Later, when I got the results back from 23andme, I discovered that I have mutant beta 1 receptors: GG on rs1801252. Only ~4% of the population have this genotype, and it's been associated with "low extroversion." I take that to mean that we suffer the fluttery feeling so bad that we mostly avoid having to be on stage in the first place. This may help explain why the beta blockers were so effective at such low doses.

So, the question is this: should I recommend the use of beta blockers to help counteract the effects of cholinesterase inhibitor sensitivity (CIS) during the detoxification process or not? It helped in the short term, but in the end felt like a trap. Also, I don't know how the mutant receptors play into this. How would this play out in people with CIS but with normal receptors? Sigh, need bigger sample size.

The more troubling thing is that ~millions of people are taking beta blockers for high blood pressure. It seems like everyone I talk to over the age of 60 is either taking them, or their spouses or friends are. Nobody warned them about receptor sensitization and withdrawal effects either. Yikes...

Generic drugs: I'm on to your tricks now

I've been thinking about writing this post for a long time, but was finally kicked into gear by LookyDaddy's recent post referring to the dangers of generic epilepsy drugs.

My first experience with this was about a year ago with Toprol XL. I'd been taking it for months with no problems. Then one refill the pills were clearly different. It turned out that Walgreens was now sourcing generic Toprol XL from a different manufacturer: Ethex instead of Sandoz. They didn't think this was worth mentioning. I only noticed because the size and shape changed.

Right away I started having trouble. During the course of the day I'd go through periods of incredibly low energy and blood pressure -- like, unable to move low -- and periods of jumpy heart racing.

Randy hypothesized that the release rate of the Ethex generic wasn't flat enough. During the low periods it was releasing the drug too fast: beta receptors too blocked, heart going too slow and weak. During the jumpy periods it was releasing too slow: receptors not blocked enough, heart going too fast and hard.

These problems went away within a few hours of getting the name brand. After that, we poked around on the web and found that lots of other people had the same problem with the Ethex generic.

More recently, I started experimenting with bupropion to try to deal with dopamine deficiency. Again they gave me a generic: Teva Budeprion XL. Again there was instability: high dopamine in the morning, sudden crash in the afternoon, ok in the evening after a nap. I thought at first that this was just startup edge effect, but it went on for weeks.

Again, these problems went away right after changing to the name brand. Again, lots of others had similar problems. We learned that two other people we know and care about were also getting screwed up by Teva Budeprion XL and got better when they stopped taking it. Ok, we thought, better put out a warning...

Now, I know this is all anecdotal and there's plenty of people on the net to complain about anything. However, consider this: the time release mechanisms in drugs are considered *inactive ingredients* and are therefore not regulated. They differ between brand name and generic, and even between generics from different manufacturers. The ones that are sophistocated enough to give reasonably flat release profiles are pricey. Generics have low profit margins. Seems like a good target for cost cutting.

Another problem with inactive ingredient substitutions is that they can be a problem for people with sensitivities. The one I have to watch out is potato starch (discussion of use in generics here). Pharmacists don't seem to have access to inactive ingredient information but will supply the phone number of the manufacturer.

I'm sure not all generics are bad, but after getting messed up by the last two in a row I no longer swallow the claim that they're "equivalent." If you're taking a generic, it may perhaps be a good idea to do an experiment:
  • Get one refill, or a partial refill, of the name brand
  • Watch yourself carefully for a few days while still on the generic, then compare how you do with the name brand
  • If you can't notice a difference, go back to the generic with restored peace of mind
  • If you notice a difference for the better, think about how much that quality of life improvement is worth to you compared to the cost differential
I know that for me it's well worth the $15 extra per month to be free of what the Ethex and Teva generics were doing to me.

Monday, June 1, 2009

Comments from Google Site

I have a Google Site at which I am trying to topically arrange info on the cholinesterase inhibitor issue. (Yeah, I know I mention it in almost every blog post -- that's the main thing I'm interested in at the moment.)

Unfortunately it turns out that Google Sites does not support comments from anyone other than owners or collaborators. I found a forum thread that addresses this issue, and it basically says: Blogger is for comments; Sites isn't. Therefore this Blogger post is intended as a place where people can comment on my Sites pages.

Please comment here!

Tuesday, May 26, 2009

"Motivation": Cortex vs. Limbic System

I speculate that dopamine affects how easy or hard it is to initiate activities. This particularly seems to affect activities requiring significant energy, like exercise, and/or decision making, like planning a trip or moving. I introduced this idea a little bit in an earlier blog post.

I found that when I was dopamine deficient, I couldn't initiate exercise myself. I could tag along if someone else initiated it though, and feel better during and after. A woman from my church invited me to go walk with her on Tuesday mornings, and I could do that. My husband and I joined a twice weekly yoga class, and I could go to that.

It seemed silly to me that I couldn't initiate these sorts of things myself. In the past I treated this as a moral failing, and beat myself up about it. That made me feel awful, but I still mostly wouldn't be able to do it. This most recent time I was more accepting about it. I still tried to convince myself to go exercise, but was more gentle about it. Sometimes I would succeed in going and exercising by myself, but mostly I wouldn't. Instead of treating it as a moral failing, I treated it as a science experiment. What was different about the times when I was able to go and exercise?

Once I got the dopamine increased enough I could mostly initiate exercise by myself no problem. It wasn't that I was trying harder, or being more morally upright. It just felt like a road block that had been there was just gone.

When I studied more about dopamine, and what affects it, I realized that dopamine levels seemed to correspond to how easy or hard it was to initiate that sort of activity. When dopamine levels were mostly low, I would only be able to do it as a follower or after some sort of experience that sufficiently increased dopamine. Now that dopamine levels are mostly ok (got the bupropion working right), I can initiate exercise myself most of the time, except after experiences that sufficiently decrease dopamine.

All this made me realize that the concept we call "motivation" really has more facets than I'd realized before. What you think about how much you "should" do something, how much you want to do it, and what you think about where it ranks in your priority and value schemes are one set of factors. How you feel when your think about doing something -- how your biochemistry reacts to the idea -- is another. They're controlled by different parts of your brain (cortex vs. limbic system), and are not always in sync.

I suspect that the latter part is the one that's more tied into physiological state -- how much dopamine, energy, etc. you've got to start with and how those change in reaction to your proposed activity, like exercise. It can agree and reward you with an added burst of dopamine, which makes it real easy and appealing to go off and initiate the activity. It can also disagree and make you feel uneasy about it (not sure if this is it decreasing dopamine, increasing stress chemicals, or both), and make it real hard.

It seems to me that in some cases the meaning of "motivation" is pretty clear:
  • Motivated = cortex decides to do it, limbic system agrees, you do it
  • Unmotivated = cortex decides not to do it
However, what do we say about the case where the cortex decides to do it but the limbic system disagrees? Generally this is where things gets tough and we are prone to beat ourselves up. I bet we end up in this state more often when dopamine is low. I also bet that when dopamine is low and we end up in this state, we're much less likely to be able to force ourselves to initiate the activity anyway. Here's the trap: the way we think about failing to initiate activities like this can further decrease dopamine, making it even harder next time.

I certainly find myself in that state much less often now. For a few months, before using the bupropion to increase dopamine tone, I was in that state almost all the time. I exercise much more often now than I did then. I don't actually decide to exercise any more often -- likely I decide to do it less frequently. The difference is that now it's much easier to follow through on that decision. Does that reflect a difference in "motivation" or not?

Friday, May 15, 2009

Evaluating food risk: "spices" vs. "fava bean flour"

My husband Randy and I recently moved to Pittsburgh. He likes a local chain here called Panera's that looks like a bakery and projects a more-than-usually convincing image of wholesomeness. From the ordering line you can see a glimpse of a convincingly realistic bakery kitchen. This resembles the sort of place where you'd expect the baked goodies to have been baked on-site.

The first time we went there, I wasn't yet ready to take a risk on eating anything there. After all, baked goods are at risk of containing hidden potato starch. I watched him eat a very yummy looking souffle thingy and, truth be told, really wanted to eat one too.

The second time we went there I had decided to take the risk, ask about ingredients, and not feel left out this time. I was reassured that there was a sign behind the counter saying you could ask to see the list of ingredients. I asked for the ingredients for the most conservative souffle thingy they had: the Four Cheese Souffle.

I scanned the list of ingredients quickly looking for nightshade. I didn't see any, but I did see "spices," which can include hidden nightshade (usually paprika or other peppers). I asked if they knew which "spices" it contained, and if I could see the container. They looked at me funny, then looked at each other. I suddenly realized that they must not actually be made on-site. In retrospect, I should have figured that out from the length of the ingredients list, but I wasn't thinking that fast.

I went back to the ingredients binder and looked at the next most conservative item, the Egg & Cheese Breakfast Sandwich. If you go to Panera's Breakfast Sandwiches Menu, you will see that at first glance this contains 3 ingredients, and 12 descriptive words to positively influence you're attitude towards them. However, if you click on "Egg & Cheese" you get the real list, containing 36 ingredients, 29 of which are in the "two slices of freshly baked Ciabatta." The most memorable of these are "fava bean flour" and "distilled monoglycerides."

Admittedly this isn't as bad as an Egg McMuffin which at first glance contains 5 ingredients, but 64 when you dereference the ingredients (35 in "English Muffin", 2 in "Egg", 14 in "Canadian Style Bacon", 13 in "Liquid Margerine"). Now, a lot of those are duplicates, but it would still be a lot if the duplicates were removed. Also, that list includes scarier things, including "high fructose corn syrup", "partially hydrogenated soybean oil" and "artificial flavors" which Panera's happily doesn't.

Despite the carefully crafted image Panera projects, it would be unjust to consider just one of these breakfast sandwiches as "processed" -- they both are. Both are engineered to stimulate your senses in ways that mere unaided nature cannot compete with.

That's what I thought of when reflecting back on the experience. What I thought of while standing around hungrily perusing the ingredient binder is this: which is riskier, "spices" or "fava bean flour"? I vaguely remembered that fava beans have some pretty potent physiological effects, though I couldn't remember what they were. Most importantly, I haven't eaten any since I overcame the cholinesterase inhibitor stuff and started carefully adding foods back in. I didn't even dare to think about the distilled monoglycerides...

In the end, I decided to go for the Egg & Cheese Breakfast Sandwich as the least of three evils (the third being to sit there hungry watching Randy eat his souffle). It was reasonably tasty, and happily I did not notice any nasty side effects of having eaten it.

The next day I made an egg & cheese sandwich at home. The eggs, cheese, and butter were local. (I later got to meet the farmer in Ligonier who raised the eggs.) The bread was organic and baked at Whole Foods. It was yummier, and led to less angst.