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

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Thu Jun 27 18:11:32 CEST 2024


   This seems fine.  You would end up with a 3x3 covariance matrix 
(variation in intercept, slope with respect to time, and effect of dose 
across subjects, and 3 covariances).

   A bit more complicated, but e.g. Moritz et al (2023) fit models where 
the random effects include the intercept plus random slopes for *four* 
continuous covariates ...

   I might consider the possibility of a time-by-meddose interaction, 
both in the fixed effects and random effects (i.e. (1 + time + meddose + 
time:meddose | subject) or equivalently (1 + time*meddose | subject ), 
although that would expand your covariance matrix to 4x4 ...

   cheers
    Ben Bolker


Moritz, Max A., Enric Batllori, and Benjamin M. Bolker. 2023. “The Role 
of Fire in Terrestrial Vertebrate Richness Patterns.” Ecology Letters 26 
(4): 563–74. https://doi.org/10.1111/ele.14177.


On 2024-06-27 10:41 a.m., Kim Pearce via R-sig-mixed-models wrote:
> 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
> 
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models



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