Inequality constraint on sum of parameters via transformed parameters block?

234 views
Skip to first unread message

Julian King

unread,
Oct 14, 2015, 7:15:47 PM10/14/15
to Stan users mailing list
Hi everyone,

Suppose that I have a block of parameters:
vector[k] beta;
and a set of regressors
vector[k] X;

I want to calculate the derived quantity:
Y <- beta*X;

Is it possible to enforce an inequality constraint such that eg y <= 0?

Perhaps via the transformed parameters block, ie define
real<upper=0> Y;

Thanks!

Ben Goodrich

unread,
Oct 14, 2015, 10:44:19 PM10/14/15
to Stan users mailing list

That is valid syntax but will lead to horrible sampling in Stan and in more complicated cases, your prior on the parameters does not integrate to a constant. A better way to do it is to separate the intercept out of beta (and delete the column of ones from X). Then put a bound on the intercept such that the inequality constraint is satisfied. Like this:

parameters {
  vector
[K] beta;
  real
<upper = -max(X * beta)> intercept;
}

We have done something a bit like that for a few models and there is still considerable, non-constant dependence between the elements of beta and the intercept. But at least it is a contiguous parameter space.

Ben

Bob Carpenter

unread,
Oct 14, 2015, 11:50:14 PM10/14/15
to stan-...@googlegroups.com
That's very elegant --- like the sum to 0 constraint,
only more subtle.

I would like to warn you that this will ensure the constraint
is satisfied for any X in the data you use to fit the model, but
it won't necessarily satisfy the constraint out of sample.
You will need to look deeper into where the constraint comes from for that.

Alternatively, use exp(beta * X) instead of (beta * X) --- that's
guaranteed to be positive. It's what you usually see in things like
Poisson GLMs that require positive linear predictors.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Julian King

unread,
Oct 15, 2015, 3:00:30 AM10/15/15
to Stan users mailing list
Bob and Ben,

Thanks for the suggestions.

I have used the simple example above to try to explain the problem, but unfortunately my actual model is rather more horrible in how the constraint is imposed (which makes it much more difficult to satisfy).

If you imagine I have y = f({beta_X,beta_Z}, {X,Z}), my constraint requires that y(X+dX,Z) - y(X) < 0, ie the constraint relates to a complex derivative function.

Thanks for your thoughts anyway - it may be difficult for me to enforce the constraint.

Ben Goodrich

unread,
Oct 15, 2015, 10:11:22 AM10/15/15
to Stan users mailing list
On Thursday, October 15, 2015 at 3:00:30 AM UTC-4, Julian King wrote:
I have used the simple example above to try to explain the problem, but unfortunately my actual model is rather more horrible in how the constraint is imposed (which makes it much more difficult to satisfy).

If you imagine I have y = f({beta_X,beta_Z}, {X,Z}), my constraint requires that y(X+dX,Z) - y(X) < 0, ie the constraint relates to a complex derivative function.

Thanks for your thoughts anyway - it may be difficult for me to enforce the constraint.

You basically have to set up the parameters block such that the inequality constraint is satisfied by construction, rather than relying on the fact that Stan will reject proposals for the parameters that happen to not satisfy the inequality constraint. I would try to basically do the same approach:
  1. Solve for the value of some scalar parameter that renders y(X+dX,Z) - y(X) <= 0 for all observations with equality for one observation
  2. Use that value for an upper or lower bound on that scalar parameter in the parameters block so that y(X+dX,Z) - y(X) < 0 for all observations

You may have to write a function in the functions block that implements (1) because you can't define any intermediate quantities in the parameters block.


Ben

Reply all
Reply to author
Forward
0 new messages