What is the most efficient way to sample a matrix of parameters drawn independently from the same distribution? I’m working on a multinomial logit model where I have a matrix of coefficients \beta that includes one column for each of K-1 outcomes in the data. I have \beta declared as a D \times K-1 matrix where each element is distributed \mathcal{N}(\mu_\beta, \sigma_\beta), where \mu_\beta and \sigma_\beta are hyperpriors.

I’m currently using `to_vector`

to draw \beta because you can’t have a matrix on the left hand side of a `normal_lpdf`

. A MWE of the model is included below. Is this the most efficient approach to sampling these parameters?

```
data {
int<lower=1> N; // number of observations
int<lower=1> D; // number of predictors (p + 1)
int<lower=2> K; // number of alternatives
int<lower=1,upper=K> Y[N]; // response variable
vector[D] X[N]; // design matrix
}
parameters {
matrix[K-1,D] beta_free_raw; // regression coefficeients for K - 1 alternatives
real mu_beta;
real<lower=.001> sigma_beta;
}
transformed parameters {
matrix[K-1,D] beta_free;
matrix[K,D] beta;
beta_free = mu_beta + sigma_beta * beta_free_raw; // re-center parameters
beta = append_row(rep_row_vector(0, D), beta_free); // append row of 0s to top
}
model {
mu_beta ~ normal(0, 5);
sigma_beta ~ cauchy(0, 2.5);
to_vector(beta_free_raw) ~ normal(0, 1);
for (n in 1:N) Y[n] ~ categorical_logit(to_vector(beta * X[n]));
}
```