How to utilize "masked arrays" in map_rect?

When converting my model to a map_rect formulation, I am wondering how to tell the likelihood not to fit certain elements of the input data. In particular, I was going to elementwise multiply the data with a boolean (0-1 matrix in stan) matrix to tell the likelihood to not include those elements in the parameter fit.

Currently, I am doing a for loop over the data and I have an if statement that skips the data point if it corresponds to a 0 in the boolean matrix.

How can I replicate this in the map_rec formulation? Do I need to incorporate this if functionality in the function passed into map_rect?

Thanks

Dan

Yes, this will have to be in the function passed to map_rect.

One way you can subset an array y in Stan is to use y[idxs] where idxs is a 1D array of integers for the indexes to keep. Then

y[idxs] ~ foo(theta)

which will be equivalent to the loop form:

for (n in 1:size(idxs))
  y[idxs[n]] ~ foo(theta);

or the even less efficient version where you pass in an array of booleans:

for (n in 1:size(y))
  if (include[n]) 
    y[n] ~ foo(theta);

There’s no way yet to select members from an array of booleans, but we need to add that.

Okay! I think I will do the (less efficient) idea first to make sure it matches.

Really appreciated!

Dan