Skip to content

Trying to understand the syntax of lmer

2 messages · Sorkin, John, Ben Bolker

#
Colleagues,
I hope you will not mind my asking seven questions, questions designed to allow me to know if my basic understanding of lmer syntax is correct. Below I post code and in the comments 7 questions.?


data(Orthodont,package="nlme")
Orthodont$nsex <- as.numeric(Orthodont$Sex=="Male")
Orthodont$nsexage <- with(Orthodont, nsex*age)

# (1) Is this a model with a random intercept in which, each subject has his, or her own intercept?
lmer(distance ~ age +(1|Subject),data=Orthodont)

# (2) Is this a model with a random slope, where age is the slope, each subject having their own slope?
lmer(distance ~ age + (0+age|Subject), data=Orthodont)

# (3) Is this a model with random intercept, Subject, and random slope age?
# (4) If it is, what is the assumed covariance structure between slope and intercept?
# (5) Is the covariance structure assumed to be unstructured?
# (6) How can I get the estimated covariance between intercept (subject) and slope (age)?
lmer(distance ~ age +(1|Subject)+(0+age|Subject), data=Orthodont)
# (7) The next two models, I believe have a random intercept (a sparate slope for each subject),
# ? ? an age*sex interaction, a random slope (age) for each subject. Are my assumptions correct?
lmer(distance ~ age +Sex+nsexage+(1|Subject)+(0+age|Subject), data=Orthodont)
lmer(distance ~ age +Sex+Sex*age+(1|Subject)+(0+age|Subject), data=Orthodont)

Thank you for your patients with my eight questions.

John



John David Sorkin M.D., Ph.D.

Professor of Medicine

Chief, Biostatistics and Informatics

University of Maryland School of Medicine Division of?Gerontology and Geriatric Medicine

Baltimore VA Medical Center

10 North Greene Street

GRECC (BT/18/GR)

Baltimore, MD 21201-1524

(Phone) 410-605-7119

(Fax) 410-605-7913 (Please call phone number above prior to faxing)
#
On Sat, Sep 14, 2019 at 5:42 PM Sorkin, John <jsorkin at som.umaryland.edu> wrote:
Yes
Yes
I'm confused.  Are you referring to this model

(a) > lmer(distance ~ age +(1|Subject)+(0+age|Subject), data=Orthodont)

or

(b)  lmer(distance ~ age + (age|Subject), data=Orthodont)

  Both models allow varying intercepts and slopes among Subjects.
(a) intercept-slope covariance is constrained to 0
 (b) variance-covariance matrix is positive semi-definite (i.e., both
eigenvalues >=0).  Correlation can be any value between -1 and 1.
(a) No.
(b) Yes.
(a) it's constrained to be zero
 (b) VarCorr(fitted_model)$Subject[1,2]
Yes. In the second model, the fixed effect specification is slightly
redundant.
  distance ~ age*Sex + ... (or ~ Sex*age + ...) will include the main
effects as well as the interaction.
(questions about fixed-effect model specification are not specific to
mixed models, but follow R's general rules as implemented by
model.matrix() ...)

See:

  section 2.2 of Bates et all JSS paper [vignette("lmer",package="lme4")]
 and https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#model-specification
(and links therein:
http://www.rensenieuwenhuis.nl/r-sessions-16-multilevel-model-specification-lme4/
and https://rpsychologist.com/r-guide-longitudinal-lme-lmer)