Set different bounds for each element in a parameter array

I have alpha[S] where S = 3. Each has different bounds. I can not declare alpha[1] [2] and [3] separately in parameter block. Is there another way to set separate bounds for each element?

Do real<lower=0,upper=1> alpha_raw[S] in parameters. Map the three elements of alpha_raw into alpha in the transformed parameters block. Figure out the Jacobian correction if you are placing a prior on alpha.

Wait. I am not getting the whole picture. I declared real alpha in transformed block, then how do I specify different bounds when I map alpha into alpha_raw? alpha[1] = alpha_raw[1] doesn’t allow me to set bounds.

alpha[1] = g(alpha_raw[1]) where g() is some function (or maybe just an expression) that enforces the bounds.

What I am currently doing in my own models, where I want one of the parameters to be bounded between 0 and an individual bound for each element, is to make use of the inverse-logit function. If multiplied by the upper boundary value, this will transform the data/parameter values to be bounded between 0 and the multiplied value:

As @bgoodri said, setting up the Jacobian should also work, however, I don’t now how to do it.

Here is an example from how I do it. Might not be the most correct way but hope it helps.

data {
int N; // number of measurements
real y[N]; // individual measurements
}

transformed data {
real upper_lim[N];
upper_lim = y; // vector of upper limits
}

parameters {
vector[N] tauU; // unconstrained target parameter 
}

transformed parameters {
vector[N] tau; // bounded target parameter

for(n in 1:N){
   tau[n] = inv_logit(tauU[n]) * upper_lim[n]; 
   }
}

mode l{
tauU  ~ normal(0,1); // unconstrained prior

y ~ normal(0, tau);

}

There’s an explanation in the manual in the section titled “Vectors with Varying Bounds”.

1 Like