Translating brms model into equation

Hi everyone,

I have a logistic hierarchical model that I ran using brms:

correct ~ 1 + experiment * phase + (1 + experiment * phase | strategy/subject)

Here, I wanted to predict the probability of getting a correct response, having experiment (categorical 2 levels) and phase (categorical 2 levels) as predictors; also, I have participants clustered within groups, and I wanted to get varying intercepts and effects for them, I used the following priors:

priors_logistic <- c(prior(normal(2, 2), class = b), prior(normal(2, 2), class = Intercept), prior(lkj(2), class = cor), prior(normal(0, 2), class = sd))

I want to report this model, and I am struggling to find an example similar to this to write the equation (having both varying intercept, effects and the interaction for nested clusters). So far this is what I think it should look like:

\begin{align*} \text{correct}_i & \sim \operatorname{Binomial}(n_i, p_i) \\ logit(p_i) & = \alpha_{jk[i]} + \beta_{1jk[i]}experiment + \beta_{2jk[i]}phase + \beta_{3jk[i]}experiment \times phase \\ \begin{bmatrix} \alpha_{jk} \\ \beta_{1jk} \\ \beta_{2jk} \\ \beta_{3jk}\end{bmatrix} & \sim \text{MVNormal} \left (\begin{bmatrix} \alpha \\ \beta_{1} \\ \beta_{2} \\ \beta_{3}\end{bmatrix}, \mathbf{S} \right ) \\ \mathbf{S} & = \begin{bmatrix} \sigma_\alpha & 0 & 0 & 0 \\ 0 & \sigma_{\beta_{1}} & 0 & 0 \\ 0 & 0 & \sigma_{\beta_{2}} & 0 \\ 0 & 0 & 0 & \sigma_{\beta_{3}} \end{bmatrix} \mathbf R \begin{bmatrix} \sigma_\alpha & 0 & 0 & 0 \\ 0 & \sigma_{\beta_{1}} & 0 & 0 \\ 0 & 0 & \sigma_{\beta_{2}} & 0 \\ 0 & 0 & 0 & \sigma_{\beta_{3}} \end{bmatrix} \\ \alpha & \sim \operatorname{Normal}(2,2) \\ \beta_{1}, \beta_{2} \ and\ \beta_{3} & \sim \operatorname{Normal}(2,2) \\ \sigma_{\alpha}, \sigma_{\beta_{1}}, \sigma_{\beta_{2}} \ and \ \sigma_{\beta_{3}} & \sim \operatorname{HalfNormal}(0,2) \\ R & \sim \operatorname{LKJcorr}(2) \end{align*}

But I am not sure if these lay out the model correctly. Thanks for your help!

Check out the equatiomatic package; while it won’t give you the prior parts it might be useful to check your translation of the likelihood structure?

2 Likes

Thanks! I’ll give it a try later today

The package is pretty cool. Unfortunately, it doesn’t support models from glmer.

You can find a few examples of 3-level covariance matrices here. I’m not sure any of them are exactly what you’re looking for, but they might give you some inspiration.

2 Likes

Thanks for sending this, Solomon it is very helpful! By the way, also thanks for translating McElreath’s book into brms, it was invaluable for me to learn how to build my models!

2 Likes