Ordered_logistic_lpmf

This is due to a bug in the vectorised code (my fault actually!). For that combination of inputs, the derivatives aren’t being calculated properly. There’s more context on the issue here.

This bug has been fixed in the 2.20 release. In the interim, you can also fix this yourself.

First find the ordered_logistic header file with the command:

system.file("include", "stan", "math", "prim", "mat", "prob", 
            "ordered_logistic_lpmf.hpp", 
            package = "StanHeaders")

If you open up that file, on line 139 you’ll see:

        ops_partials.edge2_.partials_vec_[n](0) = d;

Change that to:

        ops_partials.edge2_.partials_vec_[n](0) += d;

i.e., change “=” to “+=”

This code was overwriting the derivatives w.r.t to the vector of cutpoints, rather than accumulating them for each observation. Let me know if that works for you or not

4 Likes