I am trying to do cross-validation within my stan model. I haven’t found any method to do that on its own (rstanarm has it, but I rather want to have it in the model itself) - is there anything else?
The first question is about indexing. In Stan I can use
intarrays for indexing like
yis what I want to subset with the indices in the integer array
idx1. But can I somehow exclude certain indices? In R this would be
y[ -(idx1)], but this doesn’t work in Stan. Or can I index with a condition? Again in R, this would be
y[idx[i] == 2]or
y[idx[i] != 3].
My second questions is about tilde assignments: Can I use one element multiple times on the left side of a tilde? In cross validation I would have to use y for training every group of parameters except the one that the first observation is in itself, so
If multiple assignments are not possible, my first workaround idea was to replicate the data
yso that I have a 2-dimensional array and then I would not assign
ymultiple times but rather use
y[1, 1], then
y[2, 1], …,