I have defined a custom probability distribution (lpdf) in the functions-block. Within the definition of the lpdf, I use a call to the function “integrate_1d” – which serves the purpose of integrating another function defined in the same functions block. More specifically: In defining the lpdf, I need to integrate a function of the type exp(spline), where spline is a b-spline. The signature of the function, I need to integrate is:
real exp_spline(real x, real xc, real theta, real x_r, int x_i).
Within the lpdf with signature
real exspl_lpdf(real y, real theta, real coeff, real ext_knots)
I call the function via:
integrate_1d(exp_spline, ext_knots, y, theta, ext_knots, x_i, 1e-4);
Note that the argument “ext_knots” defines the (extended) knots of a b-spline. These are meant to be supplied by the user via setting appropriate data.
When compiling my program I first got the error message:
“the 5th argument must be data-only. (Local variables are assumed to depend
on parameters; same goes for function inputs unless they are marked with
the keyword ‘data’.)”
(in my case the fifth argument refers to the knots of the spline)
After adding the keyword “data” in front of the argument, the error message disappeared.
real exspl_lpdf(real y, real theta, real coeff, data real ext_knots);
However, my (first) question is:
If I mark an argument as data, does Stan still check that I call the function appropriately?
That is, if I mark an argument as data and violate this agreement later in the program (by calling it with something not defined as data), will I get an error message? Further, it seems that adding “data” in front of the function parameter is the only way to fulfill the requirement, because I cannot use data in the functions block – as the data block is defined after the functions block. Is this correct?
Now with this added “data” in front of the parameter the model compiles – but there is no sampling output.
Error messages now seem to indicate some problem in evaluating the integral and I wonder, if it is a numerical issue or if there still is something wrong with the definition and usage:
“error estimate of integral above zero 5.3119e-06 exceeds the given relative tolerance times norm of integral above zero”
Thank you very much for suggestions and help!