Hi, I found on the Stan manual, the code to implemente the following model:
I would like to instead implement a mixture model of K distributions, where not all observations come from all K distributions. Let’s say that the distributions represent K features of y, but none of the y's are observed with all of them, but I still want to extrapolate the pooled evidence.
Let’s say that I have a matrix P, such that P_{i,j} = 1 if y_i has feature j and P_{i,j} =0 otherwise, I would like to estimate the following model:
So I give weight 0 to the feature’s distribution if it is not present for y_n and renormalize the weights to sum to 1. I tried the following code, but it does not work, I suspect it is just my poor coding.
model {
for (n in 1:N) {
real C = col(P,n)' * lambda; // normalizing constant
vector[K] lps;
for (k in 1:K){
lps[k] = log((lambda[k]*P[k,n])/C);
lps[k] += normal_lpdf(y[n] | mu[k], sigma);
}
target += log_sum_exp(lps);
}
Is there a way to implement this on Stan? Or do you suggest any other modelling alternatives?
Thanks in advance for the help.