[R-sig-ME] Trying to understand the syntax of lmer
bbo|ker @end|ng |rom gm@||@com
Sun Sep 15 00:20:50 CEST 2019
On Sat, Sep 14, 2019 at 5:42 PM Sorkin, John <jsorkin using som.umaryland.edu> wrote:
> 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.
> 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?
I'm confused. Are you referring to this model
(a) > lmer(distance ~ age +(1|Subject)+(0+age|Subject), data=Orthodont)
(b) lmer(distance ~ age + (age|Subject), data=Orthodont)
Both models allow varying intercepts and slopes among Subjects.
> # (4) If it is, what is the assumed covariance structure between slope and intercept?
(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.
> # (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)
(a) it's constrained to be zero
> # (7) The next two models, I believe have a random intercept (a separate 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)
Yes. In the second model, the fixed effect specification is slightly
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
section 2.2 of Bates et all JSS paper [vignette("lmer",package="lme4")]
(and links therein:
> Thank you for your patients with my eight questions.
> 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)
> R-sig-mixed-models using r-project.org mailing list
More information about the R-sig-mixed-models