I'm currently working with data which has continuous variables and a hierarchical structure attached to it, think of measuring blood pressure, size and weight of different domestic animals (cats, dogs, birds) as well as of their species, family and order.

All data is measured on the level of the individuals, so there are no predictors on higher levels (although they could be generated by taking, e.g. the inter-level mean).

Let's say I want to predict the blood pressure ($y$) with the help of the weight ($x_1$) and the size ($x_2$).

Ignoring the hierarchical information, I could use a linear model $y= \beta_0 + x_1\beta_1 + x_2\beta_2$, which might be a very bad idea.

If I only had two different species measured, I could use one binary dummy variable $d$ and consider $y= \beta_0 + x_1\beta_1 + x_2\beta_2 + d \beta_3$.

If I wanted to consider $n$ species instead, would I need $n$ variables $d_1, \dots, d_n$ and consider $$y= x_1\beta_1 + x_2\beta_2 + \sum_{i=1}^n d_i \beta_{i+2},$$

Is this the right approach for dummy variables if there are more than two categories?

The last model doesn't account for the hierachical structure. If I wanted to include the family as well (assuming for simplicity that there are only 2 families, but multiple species), would adding another binary predictor $\tilde d$ suffice?

$$y= x_1\beta_1 + x_2\beta_2 + \sum_{i=1}^n d_i \beta_{i+2} + \tilde d \beta_{n+3}$$

Is this the right approach to implement hierarchical dummy variables?

Edit: Removed the intercept as it was suggested in the answer of Maarten Buis.


Your first question: Close but not quite: you either need to leave one of your species out of the model as a reference category or you need to leave out the constant. In the former case each $\beta_{i+2}$ measures the difference between species $i$ and the reference species, so the parameter of the reference species is necessarily $0$, which means that the indicator variable for the reference species drops out of the model. In the latter case each $\beta_{i+2}$ is the constant for each species, which means that there is nothing left to do for the overall constant $\beta_0$ so it should drop out.

Your second question: No, all the information is already captured by the species indicator variables (a term I prefer over dummy variable), so there is nothing for the family indicator variables left to explain and they will be automatically dropped from the model due to perfect multicolinearity.

  • $\begingroup$ So species indicator variables can be used to reflect a 2-level structure, but they do not reflect the additional structure of a 3- or 4-level model - am I reading this correctly? $\endgroup$ – Roland Mar 19 '14 at 9:21
  • $\begingroup$ I don't understand that comment. I see only two levels: species and families. Where is that 3rd and 4th level comming from? As long as the levels are hierarchical, than indicator variables at the lowest level (e.g. species) will absorbe all the variance of all the higher levels (e.g. families). $\endgroup$ – Maarten Buis Mar 19 '14 at 9:47
  • $\begingroup$ Oh, I might be using terminology incorrectly. With 2 levels I mean the individual pet level (level 1), and the species level (level 2): I'd call the simple linear model without species indicators a 1-level model, and as soon as we have species information, we would have a 2-level model. The third level would be one which includes families as well. A fourth level (order) was not written down in the models, but mentioned in the introduction. $\endgroup$ – Roland Mar 19 '14 at 10:08
  • $\begingroup$ So family and order indicator variables will add nothing once you have included the species indicator variable. As a consequence, these will result in perfect colinearity and they will be dropped. $\endgroup$ – Maarten Buis Mar 19 '14 at 10:15
  • $\begingroup$ You could go the other way around though: first add only order, than add only family (which implictly also includes order, so leave that out), than add only species (which implicitly includes also family and order, so leave those out) $\endgroup$ – Maarten Buis Mar 19 '14 at 10:18

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.