# Bounds depending on parameter. Error "lub_constrain: lb is ..."

I’m trying to optimize a hierarchical model that requires some parameters to be bounded at lower=0.5, upper=1.
It runs with a centered cholesky factored parametrization, but the participant-level effects are highly correlated, it samples slowly, and I have lots of divergences.
So I thought I’d try a non-centered parametrization, but I’ve run into a weird error when trying to specify the bounds of the participant-level effects as a function of the main effect.
I’ve managed to isolate the error and create a minimal example (included below).
In this example, the error sometimes doesn’t happen if I don’t specify init=0 (and sometimes it still happens but with different “lb is…” numbers), but it always happens with the real model.
I tried searching around, but didn’t find any mentions of this error message, and I don’t have a clue what’s going on.

stan

``````data{
int<lower=1> N;
int<lower=1> P;
int<lower=1, upper=P> participant[N];
}

parameters{
real<lower=0.5, upper=1> muA;
vector<lower=muA-.5, upper=1-muA>[P] a;
}

transformed parameters {
vector<lower=0.5, upper=1>[N] total_A;
total_A = (muA + a[participant]);
}

model{
muA ~ normal(0, 1);
a ~ normal(0, 1);
}
``````

R

``````library(rstan)

data = list(
N = 10,
P = 5,
participant = c(1:5, 1:5)
)

debug_model <- stan(
file = "stan_debug_lub.stan",
data = data,
iter = 1e5, chains = 1, cores = 1, init=0
)
``````

The error

`````` "Error in sampler\$call_sampler(args_list[[i]]) : "
 "  lub_constrain: lb is 0.25, but must be less than 0.25"
``````

Thanks,

If `muA` is 0.75, then the upper and lower bounds of `a` are 0.25. If `muA` is greater than 0.75, then the lower bound of `a` is less than the upper bound.

Hopefully that’s it!

1 Like

Yes, thank you. I stared at it until I got blinded and convinced myself I’d done the number-juggling right so I must be having some kind of strange bug.

``````vector<lower=.5-muA, upper=1-muA>[P] a;
``````

Worked as it should.

1 Like