Thanks Ben, that is really helpful. Usually when I post on these forums, I try to generalize my problem to learn more about how specific things are done (which I did in this case). I think now I am going to pose my *actual* problem and ask for help in figuring out how to better parameterize my model.

I am solving Bayesian subset selection. I have three items: `A, B`

and `C`

. Now, there are 8 possible selections that may be made from these three items:

`-A, -B, -C`

none are selected,

`-A, -B C`

, only `C`

is selected

`-A, B, -C`

`-A, B, C`

`A, -B, -C`

`A, -B, C`

`A, B, -C`

`A, B, C`

, all three are selected.

Now, I want to understand the selection process in terms of the marginal distributions of each item (or pairs):

`p(A), p(B), p(C), p(AB), p(AC), p(BC), p(ABC)`

.

So I can model the outcome above as a multinomial with probability \theta \in \mathbb{R}^8 where \mathrm{sum}(\theta)=1.

Now, each of the above selections can be rewritten in terms of the marginals:

```
theta[1] = (1-pC)-(pB-pBC)-(pA-pAB-(pAC-pABC)); // p(-A,-B,-C)
theta[2] = pC-pAC-(pBC-pABC); // p(-A,-B,C)
theta[3] = pB-pBC-(pAB-pABC); // p(-A,B,-C)
theta[4] = pBC-pABC; // p(-A,B,C)
theta[5] = pA-AB-(pAC-pABC); // p(A,-B,-C)
theta[6] = pAC-pABC; // p(A,-B,C)
theta[7] = pAB-pABC; // p(A,B,-C)
theta[8] = pABC; // p(A,B,C)
```

so note that algebraically, the elements of \theta sum to 1. Now, to constrain each element of \theta to be positive, I can constrain the marginals:

```
real<lower=0,upper=1> pA;
real<lower=0,upper=1> pB;
real<lower=0,upper=1> pC;
real<lower=0,upper=fmin(pA,pB)> pAB;
real<lower=0,upper=fmin(pA,pC)> pAC;
real<lower=0,upper=fmin(pB,pC)> pBC;
real<lower=0,upper=fmin(pAB,fmin(pAC,pBC))> pABC;
```

but these constraints

- wont work with vector valued marginals
- only satisfy
`theta[4], theta[6], theta[7], theta[8]`

being positive.

Eventually, I would like to do beta regression for the marginals, so `pA ~ beta(muA*phiA,(1-muA)*phiA)`

, for `muA = inv_logit (betaA^T x)`

etc. An I would like to learn the `betaA, betaB, ..., betaABC,`

so I need constraints on the marginals to ensure Stan will initialize and run inference.

So looking back at the question you answered, I would like to know how to constrain

`A v + b = theta`

where `theta`

is a simplex, and `v = [pA,pB,pC,pAB,pAC,pAB,pABC]`

, and

`A = [[-1,-1,-1,1,1,1,-1], [0,0,1,0,0,-1,-1,1], [0,1,0,-1,0,-1,1], [0,0,0,0,0,1,-1], [1,0,0,-1,-1,0,1], [0,0,0,0,1,0,-1], [0,0,0,1,0,0,-1], [0,0,0,0,0,0,1], ]`

and `b = [1,0,0,0,0,0,0]`