Mixtures can be hard to fit, but that one has enough data
and is well separated enough.
The problem you're likely running into is running with the default four
chains. With mixtures, there's an index-swapping problem. See
the chapter on problematic posteriors.
If you fit with one chain, the fit looks OK:
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
theta[1] 0.27 0.00 0.04 0.20 0.24 0.27 0.30 0.34 656 1
theta[2] 0.50 0.00 0.03 0.43 0.48 0.50 0.52 0.56 1000 1
theta[3] 0.23 0.00 0.04 0.17 0.21 0.23 0.26 0.31 629 1
mu[1] 8.70 0.01 0.17 8.37 8.59 8.70 8.81 9.02 528 1
mu[2] 0.00 0.00 0.10 -0.21 -0.07 0.00 0.06 0.19 526 1
mu[3] 5.90 0.01 0.19 5.51 5.77 5.91 6.04 6.28 616 1
lp__ -477.71 0.08 1.50 -481.62 -478.55 -477.38 -476.57 -475.76 393 1
mu[1] just squeaked into the 97.5% interval, but everything else was in its
50% interval.
- Bob
P.S. You want to define log_theta as a temp and reuse rather than computing
log(theta) N times.
...
model {
real log_ps[K];
vector[K] log_theta;
log_theta <- log(theta);
mu ~ normal(0, 50);
for (n in 1:N) {
for (k in 1:K)
log_ps[k] <- log_theta[k] + normal_log(y[n], mu[k], 1);
increment_log_prob(log_sum_exp(log_ps));
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.
> To post to this group, send email to
stan-...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.