# Defining different bounds for each element of a matrix of parameters

\beta is a matrix of regression coefficient of dimension N\times K where N is the number of outcomes and K the number of covariates (so that \beta \cdot x, where x is the vector of covariates of length K, gives a vector of length N). Some coefficients in the matrix \beta are constrained according to other coefficients and I would like to find a way to declare these constraints directly with the matrix \beta, and not one by one, as both N and K are high.
As a simple example, let’s consider N=2, K=3 and the following constraints in \beta:=(\beta_{i,j})_{i\leq N,j\leq K}:
\beta_{1,1}>\beta_{1,2}
\beta_{1,1}>\beta_{1,3}
\beta_{2,3}<\beta_{2,1}
\beta_{2,3}<\beta_{2,2}

One way to write them would be to use real variables for each of the 6 entries:

parameters {
real beta_11;
real <upper = beta_11> beta_12;
real <upper = beta_11> beta_13;
real beta_23;
real <lower = beta_23> beta_21;
real <lower = beta_23> beta_22;
}


However, as N and K are large, it would be better to declare \beta as a matrix. However, I’m not sure whether it is possible to assign some constraint/bound for each element of the matrix. Coming back to my example, I would like to do something like:

parameters {
real beta[N,K];
for(i in 1:N){
for(j in 1:K){
//define lower and upper bound for coefficient beta[i,j]
}
}
}


Could anyone think of such way of defining bounds or should the definition of bounds necessarily be at the same place as variable declaration?

No; you have to write them out as scalars in this case.