Trouble with Mathematical Model

Sorry, your question fell through despite being well written and relevant.

The complicated code is just a way to write Z matrix from the matrix notation of a mixed model (Mixed model - Wikipedia). Sometimes, just stating the model in matrix notation is sufficient for the paper. If you want to be more detailed, you can decompose the matrix in individual coefficients. An example of how that might look like is on page 8 of my recent publication

Definitely also check out
Understanding the Mathematical Model and Mathematical description of a brms model where a similar problem is discussed.

Those question arise from time to time. The problem is that this is easy only for some models. But Stan (and even just brms) are very general and doing that generally is hard (and would often produce useless output anyway as it would just rewrite the code in greek which would be hard to understand). I’ve definitely thought about adding that capability to at least a common subset of brms models, but upon inspection it turned out to be likely quite a demanding project (but IMHO suitable for a motivated undergraduate student).

I would also mention that a growing part of academic readership would IMHO be faster to understand your model from the R formula than from the math notation, so - depending on your target audience - doing away with the math notation completely might be feasible, though a bit riskier as it is not (yet) commonly done.

1 Like