I have a question about coding interaction effects using dummy coding which I’d be really grateful for your advice on please.

Imagine I want to design an experiment to measure the impact of amount of food eaten in grams (continuous variable) on happiness scores (continuous variable), in three animals; zebras, lions & giraffes.

My variables would be i) happiness, ii) food and iii) species.

As I understand it, I could set up a regression model in three different ways;

Using dummy coding (i.e. 1 or 0 for zebra & lion), with giraffe as my reference category;

Happiness ~ food + food x zebra + food x lion

Or, by including interaction terms for all species;

Happiness ~ food + food x zebra + food x lion + food x giraffe

Or, by including interaction terms for all species without a main effect;

Happiness ~ food x zebra + food x lion + food x giraffe

The 2nd example makes most sense to me, as it seems to isolate the trans-species effect of food eaten in the “food” variable, and then capture the interaction effect for each species. However, any guides I’ve read seem to recommend the former approach, but they don’t explain why. Please could someone explain whether one model is preferable?

NB: My concern with the first approach is that the “food” variable neither reflects a trans-species effect (because it is skewed towards the effect for giraffes, as they don’t have their interaction term) nor is it equivalent to the food*giraffe term, (as it includes some trans-species effect). Have I misunderstood something?


1 Answer 1


If your notation refers to R, when using * for interaction terms, both the main effect and the interaction are included in the model. In this regards, model 2 and model 3 will be equivalent.

If you only want to specify the interaction terms (under the form of an equation), then you should consider to include the main effect as explained by Franck Harrel here: Including the interaction but not the main effects in a model

Including all levels of categorical variable

As stated by Robert Long here: changing reference level, the difference between model 1 and model 2 (including giraffe) will not change your results... but only the way you interpret them. In your first model, giraffe will be included in your intercept (as reference) and other coefficients will be interpreted based on this reference. For example, the coefficient for lion will represent the variation (increase/decrease) in happiness score compared to giraffe.

On the other hand, your second model will specify the "direct effect" of each spicy on the outcome happiness (i.e. intercept from model 1 + coefficient of lion).

Relevant CV resources (interactions):


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.