Nono, I think the code you wrote improves the situation a lot, but let me clarify my other question about it.
So we have a parameter u_{i, j}.
Some elements of u_{i, j} are not used, so we want to not sample them in our Stan programs.
One thing we can do is flatten this matrix to a vector, v_{k(i, j)} = u_{i, j} where k(i, j) indexes all the non-NA values of u_{i, j} (so v only has one index).
Another thing we can do is ragged arrays r_{i, k_i(j)} = u_{i,j} where k_i(j) is a per-row mapping of the K_i non-NA indices j to a sequence of numbers 1, ..., K_i (take all the non-NAs in a row and squish them into a list).
So I see how the second remapping (ragged arrays) is simpler than the first (flattening to a vector).
It still seems like the more convenient thing though would be if you could just define u_{i, j} in a way that turned off all the elements that weren’t being used. That way there is no remapping at all. If you index’d a value of u_{i, j} that was turned off, maybe there could be an error.
This is I think is where this post started – the idea there was just put normal(0, 1)
priors on the unused parameters and ignore them.
Does that make sense? The ragged remapping is simpler cause you’re just flattening one index, but if it were possible to just index the original, big, multidimensional thing with some elements turned off that would be nice too.