# Nested Nutrition

Recall that I’ve described the menustat.org data in a couple of previous posts. One of the first things I decided to do with it was to investigate what should be a pretty lawful set of relationships - that between the three primary macronutrients and total calories. Each macronutrient contain a set number of calories per gram:

• Fats: 9 kcal/gram
• Protiens: 4 kcal/gram
• Carbohydrates: 4 kcal/gram

This implies that if we predict the number of calories in the collection of food listed in our menustat data from the listed macronutrients, then we should obtain regression coefficients which are just about equal to those numbers (e.g. the regression coefficient for fats should be nearly exactly 9). Is this true? I’ve skipped the reading and cleaning of data, as I’ve covered it extensively elsewhere.

###Always looking at data### As might be clear by now, I’m a big advocate of looking at data first, before modeling anything. So, let’s scatter the things we’re interested in modeling:

So that’s pretty interesting. Although these are certainly strong relationships, the mapping is not perfect. There is, however, a pretty hard cutoff for each of these things. The upward spread in each can probably be accounted for by the other macronutrients. Points which fall along the hard cutoff will be foods that contain only the macronutrient illustrated in that plot, because having 100 grams of protein but only 5 calories is not possible. However, haivng 100 grams of protein and 2000 calories certainly is.

###Simple model### As a first pass, let’s account for all this observed variability in a simple linear model.

Hey! That’s almost perfect! The coefficients for proteins and carbs are not significantly different than 4, and the coefficient for fat is not significantly different than 9 - just like you would expect for something dictated by a lawful relationship such as this. Moreover, the r-squared is an astonishing .99. Wow. I’ve never analyzed anything like this before.

However, they’re not exactly right, are they. In fact, there’s something that caught my eye here. It’s the direction of the estimates. When Americans look at the nutrition of the food they’re consuming, do you think that, in general, they’re looking to maximize or minimize their intake of protein? What about carbohydrates? And fat?

Do you notice that the direction that each of these estimates differ from zero go in precisely the same direction as the social desireability of each macronutrient? Maybe this is nothing - just noise in the data that happens to correspond to some broader social issue. Or, maybe it isn’t.

###Clustered Data### One thing we can do is see if there are individual eateries whose reported nutritional info is systematically in line with these societal expectancies. This also highlights a major problem with using a standard linear model in this situation - our data are clustered. There are lots of ways in which this is true, but one obvious one is that it is clustered by restaurant. This means that the observations from one restaruant are going to look more like the observations from that restaurant than they will observations from another restaurant. This structure violates one of the assumptions of the simple linear model I ran above. One way around this is to use a mixed effects model.

That kicked out a nasty warning message (which seems to be because of the size of the dataset). I could scale the variables to get rid of it, but everything seems to look okay (note the coefficient estimate), so I’ll just move forward.

The basic idea here is that we’ve fit a model which is largely similar to the first one, but allowed the intercept and effects of protein, carbohydrate, and fat to randomly vary by restaurant. Now that we’ve done this, we can go in and get these random effects to see how restaurants may differ in their reported relationship between these macronutrients and the calories. I’m going to get these values and standardize them. This will allow me to ignore the fact that there’s probably going to be more variability on fat because it’s got a higher mean value. I’m also going to reverse the direction of the values for protein because I want the values for each of these to be consistent with social desireability. In other words, it is socially desireable to indicate lower numbers for carbohydrates and total fat, but higher numbers for protein. I’m going to switch the sign on protein so that for all three, lower numbers mean more socially desireable.

Question of interest: What happens if I standardize the random effects versus standardize the predictors in the model?

Now, let’s look at the deviation on these bad boys. We can sum across each random effect to examine a new metric I’m going to call ‘reporting tendency’. Negative numbers here will indicate a tendency to report in a socially desireable way, while positive numbers will indicate a tendency to report in a non-socially desireable way.

Hm. A couple of outliers down there. This whole exercise may yet end up being another lesson in what messy data is really like. I’m going to have to address this in a future post.

How’s that for a cliffhanger?

Written on March 6, 2015