Solved – Specifying group covariates and cross level interactions in lmer

interactionlme4-nlmemixed modelr

I'm new to R, and despite trying to read as much as I can about how lmer works in R, I still don't feel like I know how to correctly specify more complex models using the lmer syntax.

For example, at the moment I want to use lmer for a two-level multilevel model, where the first level is features of a specific course taken by a specific student in a specific semester (with covariates like kind of course, teaching method, etc) and the second level is the student, which also has a number of covariates (e.g. ethnicity, gender, age, gpa at the beginning of the study, and score on a specific instrument). I also want to assess interactions with the teaching method, for example by including cross-level interactions between the second-level covariates ethnicity, gender, age, gpa, and the instrument score and the first-level covariate teaching method.

For the sake of readability, let's limit the equation to teaching method, course type, and score. It seems to me that I have seen three different ways of doing something like what I want to do in R – they are clearly all specifying something somewhat different, but I can't figure out what the underlying math is supposed to be for each case. So, for example, in different online references and the books on MLM that I have on hand, it seems that one of these three models is recommended for what I want to do:

course_outcome ~ course_type*teaching_method + score*teaching_method + (1|student)
course_outcome ~ course_type*score + (teaching_method|student)
course_outcome ~ course_type*teaching_method + score*teaching_method + (teaching_method|student)

I'm a little confused about the differences between how lmer interprets each of these three codings – is there any chance that someone who really understands R better could possibly translate this into the basic regression equation(s) structure that would be calculated in each of these three examples? Or direct me to a reference that might more clearly explain the difference by giving the regression equations for each case?

Thanks for your time!

Best Answer

The transformations from lmer codes to regression equations are listed below, where $u$ denotes the random effect, $i$ and $j$ indicate student and course respectively. Suppose the course features would not change with the students.

  1. course_outcome ~ course_type*teaching_method + score*teaching_method + (1|student)

    $$\mathrm{course\_outcome}_{ij}= \beta_0 +\beta_1\mathrm{course\_type}_j +\beta_2\mathrm{teaching\_method}_j +\beta_3\mathrm{score}_i +\beta_4\mathrm{course\_type}_j*\mathrm{teaching\_method}_j +\beta_5\mathrm{score}_i*\mathrm{teaching\_method}_j +u_i+e_{ij}$$

  2. course_outcome ~ course_type*score + (teaching_method|student)

    $$\mathrm{course\_outcome}_{ij}= \beta_0 +\beta_1\mathrm{course\_type}_j +\beta_2\mathrm{score}_i +\beta_3\mathrm{course\_type}_j*\mathrm{score}_i +u_{0i} +u_{1i}\mathrm{teaching\_method}_j +e_{ij}$$

  3. course_outcome ~ course_type*teaching_method + score*teaching_method + (teaching_method|student)

    $$\mathrm{course\_outcome}_{ij}= \beta_0 +\beta_1\mathrm{course\_type}_j +\beta_2\mathrm{teaching\_method}_j +\beta_3\mathrm{score}_i +\beta_4\mathrm{course\_type}_j*\mathrm{teaching\_method}_j +\beta_5\mathrm{score}_i*\mathrm{teaching\_method}_j +u_{0i}+u_{1i}\mathrm{teaching\_method}_j +e_{ij}$$

It may help you form some general ideas to interpret the codes. Note that $\beta$s across the equations have different meanings. It seems that course_type and teaching_method may be factors. If so, they would have several coefficients corresponding to the number of levels.

Related Question