Okay, I figured out the issue.
Following this tutorial, the number of trials for the full dataset is passed via stanvar
:
stanvars <- stanvar(scode = stan_funs, block = "functions") +
stanvar(as.integer(cbpp$size), name = "trials")
The issue seems to occur because loo
tries to exclude the high-k observations but is still using the original trials
data, which results in a mismatch between counts and trials, where some of the former are larger than the latter.
So I suppose the question now is how to allow loo
and stanvar
to work together to pass the appropriate subsets of data into the model.