Including a series of dummy variables in a regression in R is very simple. For example,
The above regression automatically includes a dummy variable for all but the first level of the factor of the Diet variable.
This is great, and it's often what you want. But in this case, it's comparing each of the diets to Diet1. In some cases, you might want to compare to a specific diet that isn't the first in the factor list.
How can we choose which dummy to compare to? Fortunately, it's simple to compare to a specific dummy in R. We can just relevel the factor so the dummy we want to compare to is first.
The "ref" argument allows us to change the reference level of the factor variable. This means that when we perform regression analysis
You can use table or str to find the factor levels, if you don't already know them.
After releveling the factor variable, we can simply perform the same regression again, and this time it will compare the results to the new reference level:
Now we can choose any factor level as the reference for the series of dummies in the regression analysis. The code is available in a gist.