Very basic question here from a new user of Stan. I’m attempting to implement my first multilevel model, and I’ve been referencing some code that appears in the Stan manual (p151 and screenshot below). As part of the cholesky factorization optimization, the ‘group coeffs’ matrix is declared as matrix[L,K] gamma, where L = # of group predictors and K = # of individual predictors. Could someone explain why its dimensions are [L,K]?

It’s also declared the same shape in the original model on 148.

I think it’s just that you use an individual’s group properties (of which there are L) to predict the mean of their individual properties (of which there are K).

row_vector[L] u[J] is the list of group predictors for each person, so u[j] * gamma gives a row_vector of length K (number of individual predictors) for each individual (which is then used to build a distribution over betas …).

Something like that? Not familiar with the model, just going by dimensionality analysis.

One other related question: what is exactly is contained in u[j]? You say it’s a list of group predictors for each person, but the dimensions are [J,L], not [N,L]. Does the input data frame need to have these group-level predictors pre-aggregated, or does this occur automatically within Stan? Again, apologies for the basic line of questioning, I’m still wrapping my head around this.

Thanks again for your responses @bbbales2! I have an additional dimension question on this code block regarding the rows_dot_product function. It’s my understanding the matrices supplied to rows_dot_product (beta and x) need to have the same number of rows; however, in this case from the manual beta is a matrix[J,K] while X is matrix[N,K]. What am I missing?