[R-sig-ME] lmer function in R for linear mixed models : syntax - your views

Kim Pearce k|m@pe@rce @end|ng |rom newc@@t|e@@c@uk
Thu Jun 27 16:41:21 CEST 2024


Hello everyone,

I am a senior statistician working in Newcastle University, UK.  My question relates to the generation of a (hypothetical) linear mixed model using R's lmer function within the lme4 package.

I wonder if anyone has any views on the following?

Hypothetically, say we had a response (Y) from N subjects which was recorded at baseline and at each of 6 subsequent years.  "Time" (values 0,1,2,3,4,5,6) is recorded for each subject. "Medication dose" (continuous) is recorded for each subject at each of the time points.  Each subject's baseline severity group is also recorded.

In this hypothetical situation, time (level 1) would be nested within patient (level 2).  At each time point, medication dose and associated response would be recorded for each patient (and each patient belongs to a specific baseline severity group which, of course, would be constant for each patient).  I am hypothesising that the effect of medication (i.e. dose) on response could vary as a function of patient and the change in response over time could vary across people too.  In my example, I am thinking about a model that could possibly include random intercepts, fixed and random slopes for time and fixed and random slopes for medication (i.e. dose) plus q-1 fixed slopes for the q category baseline severity group.

In my model, the response (Y) takes a continuous form and I am taking "time" (time) and "medication dose" (meddose) as continuous - additionally, baseline severity group (basesevgroupf) is declared as a factor i.e. categorical.

Would the following syntax be correct?

Modely <- lmer(Y ~ time + meddose + basesevgroupf + (time + meddose | subject), data=datafile)

Or equivalently:

Modely <- lmer(Y ~ time + meddose + basesevgroupf + (1+ time + meddose | subject), data=datafile)

(Additionally, as I understand it, the above pieces of syntax would create a model with correlated random intercepts and slopes)

I ask this question as examples I have seen utilising R usually focus on the situation when the linear mixed model either contains (i) just random intercepts or (ii) random intercepts and random slopes for one predictor (whereas, in my hypothetical example, the model contains random intercepts and random slopes for two predictors).

Many thanks, in advance, for your views.
Best wishes,
Kim

Dr Kim Pearce PhD, CStat, Fellow HEA
Newcastle University 



More information about the R-sig-mixed-models mailing list