Error evaluating 1D integral for convolution

Hello, I have a problem evaluating an integral. The error is about ill-type arguments for integrate_1d function. I double check with the Stan documentation and some forum discussions, but still, I got the same error.

This is my Stan script:

functions {
    real integrand_fgd(real u, real xc, real[] theta, real[] x_r, int x_i) {
      real mu = theta[1];
      real sigma = theta[2];
      real ti = theta[3];
      real a = (mu/sigma) * (mu/sigma);
      real b = mu/(sigma*sigma);

      real gt = gamma_lpdf(u| a, b) + gamma_lpdf(u-ti| a, b);
      return exp(gt);

data {
  int N;
  vector[N] x;

  // prior parameter
  vector[2] pr_sigma;
  vector[2] pr_mu;

transformed data {
  real x_r[0];
  int x_i[0];

parameters {
  real<lower=0> mu;
  real<lower=0> sigma;

model {
  target += inv_gamma_lpdf(sigma| pr_sigma[1], pr_sigma[2]); //prior of sigma
  target += normal_lpdf(mu| pr_mu[1], pr_mu[2]) - normal_lccdf(0| pr_mu[1], pr_mu[2]); //prior for mu

  for(i in 1:N) {
    real left_limit = x[i];
    target += log(2) + log(integrate_1d(integrand_fgd,
                                        {mu, sigma, left_limit},
                                        x_r, x_i, 1e-8));

Can you post the error message you are getting? It may have additional hints on what part of the arguments is raising this error.

Stan’s integrand type involves several types, so there’s probably many places it could go wrong.

Sure. This is the error I got:

Error in stanc(filename, allow_undefined = TRUE) : 0

Semantic error in 'string', line 33, column 27 to line 37, column 55:

Ill-typed arguments supplied to function 'integrate_1d'. Available signatures: 
((real, real, real[], data real[], data int[]) => real, real, real, real[], data real[], data int[]) => real
((real, real, real[], data real[], data int[]) => real, real, real, real[], data real[], data int[], data real) => real
Instead supplied arguments of incompatible type: (real, real, real[], real[], int) => real, real, real, real[], real[], int[], real.

The error message says the function expects an integrand with type including data real[], data int[] but gets real[], int[]. The documentation on integrate_1d mentions those being “data values” and “integer data” but just say real and int, so that can be confusing.
I remember being puzzled something similar with an ODE solver, but maybe the algebraic solver explains it better.

It also says int is provided when where data int[] is expected, but you are listing int x_i[0], so I’d guess that is not the problem. In any case you should be able to debug the inputs to make sure the type is correct and get it working.