Thanks! May I suggest replacing this:
for(k in 1:m[i]) {
if(k == 1) {
kappa[pos_kappa[i]] <- mu[i];
}
if(k > 1) {
kappa[pos_kappa[i]+k-1] <- kappa[pos_kappa[i]+k-2] +
delta[pos_delta[i]+k-2];
}
}
with
if (m[i] > 0)
kapa[pos_kappa[i]] <- mu[i];
for (k in 2:m[i])
kappa[pos_kappa[i]+k-1]
<- kappa[pos_kappa[i]+k-2] + delta[pos_delta[i]+k-2];
It's almost always a good idea to reduce nesting (from 2-deep to
1-deep here) when possible. And if you know that m[i] > 0, then
you can drop the conditional (there isn't a constraint to that effect
in the transformed data variable declaration, but there should probably
at least be a lower=0)
I thought these
segment(kappa, pos_kappa[ii[n]], m[ii[n]]))
would get phased out in favor of the R/MATLAB style, but this
is really unreadable:
kappa[pos_kappa[ii[n]]:(pos_kappa[ii[n]] + m[ii[n]])]
so would require a different computation for m as end-position
rather than size.
- Bob
> <graded_response.stan>