How to constrain some correlations to 0?

You can try this code Correlation matrix with positively constrained off-diagonals - #3 by spinkney. Don’t put the lower bound on y_raw. And only declare as many non-zero off diagonal elements that you need.

In the transformed parameters block you’d create a new y_raw; where you’d place the zeroes where you want (keeping track of which vector index corresponds to the matrix index in the correlation matrix). Then pass that to matrix[K, K] y = cholesky_corr_constrain_lp(y_raw_new, K);

4 Likes