Hey guys,

I know that the Stan’s User Guide Section 1.13 Multivariate Priors for Hierarchical Models follows this syntax (`brms`

/ `lme4`

style): `y ~ 0 + (1 + x_1 + x_2 + ... | J)`

. So we have a varying-slope-intercept model without fixed (population-level) effects(slopes/intercepts). According to the manual this translates to the following stan model:

```
data {
int<lower=0> N; // num individuals
int<lower=1> K; // num ind predictors
int<lower=1> J; // num groups
int<lower=1> L; // num group predictors
int<lower=1,upper=J> jj[N]; // group for individual
matrix[N, K] x; // individual predictors
matrix[L, J] u; // group predictors transposed
vector[N] y; // outcomes
}
parameters {
matrix[K, J] z;
cholesky_factor_corr[K] L_Omega;
vector<lower=0,upper=pi()/2>[K] tau_unif; // prior scale
matrix[K, L] gamma; // group coeffs
real<lower=0> sigma; // prediction error scale
}
transformed parameters {
vector<lower=0>[K] tau = 2.5 * tan(tau_unif);
matrix[K, J] beta = gamma * u + diag_pre_multiply(tau, L_Omega) * z;
}
model {
vector[N] mu;
for(n in 1:N) {
mu[n] = x[n, ] * beta[, jj[n]];
}
to_vector(z) ~ std_normal();
L_Omega ~ lkj_corr_cholesky(2);
to_vector(gamma) ~ normal(0, 5);
y ~ normal(mu, sigma);
}
```

How would I code in Stan the same model, *but* including intercept and slopes for population (fixed effects also)? This would be the following syntax (`brms`

/ `lme4`

style): `y ~ 1 + x_1 + x_2 + x_3 ... + (1 + x_1 + x_2 + ... | J)`

.

I’ve been bashing my head against the wall trying to do this but any help would be most appreciated. (`bmrs`

code didn’t help it makes a `Z_1_1`

, `Z_1_2`

etc…)