How to express mixed logistic regression in formal notation?

I'm working with glmer in the lme4 package in R to estimate a binary outcome variable from two categorical predictors (with 3 levels each) as well as two random effects parameters. The data I'm trying to predict are binary outcome data generated by an experimental design in which multiple participants (Subject) completed multiple test items (Item). I allow only intercepts to vary randomly by Subject, and allow slopes for X1, (but not X2) and intercepts to vary by Item. I also include an interaction term for the two three-level categorical predictors. In other words, my glmer formula is:

~ X1 * X2 + (1 + X1|Item) + (1 | Subject)


My question is: how do I correctly represent this model formula as an equation?

I have read @BenBolker's recommendations on model specification, here. The closest model specification to mine given there is this:

∼ X + (1 + X∣Subject) + (1∣Item)


...and the recommended equation to represent it is given as:

$$(\beta_0+b_{S,0s}+b_{I,0i})+(\beta_1+b_{S,1s})X_i + e_{si}$$

where $$b_{S,0s}$$ represents random intercepts for Subject, $$b_{I,0i}$$ represents random intercepts for Item and $$b_{S,1s}$$ the random slope increment for $$\beta_1$$.

Based on this formula, I've tried to express my model as follows:

$$log(p_{si}/(1-p_{si})) = \\ (\beta_0 + b_{S,0s} + b_{I,0i}) + \\ (\beta_{1} + bl1_{I,1i})X1lev1_s + \\ (\beta_{2} + bl2_{I,1i})X1lev2_s + \\ \beta_{3}X2lev1_s +\\ \beta_{4}X2lev2_s+\\ \beta_{5}X1lev1:X2lev1_{s}+\\ \beta_{6}X1lev1:X2lev2_{s}+\\ \beta_{7}X1lev2:X2lev1_{s}+\\ \beta_{8}X1lev2:X2lev2_{s}$$

Where $$_s$$ and $$_i$$ index Subject and Item, respectively, and random intercepts for these terms are represented by $$b_{S,0s}$$ and $$b_{I,0i}$$. The random slopes for each level of X1 are represented by $$bl1_{I,1i}$$ and $$bl2_{I,1i}$$, i.e. $$l$$ stands for each level. Finally, I include fixed effects for X2 with no random slope component, as well as the 2x2 interaction terms between each of the levels of X1 and X2.

My question is, is this correct? If not I'm hoping someone could please explain why as well as provide the correct equation.

• A nice blog post on mixed modelling as a foreign language: thestudyofthehousehold.me/2018/02/28/…. – Isabella Ghement Aug 29 '19 at 1:24
• Ok, thanks for all your time and attention:) – Cole Robertson Aug 30 '19 at 11:38
• Well, I found Bolker's recommendation from that blog post, and I think they certainly were helpful. Thanks. – Cole Robertson Aug 30 '19 at 11:42
• At least something I recommended was helpful! I’ll settle for that. 🤪 – Isabella Ghement Aug 30 '19 at 11:46
• You've been very helpful, it's just that the question wasn't about experimental design:) – Cole Robertson Aug 30 '19 at 12:15

Your equation seems correct; I would write something like: \begin{align} \log \left(\frac{p_{si}}{1-p_{si}}\right) = & \,\, \beta_0 + b_{S,0s} + b_{I,0i} \\ & + (\beta_{1} + b_{I,1i}) \cdot X1_1 + (\beta_{2} + b_{I,2i}) \cdot X1_2 \\ & + \beta_{3} \cdot X2_2 + \beta_{4} \cdot X2_2 \\ & + \beta_{5} \cdot X1_1:X2_1 + \beta_{6} \cdot X1_1:X2_2\\ & + \beta_{7} \cdot X1_2:X2_1 + \beta_{8} \cdot X1_2:X2_2 & \end{align}

The only part that is missing to fully specify the model are the distribution of the random effects:

$$b_S \sim \mathcal{N} \left(0, \sigma_S^2 \right) \\ {\bf b}_I \sim \mathcal{N} \left(0, \Omega \right)$$ where $$\Omega$$ is the variance-covariance matrix of the random effects, e.g.

$${\bf b}_I = \left[ {\begin{array}{*{20}{c}} {{b_0}}\\ {{b_1}}\\ b_2 \end{array}} \right] \sim\cal N \left( {\left[ {\begin{array}{*{20}{c}} 0\\ 0\\ 0 \end{array}} \right],\Omega = \left[ {\begin{array}{*{20}{c}} {\sigma_0^2}&{{\mathop{\rm cov}} \left( {{b_0},{b_1}} \right) } & {{\mathop{\rm cov}} \left( {{b_0},{b_2}} \right) }\\ {{\mathop{\rm cov}} \left( {{b_0},{b_1}} \right)}&{\sigma _1^2}& {{\mathop{\rm cov}} \left( {{b_1},{b_2}} \right) } \\ {{\mathop{\rm cov}} \left( {{b_0},{b_2}} \right)}& {{\mathop{\rm cov}} \left( {{b_1},{b_2}} \right) } & {\sigma _2^2} \end{array}} \right]} \right)$$ (where I simplified the notation in the subscripts for clarity).

• Thanks so much! – Cole Robertson Sep 5 '19 at 11:55