I don't have anything else to add on mixing theory,
but you can make the model faster by using sum() instead
of incrementing:
ll <- 0;
for (n in 1:N) {
real eta;
eta <- alpha + X[n] * beta + epsilon[month[n]];
ll <- ll + w0[n] * bernoulli_logit_log(0, eta) + w1[n] * bernoulli_logit_log(1, eta);
}
can be written as
{
reals ll[N];
for (n in 1:N) {
real eta;
eta <- alpha + X[n] * beta + epsilon[month[n]];
lls[n] <- w0[n] * bernoulli_logit_log(0, eta) + w1[n] * bernoulli_logit_log(1, eta);
}
}
ll <- sum(lls);
The brackets are important because they make ll a local variable
so that the entries aren't printed.
It doesn't seem like it'd be faster because of the extra
allocation and assignments, but it cuts down the size
of the expression tree for auto-diff, which is a speed
bottleneck for Stan.
Do you know how much eta varies? It needs to stay roughly
in the -700 to 700 range to not overflow or underflow on
bernoulli_logit_log. That can also cause things to get stuck.
- Bob