Unfortunately the glm
distributions aren’t able to be applied in a vectorised fashion when there are random effects involved (only random intercepts), as the distribution assumes a common beta
for each individual.
You can either use the bernoulli_logit_glm
in an un-vectorised fashion, or you can use the bernoulli_logit
distribution but construct the linear predictor in a vectorised fashion.
To do this, you just need to declare both x
and beta
as matrix
types, and then you can use rows_dot_product
:
y ~ bernoulli_logit(rows_dot_product(x,beta[ll]));
Additionally, this will be faster if you can declare the inputs with the opposite dimensions, and then you can use columns_dot_product
instead: PSA: where possible, use columns_dot_product rather than rows_dot_product