Thanks a lot, mathDR! It worked well and the reading was also very useful.

There are actually contemporaneous covariances between the 2. I tried to modify the code to make it work but failed and the link you gave didn’t talk about this. Would you mind taking another look?:)

Here’s my modified code:

```
parameters {
cholesky_factor_corr[2] Lcorr;
matrix[N,2] prior_mu;
vector<lower=0>[2] prior_scale;
matrix[N,2] Z;
}
transformed parameters {
matrix[N,2] sigma = prior_mu + diag_pre_multiply(prior_scale, Lcorr)*Z;
}
model {
Z ~ std_normal();
prior_scale ~ std_normal();
Lcorr ~ lkj_corr_cholesky(2.0);
y1[n] ~ normal(mu1[n], sigma[n,1]);
y2[n] ~ normal(mu2[n], sigma[n,2]);
}
```

##
Duplicate declaration of variable, name=error; attempt to redeclare as matrix in transformed parameter; previously declared as matrix in parameter

error in ‘model14ae1914545_2ef64b1018424bfaa8c4b0cbcd92eefb’ at line 18, column 72

##
16:

17: transformed parameters {

18: matrix[N,2] error = prior_mu + diag_pre_multiply(prior_scale, Lcorr)*Z;

^

19: }

Error in stanc(file = file, model_code = model_code, model_name = model_name, :

failed to parse Stan model ‘2ef64b1018424bfaa8c4b0cbcd92eefb’ due to the above error.