# Ordered and constrained parameters

Hi,
let’s say I have to parameters a and b that are both ordered and constrained, e.g.:

• a < b
• a,b ∈ (0.1, 0.5)

What would be the best way to implement these restrictions in stan? I’ve tried adding <lower> and <upper> to an ordered vector containing a and b, but that doesn’t seem to be supported.
I’ve considered:

• Implementing the corresponding constraint transform myself in the transformed_parameters block
• Defining a as constrained real and a helper parameter c \in (0,1), then generating b as transformed parameter via b = 0.1 + c \cdot (0.5-a), but that would rather result in a relative difference.

Already solved it using the constraint transform, this resulted in the desired behaviour:

parameters {
ordered[2] a_b;
}
transformed parameters{
real a = 0.1 + 0.4 * inv_logit(a_b[1]);
real b = 0.1 + 0.4 * inv_logit(a_b[2]));
}
model {
a_b ~ normal(0,2);
}

1 Like

Parameter constraints can depend on other previously declared parameters so this is also possible

parameters {
real<lower=0.1,upper=0.5> a;
real<lower=a,upper=0.5> b;
}

2 Likes