Design matrices unite seemingly disparate statistical methods, including linear regression, ANOVA, multiple regression, ANCOVA, and generalized linear modeling. As part of a hierarchical Bayesian modeling course that we offered this semester, we wanted our students to learn about design matrices to facilitate model specification and parameter interpretation. Naively, I thought that I could spend a few minutes in class reviewing matrix multiplication and a design matrix for simple linear regression, and if students wanted more, they might end up on Wikipedia’s Design matrix page.
It quickly became clear that this approach was not effective, so I started to think about how students could construct their own understanding of design matrices. About the same time, I watched a pretty incredible kung fu movie called Five Element Ninjas, and it occurred to me that the “five elements” concept could be an effective device for getting my students to think about model specification and design matrices.
Students should be able to specify design matrices for many different types of models (e.g., linear models and generalized linear models), and they should be able to interpret the parameters.
The broad idea was to get the students to think about model specification from five perspectives:
- Model specification via a design matrix
- Model specification via R syntax (e.g., the
- Model specification via “long form” equations
- Graphical model specification
- Verbal model specification (along with an interpretation of each of the parameter estimates)
This leverages what students already know, and encourages them to connect new concepts to their existing knowledge. In our case, the students were all students in CU Boulder’s Ecology and Evolutionary Biology graduate program. Most of them had a strong grasp of perspective 2 (model specification in R syntax), but relatively weak understanding of the remaining perspectives.
Getting the students started
Before we asked them to do anything, I demonstrated this five elements approach on a simple model: the model of the mean.
1. Design matrix specification
2. R syntax
The formula for a model of the mean is
y ~ 1
3. Long form equations
4. Graphical interpretation
5. Verbal description
I asked for a student to take a stab at a verbal description of the model specification, and also to explain the interpretation of the parameter $\beta$. If they’re having a hard time understanding the task, you can tell them to pretend that they are talking to a classmate on the phone and trying to describe the model.
We provided students with a very simple data set that does not include the “response” variable. This was printed ahead of time, so that each student had a paper copy that they could also use as scratch paper.
|Covariate 1||Covariate 2|
The omission of the response variable is deliberate, reinforcing the idea that one can construct a design matrix without knowing the outcome variable (this is useful later in our class for prior and posterior predictive simulations).
We organized the students into groups of three or four and had each group come up to the blackboard, which we partitioned ahead of time to have a space for each group to work. Then, we proceeded to work through incrementally more complex models with our five-pronged approach:
- A model that includes an effect of covariate 1.
- A model that includes an effect of covariate 2.
- A model that includes additive effects of covariate 1 and 2 (no interactions).
- A model that includes additive effects and an interaction between covariate 1 and 2.
Each of these exercises took about 15 minutes, and once all the groups were done we checked in with each group as a class to see what they came up with.
Some groups opted for effects parameterizations, while others opted for means parameterizations, which lead to a useful discussion of the default treatment of intercepts in R model formulas and the manual suppression of intercepts (e.g.,
y ~ 0 + x).
This in-class activity was surprisingly well-received, and it seemed to provide the context and practice necessary for the students to understand design matrices on a deeper level. Throughout the rest of the semester, model matrices were preferred over other specifications by many of the students - a far cry from the widespread confusion at the beginning of the semester.