Random slopes

This lab will show you how to estimate a random-slopes model using brms.

Get the data

We'll use the Tennessee STAR data again, but this time limiting to a 50% random sample to speed up calculations:

Since we will be using student age as a predictor, we will need to create that variable. In the previous lab, we standardized age to have a mean of zero and a standard deviation of one. This time, we will simply center the student age. This means it will have a mean of zero, but the units will still be "years." We'll use the same trick as last time where we treat the negative year of birth as an uncenetered measure of age.

Specify the model

Our model is:

$$\begin{aligned} S_{ik} &\sim \mathrm{Norm}(\mu_{ik},\sigma)\\ \mu_{ik} &= \beta_{0k} + \beta_{1k}Age_i \\ \\ \beta_{0k} &= \gamma_{00} + \eta_{0k}\\ \beta_{1k} &= \gamma_{10} + \eta_{1k}\\ \\ \begin{bmatrix}\eta_{0k}\\\eta_{1k}\end{bmatrix} &\sim \mathrm{MVNorm}\left(\begin{bmatrix}0\\0\end{bmatrix}, \Phi\right)\\ \\ &\mathrm{(fixed\ priors\ omitted)} \end{aligned}$$

Note, we haven't talked about priors on covariance matrices yet — we'll cover that in the next class. For now we will just let brms pick the priors for us.


The "Group-Level Effects" section of the summary gives us the estimates of our entire covariance matrix.