Constrained Optimization in Rstan

Hello. I am trying to run a constrained optimization in rstan. My model looks something like y ~ B0 + B1X1 + B2X2. I already built a model to find the posterior estimates for B0, B1, and B2. Now I want to find the optimal values of X1 and X2 in order to maximize y (given some constraints on how big or small the X’s can be).

Can someone point me to some example code on how to do this? Much appreciated.



could you perhaps use posterior_linpred() to see at which predictor values y has its maximum value? If you want to propagate the uncertainty perhaps posterior_predict() could be used instead?

1 Like