What approach to use?

When dealing with clustered data we have observations that are non-independent and reside within some grouping structure. This could be replicate samples for a specimen in an experiment, children nested within schools, which themselves are nested within districts, we might obtain the same measures at different time points for the same unit of observation, etc.

In such cases standard methods may be applied, just as they can be anywhere, but they would be lacking in some respect. The following demonstrates a number of methods that might be used in these situations, but while some will definitely be better than others, in other cases, it might be a practical or theoretical choice that drives the decision on how to deal with the data. In what follows, I will create a data set for us to use so that we don’t have any questions as to what might be going on, or what nuances we are not privy to that might produce differences in the results.


Things to note

No attempt is made at providing too much detail on model specifics. It is assumed that if you’re reading this you’re already at least conceptually familiar in some sense with a couple of these models. The primary purpose here is to compare, contrast, and note issues. Sometimes a little more detail is required, but again, the goal is not to teach the methods themselves. See the references for more detail.

In many cases I hide the code but it is still available for viewing, especially in cases where it involves mostly data setup or wrangling, or involves more detailed technique than I am assuming some readers of this doc will understand. I prefer this document to be a more conceptual in nature and tool agnostic. Though it relies on R, the tool used doesn’t matter, and all the models conducted here could be run using other packages.

In describing some of these approaches I suggest that some are more discipline specific or more common in certain areas. This assessment is based on years of consulting across many, many academic disciplines, as well as reading many discipline-specific texts and articles, but this admittedly is not a random sample, so take that info as you wish. I just provide it as a means for the reader to understand why they may not be familiar with such a technique, and where they might find more information or examples.


Note that in the following, terms such as ‘clustering’ and ‘cluster’ have nothing to do with unsupervised learning methods such as mixture models. I use the terms ‘cluster’, ‘grouping’ and similar terms as synonyms. As ‘mixed’ models incorporate random effects, I don’t normally distinguish between a random effects model (which could be seen as the general case) and a mixed model, except perhaps when comparing to ‘fixed effects models’. I’m not going to get into it here, but ‘fixed effects’ and ‘fixed-effect models’ are not the same thing1. I will try to be clear.

Color coding:

  • emphasis
  • package
  • function
  • object/class
  • link

This doc also available in .epub and .pdf (See the icon above), though the doc is automatically converted to those formats, and to be perfectly honest I don’t care what may or may not look good or transfer appropriately.

  1. Blame the economists.