I am unsure how the correct mathematical notation of two mixed model I've estimated in R should look like. The data consists of test scores of students that were in different classes. Some of the students have repeated measures. So after taking a test for the first time, the students have tried different study methods and then again taken a test. Two models were estimated to see if test scores are on average different (1) and if the stuy methods had a significant effect on test score (2) The models look in R look like this:

Test_score ~ Study_method + FE1 + FE2 + FE3 + (1 | Classroom ID)
Test_score ~ Study_method + FE1 + FE2 + FE3 + (1 | Classroom ID / Student_ID)

The data is structured as follows:


How is the mathematical notation of these two models? I'm especially unsure about the many subscripts and the repeated measures of some students.


Let $\texttt{Test_Score}_{ijk}$ denote the $k$-th test score of the $j$-th student in the $i$-th class. Then, the equation behind the first R formula is:

$$\left \{ \begin{array} \mbox{\texttt{Test_Score}}_{ijk} = \beta_0 + \beta_1 \texttt{Study_Method}_{ijk} + \beta_2 \texttt{FE1}_{ijk} + \beta_3 \texttt{FE2}_{ijk} + \beta_4 \texttt{FE3}_{ijk} + u_{i} + \varepsilon_{ijk},\\ u_{i} \sim \mathcal N(0, \sigma_u^2), \quad \varepsilon_{ijk} \sim \mathcal N(0, \sigma^2), \end{array} \right.$$

and the model behind the second R formula is: $$\left \{ \begin{array} \mbox{\texttt{Test_Score}}_{ijk} = \beta_0 + \beta_1 \texttt{Study_Method}_{ijk} + \beta_2 \texttt{FE1}_{ijk} + \beta_3 \texttt{FE2}_{ijk} + \beta_4 \texttt{FE3}_{ijk} + u_{i} + b_{ij} + \varepsilon_{ijk},\\ u_{i} \sim \mathcal N(0, \sigma_u^2), \quad b_{ij} \sim \mathcal N(0, \sigma_b^2), \quad \varepsilon_{ijk} \sim \mathcal N(0, \sigma^2). \end{array} \right.$$

A couple of notes regarding the formulation of these models

  • I have assumed that you are fitting linear mixed models with normally distributed error terms. If this is not the case, then you will need to adapt the equations accordingly.
  • Also it was not clear at which level the covariates $\texttt{Study_Method}$, $\texttt{FE1}$, $\ldots$, $\texttt{FE3}$ are measured. Therefore, to be more general I have used all subscripts in their definition. You could also change this if some of the covariates are in the class or student level by dropping the corresponding subscripts.

I am assuming you are using lme4 library in R. First of all you would like your data are normally distributed. So the command should be lmer(): "The first argument to the function is a formula that takes the form y ~ x1 + x2 ... etc., where y is the response variable and x1, x2, etc. are explanatory variables. Random effects are added in with the explanatory variables. Crossed random effects take the form (1 | r1) + (1 | r2) ... while nested random effects take the form (1 | r1 / r2)."

So for the Study_method, you need to look at the Fixed effects section from the fitting result, whether it is included in the table, if not, that suggests Study_method has no effect on the output.

For the Classroom ID/Student_ID, you want to check the Random Effect section, "this number is important, because if it's indistinguishable from zero, then your random effect probably doesn't matter and you can go ahead and do a regular linear model instead."

(adapted from http://ase.tufts.edu/gsc/gradresources/guidetomixedmodelsinr/mixed%20model%20guide.html)

  • $\begingroup$ Hej Bill! Thanks for your answer. You're right, I've been using the lmer() command. I guess my question may have been misleading, I'm aware of the interpretation of the R output but I am not sure how to transform the R syntax into a mathematical notation. So instead of Test_score ~ Study_method + FE1 + FE2 + FE3 + (1| Classroom ID) Test_score ~ Study_method + FE1 + FE2 + FE3 + (1| Classroom ID/Student_ID) I want to have a mathematical notation of the regression. I hope that makes my question clearer. $\endgroup$ – Juju Nov 8 '19 at 14:43

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.