1d integration in Stan

Hi there, I am having some issues when doing integration for below code:

vector[] t = {0,50,51,52,53,54};
real WQ_integral(real x,
real xc,
real[] theta,
real[] x_r,
int[] x_i){

       real mu = theta[1];
       real sigma2 = theta[2];
       real lambda = theta[3];
       real alpha = theta[4];
       real t= x_r[2];
       real WQ;
       WQ= 0.3*exp(-((log(x)-mu)^2)/(2*sigma2))/(sqrt(2*pi()*sigma2)*x))*(-lambda*((t-x)^(alpha));

integrate_1d(WQ_integral,left_limit, right_limit,{ mu, sigma2, alpha, lambda }, x_r=t , {}, 1e-8)

Here, I want to find this integral for different t values that means looping over vector t above, with known values for lower and upper limits and for theta

Can someone help me?

transformed data {
  vector[6] t = [0,50,51,52,53,54]';
  vector[6] result;
  for (i in 1:6) {
    result[i] = integrate_1d(WQ_integral, left_limit, right_limit,
                         {mu, sigma2, alpha, lambda}, {t[i]}, {0}, 1e-8)
1 Like

Thanks. Hope it will work for my code. :)