Inequality between ordered array and a scalar

Here is a quickie (?!) but I’ve no luck from Google, this forum search, nor chatGPT.

In generated quantities I need to find the first index of an array where an inequality is met. Why can’t I do

 ordered[K-1] cH;   // cut points
 real etaS;             // x beta plus logistic draw
 int response;      // prediction from K possible responses

response = sum( etaS> cH );

The above gives an error like

Ill-typed arguments supplied to infix operator >. Available signatures: 
(int, int) => int
(int, real) => int
(real, int) => int
(real, real) => int

which maybe is fully self explanatory: there are no inequality operators defined between anything except scalars?

If the answer is stupidly simple, can you also mention how I should have found the answer in the docs? I looked in function reference manual (typing, cast, convert, etc, and looked through the real type functions for a real(), etc ) and Reference manual (inequality, <, etc) for anything on comparing scalars to a vector and on treating an ordered like a real.

Thank you!

I would say there isn’t a function to do that, and since the objects are just scalar/vector/matrix types they won’t have any methods/attributes that would yield that either. However, that may be because I tend to think of that kind of operation in the processing of the data, not the modeling, and Stan is mainly dedicated to the latter. So I may be wrong.

I did a quick search here and could find a somewhat old thread with a related question where the answer is “no”. So the solution would probably be to loop over the array and check for the condition on each element.

1 Like