Hi everybody,

I have just recently taken my first steps in hierarchical Bayesian modeling with Stan. The forum has been a great source to answer basic questions so far, but now I am facing an issue that I can’t wrap my head around:

I want to code a 3-parameter hierarchical model with nSubjects as random effects and a group level for fixed effects. I also want to account for possible correlations between parameters. Therefore, I adapted a code that I found based on a 2-parameter linear model:

```
data {
int<lower=1> nSubjects;
int<lower=1> nTrials;
matrix<lower=0>[nSubjects, nTrials] x;
matrix<lower=0>[nSubjects, nTrials] y;
}
parameters {
// group-level parameters
real<lower=0> sigma;
real alpha;
real beta;
real gamma;
vector<lower=0>[3] tau_u;
matrix[3, nSubjects] z_u;
cholesky_factor_corr[3] L_u;
}
transformed parameters {
matrix[nSubjects, 3] u;
u = (diag_pre_multiply(tau_u, L_u) * z_u)';
}
model {
// priors
target += cauchy_lpdf(sigma | 0,10) - cauchy_lccdf(0 | 0,10);
target += normal_lpdf(alpha_mu | 0,1000);
target += normal_lpdf(beta_mu | 0,10);
target += normal_lpdf(gamma_mu | 0,10);
target += cauchy_lpdf(tau_u[1] | 0,50) - cauchy_lccdf(0 | 0,50);
target += cauchy_lpdf(tau_u[2] | 0,50) - cauchy_lccdf(0 | 0,50);
target += cauchy_lpdf(tau_u[3] | 0,50) - cauchy_lccdf(0 | 0,50);
target += lkj_corr_cholesky_lpdf(L_u | 2);
target += std_normal_lpdf(to_vector(z_u));
// likelihood
for (s in 1:nSubjects) {
target += normal_lpdf(y[s] | (alpha + u[s, 1]) ./ (x[s] - (beta + u[s, 2])) + (gamma + u[s, 3]), sigma);
}
}
```

The issue I’m having now is, that according to published theory behind the model, parameters should have different bounds, stated as follows:

alpha <lower = 0>

beta <upper = 0>

gamma <lower = 0>

This would account to both, group level and subject level parameters. Setting bounds to the group level parameters shouldn’t be too much of a problem. But how can you apply different truncations to subject level parameters that are sampled from a covariance relationship matrix?

Thank you in advance for any help!