Cannot use a (new) function for a rstantools based package

When I try to start building a package with rstantools (using rstan_create_package) that uses the function ordered_logistic_glm_lpmf I get the error:

No matches for: 
  ordered_logistic_glm_lpmf(int[ ], vector, matrix, vector)
Function ordered_logistic_glm_lpmf not found.

even though I can compile the same model that includes ordered_logistic_glm_lpmf when I try to compile it directly with stan_models. (I used install_StanHeaders to install the Stan/math version that includes the function)

Does anybody have an idea what the problem could be?
(tagging @bgoodri, @jonah)

Thanks in advance, Guido

PS: RStudio also dose not recognize the function in the .stan file

1 Like

That function might not be in the Stan language, which hasn’t been updated on the C++ side as we are switching to OCaml. If so, then you would need to declare ordered_logistic_glm_lpmf as a “user-defined” C++ function in the functions block and then the definition should already be #included through Stan Math.

2 Likes

That is correct, the ordered_logistic_glm_lpmf was only implemented in stanc3 and not in stanc2.

1 Like

Not sure if I understood this correctly, but I just added the following to the top of the .stan file:

functions {
  real ordered_logistic_glm_lpmf(int[] Y, matrix X, vector b, vector cuts);
}

Wit this the compilation at least starts, but it then aborts with another error due to the ordered_logistic_glm_lpmf function:

Eigen::Matrix<T_job_param, -1, 1>&, std::ostream*)
    ordered_logistic_glm_lpmf(const std::vector<int>& Y,
    ^
   stanExports_spolr.h:41:1: note:   template argument deduction/substitution failed:
   In file included from stanExports_spolr.cc:5:0:
   stanExports_spolr.h:243:83: note:   couldn't deduce template parameter 'propto'
                lp_accum__.add(ordered_logistic_glm_lpmf(Y, X, b, Intercept, pstream__));
                                                                                      ^
   make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:213: stanExports_spolr.o] Error 1
   ERROR: compilation failed for package 'spolr'

Does this look like this is something easy to fix, or is it better to wait until rstan also uses OCaml?

1 Like

It seems that ordered_logistic_glm_lpmf is also missing from the Stan documentation.

Can you say of the speed improvement of ordered_logistic_glm_lpmf over ordered_logistic_lpmf is meaningfull (lets say > 10% for a design matrix with 150 columns and 5000 rows)

Yeah, its only documented in the math library, sorry for that. For the speed question I am tagging @tadej as he added this GLM in Stan Math and would probably know best.

At that size you can expect glm function to be several (~10) times faster.

2 Likes