Parameter-dependent constraints

Hi,

I am wondering if it is possible to specify parameter constraints based on other parameters?

Suppose I have

parameters{
    real<lower=0, upper=1> alpha;
    real delta;
}

Is it possible to put a constraint on delta, so that it satisfies alpha + delta is bounded between 0 and 1?

Thanks!

1 Like

This has worked just fine for me.

real<lower = -alpha, upper = 1-alpha> delta;

1 Like

@groceryheist’s answer will work, but I’d usually just use a simplex:

parameters {
  simplex[2] beta;
}
1 Like

Thanks a lot for the answer. I have a follow-up question, would this work for a vector? So if I have
vector<lower = 0, upper = 1>[N] alpha;
Can I define a vector of delta with
vector<lower = -alpha, upper = 1-alpha>[N] delta;
Or should I declare each element in a loop? (Not sure if variable declaration can be done in a loop.)

Thanks!

I’m not exactly sure what you mean, but if you have a set of values that
all sum to a constant you very likely want a simplex.

I do not want the set of values to sum to a fixed constant.

Basically, I wanted to model the difference between alpha and alpha2, such that delta = alpha2 - alpha. Both alpha and alpha2 should be between 0 and 1 (because they are learning rates), hence I wanted to see if I can constrain delta based on alpha and alpha2. I am not modeling alpha and alpha2 seperately, because this is a within subject hierarchical model and I am modeling the difference parameter delta for each individual to be drawn from a group hyperparameter distribution.

You can work out what the constraint should be with basic algebra.

d = a2 - a1 <-> d + a1 = a2 <-> a2 - d = a1

since 0 < a1 < 1,
0 < a2 - d <= 1 <-> a2 - 1 < d < a2'

and since 0 < a2 < 1
0 < d + a1 < 1 <-> -a1 < d <1 + a1

So to satisfy both constraints we have

max(a2-1,-a1) < d < min(a2, 1 + a1)

Not yet, but it’s on our to-do list.

That is not supported and not going to be supported. Scopes are all wrong to do that.

If you need varying upper and lower bounds, you have to do it yourself for now, including the Jacobian adjustment.

Even if you’re ultimately interested in the difference, it is usually easier scientifically to model the individuals individually, then derive quantities like differences in abilities to measure.

If you have parameters alpha and alpha2, then you can just define a transformed parameter delta = alpha2 - alpha.

Is this possible now?..as you have mentioned that its in your to do list…

https://github.com/stan-dev/stan/issues/2656