2
$\begingroup$

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!

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ In R, the var1*var2 terms translate into both main effects plus the interaction term, namely: var1 + var2 + var1:var2 (that is, in R, the interactions are denoted with :, while * includes all possible main effects and interactions). This is not reflected in your equations. $\endgroup$ Commented Oct 26, 2013 at 4:39
  • $\begingroup$ Thanks @PatrickCoulombe! Sorry for the careless error and I fixed it above. $\endgroup$
    – Randel
    Commented Oct 26, 2013 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.