# Specify LMM in lme4 with two predictors but random intercepts for just one of both predictors

I want to specify a linear mixed model with one dependent variable (DV) and two independent variables (IV). Furthermore, I want to add random intercepts for each of my participant but just for my first (IV1) and not the second (IV2) independent variable. How do I specify that using lme4 in R?

Currently I use the following specification, which in my understanding includes the random intercepts for both of my IVs.

DV ~ 1 + IV1 + IV2 + IV1:IV2 + (1|participant).

With IV1 and IV2 being my fixed effects, IV1:IV2 representing an interaction between my fixed effects and (1|participant) representing my random intercepts.

However I want to specify random intercepts per participant for my IV1 only. How do I do that?

Thanks a lot :)

It makes no sens to add a random intercept "for an independant variable". A random intercept is as its name suggests an intercept. You can see it a a kind of bonus/penalty for each participant added to the regression formula (this is not exactly the case). However, you can also change the slope of independant variables according to the participant. In that case, you will add a bonus/penalty to the global coefficient depending on the participant.

So this formulation is the random intercept only :

DV ~ 1 + IV1 + IV2 + IV1:IV2 + (1|participant)

Here you have a random slope only for IV1 :

DV ~ 1 + IV1 + IV2 + IV1:IV2 + (0 + IV1|participant)

And here both of them combined :

DV ~ 1 + IV1 + IV2 + IV1:IV2 + (1 + IV1|participant)

You could read the vignette of the lme4 package to get a better grasp on mixed effect models (https://cran.r-project.org/web/packages/lme4/vignettes/lmer.pdf)

I hope it will help !

• Thanks for the answer and clarification. Luckily I arrived at the same conclusion myself after thinking it through once more. The random intercept of course refers to how high the intercept per participant is with regard to my DV right? So it makes no sense to specify it per IV. I am confused though by the way you specified the combination of two random slopes though. I thought it should look like this: DV ~ IV1 + IV2 + IV1:IV2 + (1 + IV1 + IV2 | participant)
– der
Nov 19, 2021 at 15:38
• yes, DV ~ IV1 + IV2 + IV1:IV2 + (1 + IV1 + IV2 | participant) is the way to go to have a random slope for both. Note that the model will estimate also the correlations between your random effect. These parameters can be very interesting to analyze bet require enough data and participants. You could also specify independant random effects with : DV ~ IV1 + IV2 + IV1:IV2 + (1 | participant) + (0 + IV1 | participant) + (0 + IV2 | participant) Nov 19, 2021 at 17:17