# Understanding multilevel multinomial models generated by brms

I would like to check my understanding of multilevel models generated by brms for the case of the multinomial family and would appreciate any comments.

Suppose there are three categories: `a`, `b`, and `c`. Suppose also there is one grouping factor: `age`. The formula is as follows:

``````y | trials(total) ~ (1 | age)
``````

where `y` binds counts for `a`, `b`, and `c` (in that order), and `total` is the total number of trials for the corresponding observations.

Would the following be a correct summary of the model being generated?

1 Like

That looks correct to me.

1 Like

Thank you for the answer! I cannot explain the following behavior, where we study the difference between the probabilities of `c` and `a`:

``````library(bayesplot)
library(brms) # ⚠️ Master on GitHub
library(tidyverse)

data <- tibble(a = seq(6) * 1000, b = 1000, c = seq(6) * 1000,
age = factor(seq(6))) %>%
mutate(total = a + b + c)
data\$counts <- with(data, cbind(a, b, c))

formula <- brmsformula(counts | trials(total) ~ (1 | age))
model <- brm(formula, data, multinomial(), seed = 42)

y <- with(data, (c - a) / total)
y_replica <- predict(model, newdata = data, summary = FALSE)
y_replica <- y_replica[ , , 'c'] - y_replica[ , , 'a']
y_replica <- sweep(y_replica, 2, data\$total, '/')
colnames(y_replica) <- seq(length(y))
mcmc_recover_intervals(y_replica, y)
``````

It looks like some kind of systematic error.

1 Like
1 Like

I will check what is going wrong. The multinomial distribution is quite new to brms and there may be some problems still hiding somewhere…

Can you try again with the latest version from github which I pushed a few hours ago. With that version I get the expected results.

1 Like

Cannot thank you enough! It looks adequate now!

For those who happen to stumble upon this question and would like to know more, here is an article, I have written, describing this very model applied to a real-world problem:

6 Likes

@IvanUkhov Your summary of multilevel multinomial using brms is very helpful! I am wondering If you or anyone else on the listserve has an example with repeated measures that I could work through to help me understand how I might adapt this kind of model to an experiment where dependent variable is 3 category choice that is repeated 60 times under different conditions.