When I try to compile this simple application of integrate_1d
functions{
real[] integrand(real x, // Function argument
real[] f, // Complement of function argument
// on the domain (defined later)
real[] theta, // parameters
real[] x_r, // data (real)
int[] x_i) { // data (integer)
real df_dx[1];
df_dx[1] = exp(-0.5* square(x)) ;
return(df_dx);
}
}
data {
real x;
}
transformed data {
real x_r[0];
int x_i[0];
real theta[0];
}
generated quantities{
real value = integrate_1d(integrand,
negative_infinity(),
x,
theta,
x_r,
x_i);
}
I get this in the Console:
R>rstan:::rstudio_stanc(“mre.stan”)
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in ‘model2db7379c0142_mre’ at line 32, column 33
30: theta,
31: x_r,
32: x_i);
^
33:
PARSER EXPECTED: “,”
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘mre’ due to the above error.
That is not what the manual says should happen but according to this thread https://discourse.mc-stan.org/t/how-to-use-integrate-1d/9218?u=jgcolman the problem is that integrate_1d requires the variable
rel_tol
to be supplied.
So why then if I try to compile this:
functions{
real[] integrand(real x, // Function argument
real[] f, // Complement of function argument
// on the domain (defined later)
real[] theta, // parameters
real[] x_r, // data (real)
int[] x_i) { // data (integer)
real df_dx[1];
df_dx[1] = exp(-0.5* square(x)) ;
return(df_dx);
}
}
data {
real x;
}
transformed data {
real x_r[0];
int x_i[0];
real theta[0];
}
generated quantities{
real value = integrate_1d(integrand,
negative_infinity(),
x,
theta,
x_r,
x_i,
0.01);
}
in which I have supplied
rel_tol
do I get this:
R>rstan:::rstudio_stanc(“mre1.stan”)
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
first argument to integrate_1d must be the name of a function with signature (real, real, real, real, int) : real
error in ‘model2db766a2b5b7_mre1’ at line 33, column 3431: x_r, 32: x_i, 33: 0.01); ^ 34:
PARSER EXPECTED: “)”
Show TracebackRerun with Debug
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘mre1’ due to the above error.
It is probable that there is some silly error here as the example in the post I referred to does work for me.