# Co-occurring mixtures for two parameters

Hello,

I have
x ~ gamma(alpha/(beta+1), beta);
alpha ~ mixture_gamma()
beta ~ mixture_gamma()

``````for(g in 1:(G))	for(p in 1:P) target += log_mix(lambda,
gamma_lpdf(alpha[p,g] | h_a*100, 1/h_b),
gamma_lpdf(alpha[p,g] | h_a*100, 1/h_b)
);

for(g in 1:(G))	for(p in 1:P) target += log_mix(lambda,
gamma_lpdf(beta[p,g] | o_a, 1/o_b*10),
gamma_lpdf(beta[p,g] | o_a, 1/o_b*10)
);
``````

But I would like to force the first distribution of the mixes to CO-occur. Something like

``````for(g in 1:(G))	for(p in 1:P) target += log_mix(lambda,
gamma_lpdf(alpha[p,g] | h_a*100, 1/h_b) + gamma_lpdf(beta[p,g] | o_a, 1/o_b*100),
gamma_lpdf(alpha[p,g] | h_a*100, 1/h_b) + gamma_lpdf(beta[p,g] | o_a, 1/o_b*100)
);
``````

Am I doing something clearly wrong?

Actually the parameter lambda can force the mixture to be coupled already, without the need to merge somehow the statements.

Yes, it’s OK to have two observations (here `alpha[p,g]` and `beta[p,g]`) to be based on the same mixing component. You just think of it as a mixture of a bivariate distribution.

Doing the division and multiplication outside of the loop and saving for reuse will make this all a lot faster. And rather than `1 / x * 10`, I’d recommend the much more efficient `10 / x` (removes a multiplication).

P.S. I find it much easier to read code that follows standard formatting conventions.