6
$\begingroup$

I am running a multilevel log odds regression on a dataset that is at the individual level. Each individual belongs to a district, and there are both individual level variables (which vary by individual) and district level variables (which are constant per district). Let's call our explanatory variables ind_var1, ind_var2, dis_var1, dis_var2, our district dis, and our output variable out

I've been looking for the proper syntax on how to code this, and this is how far I've gotten:

mod1 = glmer(out ~ ind_var1 + ind_var2 + dis_var1 + dis_var2 + (1|dis), data = data, family = binomial(link = 'logit'))

My question is, is the above code correct syntax for construction the model, or does the syntax for the district level explanatory variables (dis_var1 and dis_var2) need to be edited?

$\endgroup$
2
  • $\begingroup$ This looks good! Why do you think the district variables would need to be edited? lmer understands these as level 2 or district-level predictors because, as you say, they are constant per district. $\endgroup$
    – Erik Ruzek
    Commented Feb 7, 2020 at 2:04
  • $\begingroup$ Great, thank you! It was hard to find an answer to my rather simplistic study as most of the other questions also included interactions and nested levels. That's awesome that lmer automatically understands the level of the variables. $\endgroup$
    – guest
    Commented Feb 7, 2020 at 20:48

1 Answer 1

3
$\begingroup$

There is often confusion about "the level that a variable varies" with mixed effects models, when someone comes more from a multilevel background and/or has used software such as HLM or MLwiN where (from what I remember) it is necessary to specify the level at which a variable varies. This is not the case with mixed effects models. The software "knows" what level a variable varies and it all that is needed is to include the variable in the fixed effects part of the formula.

The model formula you used looks to be absolutely fine.

$\endgroup$
2
  • 1
    $\begingroup$ Being familiar with both, only HLM needs to know whether a variable is at a higher level. You have to give it separate data files for each level. MLwiN, by comparison, is a dream. It has both its own interface and then the developers have created Stata and R packages to run MLwiN directly from those programs. $\endgroup$
    – Erik Ruzek
    Commented Feb 7, 2020 at 14:00
  • 1
    $\begingroup$ @ErikRuzek ahh thanks ! It's been quite a few years since I've used either. $\endgroup$ Commented Feb 7, 2020 at 14:58

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.