Yes, I would like to use the function log_modified_bessel_first_kind in a Stan model. I haven’t build the actual model yet, but just tried whether I can manage to use the function at all, so I’ve tried the following in R:

mc <-
'
functions { real log_modified_bessel_first_kind(real y, real z); }
model {} // use the log_modified_bessel_first_kind() function somehow
generated quantities {
real bessel_value;
bessel_value = log_modified_bessel_first_kind(1.5, 3.5);
}
'
stan_model_object <-
stan_model(model_code = mc, model_name = "external", allow_undefined = TRUE,
includes = paste0('\n#include "', file.path('/usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/scal/fun/log_modified_bessel_first_kind.hpp'), '"\n'))

which returns the error that I posted in my previous comment.

Alright I think the thing is you gotta write a little wrapper function. The signature generated by stanc3 includes a std::ostream* argument which the Math library function doesn’t have.

So drop this in a file called ‘interface.hpp’ in your working directory:

library(rstan)
mc <- 'functions { real log_modified_bessel_first_kind(real y, real z); }
model {} // use the log_modified_bessel_first_kind() function somehow
generated quantities {
real bessel_value;
bessel_value = log_modified_bessel_first_kind(1.5, 3.5);
}'
stan_model_object <- stan_model(model_code = mc, model_name = "external", allow_undefined = TRUE, verbose = TRUE,
includes = paste0('\n#include "', getwd(), '/interface.hpp"\n'))