Hi,
I am trying to fit a 4-component mixture model where the probability of component membership of each sample (pi) is estimated in a separate stan fit. I am using dirichlet to introduce uncertainty but getting many of “Exception thrown at line 20: dirichlet_log: probabilities is not a valid simplex. sum(probabilities) = nan, but should be 1”. I am using the first component to capture samples whose n is zero. Where do you think I am getting nan? Any comment would be greatly appreciated.
data {
int<lower=1> N;
int<lower=0> n[N];
vector<lower=0,upper=1>[4] pi[N];
}
parameters {
real<lower=0,upper=1> a4;
real<upper=max(n)> a5;
real<lower=1> b5;
real<upper=max(n)> a6;
real<lower=1> b6;
real<upper=max(n)> a7;
real<lower=1> b7;
}
model {
for (i in 1:N) {
vector[4] lps;
vector[4] tau;
tau ~ dirichlet(pi[i]);
lps[1] = tau[1] * exp(neg_binomial_2_lpmf(n[i]|a4, 1));
lps[2] = tau[2] * exp(neg_binomial_2_lpmf(n[i]|a5, b5));
lps[3] = tau[3] * exp(neg_binomial_2_lpmf(n[i]|a6, b6));
lps[4] = tau[4] * exp(neg_binomial_2_lpmf(n[i]|a7, b7));
target += log(sum(lps));
}
}