Co-occurring mixtures for two parameters

techniques

#1

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[1]),
	gamma_lpdf(alpha[p,g] | h_a*100, 1/h_b[2])
);

for(g in 1:(G))	for(p in 1:P) target += log_mix(lambda,
	gamma_lpdf(beta[p,g] | o_a, 1/o_b[1]*10),
	gamma_lpdf(beta[p,g] | o_a, 1/o_b[2]*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[1]*100, 1/h_b[1]) + gamma_lpdf(beta[p,g] | o_a, 1/o_b[1]*100),
	gamma_lpdf(alpha[p,g] | h_a[2]*100, 1/h_b[2]) + gamma_lpdf(beta[p,g] | o_a, 1/o_b[2]*100)
);

Am I doing something clearly wrong?


#2

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


#3

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.