These models are getting complicated!
Comment 1: Don't use tabs; you can see the kind of trouble they
cause by viewing lines 51 and 53 of your code on GitHub. If you
use emacs, you can set it up to get rid of tabs automatically (untabify
or you can use the elisp config we give from our developer tools wiki
page on stan-dev/stan). Emacs has a Stan mode (downloadable from stan-dev)!
Comment 2: Probit is suboptimal compared to logit computationally in
Stan because Phi() is so much harder to compute than inv_logit.
The reverse was true in BUGS/JAGS, I think.
Comment 3: This is suboptimal because the max and min will cut the relation
to the gradients:
dummy[d] <- exp(fmax(fmin(Ev[d] * theta, 450), -450));
Instead, you should use the built-in softmax function, or even better,
just use the softmax-parameterized categorical distribution, which cuts
choice[s, t + 1] ~ categorical_softmax(Ev);
Comment 4: I wouldn't put the lp_parts in transformed parameters unless
you need to save them for some reason. There's a two-argument log_sum_exp
that you can use directly. What we really need are some mixture functions
to make this all easier.
Comment 5: I still think it's easier to just work in expectation
than sample bernoulli data from a known probability only to estimate
that probabilty. The Rao-Blackwell theorem tells you this in theory, but
you can also see it in practice because there's sampling error in estimating
by sampling, whereas there's none in just using the expectation. But if you
really need the samples for some reason, then what you're doing is the right
way to get them.
Comment 6: Use vector-based distributions wherever possible, even at the cost
of some data manipulation. So this (mangled by tabs!):
for (i in 1:4) {
# Prior on the group-level mean parameters
# probit scale [-Inf, Inf]
mu_pr[i] ~ normal(0, 1);
# Individual-level paramters
for (s in 1:n_s_1) {
# Group 1
ind_pr[i,s] ~ normal(mu_pr[i,1], std[i,1]);
}
# Group 2
increment_log_prob(log_sum_exp(lp_parts[i]));
}
should be
for (i in 1:4)
mu_pr[i] ~ normal(0,1);
for (i in 1:4)
ind_pr[i] ~ normal(mu_pr[i,1], std[i,1]);
for (i in 1:4)
increment_log_prob(log_sum_exp(lp_parts[i]));
You can put them all in the same loop, but it's usually
clearer with a loop per variable (and just as fast, if
not faster in the case of long arrays).
To answer your questions.
1) Yes, this looks right for the mixture.
2) See above --- the move to categorical_softmax should be a big boost.
3) The usual approach in a mixture model is to estimate the mixing proportion
lambda constrained to [0,1]. You can also set it if you know it ahead of time,
or you can take the in-between route and give it an informative prior.
4) Yes, they're interchangeable, but see above on exp(). Any time you find yourself
using exp() on scalars or inverse() on matrices, you want to step back and
reformulate wherever possible for better arithmetic stability. But the + version
may be faster because the vector-based sum() isn't saving you anything with
only two operands.
- Bob
> --
> 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.
> For more options, visit
https://groups.google.com/d/optout.