9
$\begingroup$

I've scoured Google and this site and I am still confused about the lmer function in the lme4 library.

I have some data collected from different psychiatric wards, which have a multilevel structure. To simplify, I'll pick two level 2 and two level 1 variables, although I actually have a few more.

Level 2- WardSize [this is the number of people on the ward] & WAS [this is a measure of how "nice" the ward is]

The grouping variable that tells R who's in which ward is called "Ward"

Level one- Gender [this is gender, obviously] & BSITotal [this is a measure of symptom severity]

Outcome is Selfreject, which again is what it sounds like.

I have this formula:

help=lmer(formula=Selfreject~WardSize+WAS+Gender+BSITotal+(1|Ward))

I'm hoping this means "each individual has a score related to their own Gender and symptom severity, and also a ward-level effect relating to the size of the ward and how "nice" it is"

Is this correct? The thing that's confusing me is that I can't see how R can tell which are level 1 and which level 2 variables, except for the ward level intercept given at the end.

If anyone could explain the notation so an idiot like me can understand that would be even better.

Many thanks!

$\endgroup$

2 Answers 2

12
$\begingroup$

Your model specification is fine.

The varying intercept for Ward, specified in lmer as you've done with (1 | Ward), is saying that subjects within each ward might be more similar to each other on Selfreject for reasons other than WardSize or Gender, so you are controlling for between-ward heterogeneity.

You can think of the "1" as a column of 1s (i.e., a constant) in the data to which an intercept is fit. Usually the "1" is implied automatically in lm, for instance

lm(Y ~ X1 + X2)

actually specifies

lm(Y ~ 1 + X1 + X2)

Now that you have your basic model, you can start asking further questions like "Does the relationship between BSItotal and Selfreject differ between wards?"

lmer(formula=Selfreject ~ WardSize + WAS + Gender + BSITotal + (1 + BSITotal | Ward))

That is, both the intercept and the slope of BSITotal can differ between wards.

If you haven't picked it up yet, Gelman & Hill's Data Analysis Using Regression and Multilevel Model/Hierarchical Models is a great book that explains fitting models like this with lmer.

$\endgroup$
1
$\begingroup$

Here is a link to an explanation by Douglas Bates (who wrote lme4) as to why it's not necessary to specify the level for fixed effects.

$\endgroup$
2
  • 2
    $\begingroup$ Welcome to the site, @Breyer. I suspect this is a helpful contribution. Would you mind giving a brief summary of the argument there, so readers can decide if it's what they're looking for, or in case of future linkrot? $\endgroup$ Commented Apr 4, 2013 at 3:56
  • 2
    $\begingroup$ Thanks for the welcome @gung. Sure, Bates explains that it's not necessary to specify levels for fixed effects because the lme4 package is written for mixed models, including but not limited to multilevel/hierarchical models. This means the computational methods do not rely on the specification of levels, as is the case for specialized multilevel regression software (HLM etc) that leverage the nested data structure in computation. $\endgroup$
    – Breyer
    Commented Apr 4, 2013 at 4:57

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.