On 6/26/13 11:02 AM, Brendan wrote:
> ...
> The outcome of interest is at the group level only. However, the approach I used in WinBUGS
> (using from and to index variables, of length J, giving the start and end positions of the subsets of wlp which
> correspond to each group), hasn't worked in Stan.
...
> index <- from[j]:to[j];
> wlp <- mean(i_lp[index]);
...
> Putting aside why on earth I'd want to for a second, is there a way to subset vectors mid-loop like this?
No, there's not. It's another thing on our to-do list, but
even if we build it, it won't be the fastest way to do this in Stan.
In Stan 2.0, we've introduced a way to do it as follows:
wlp <- mean(sub_vector(i_lp,from[j],to[j]));
For now, the only way to do it is with a temporary
variable into which the sub-vector is written:
{
vector[to[j] - from[j]] temp;
for (i in from[j]:to[j])
temp[i - to[j] + 1] <- i_lp[i];
wlp <- mean(temp);
}
You need the brackets to make "temp" a local variable.
- Bob