Ode_bdf solver of a vector function

Hi all,

I am trying to solve this code. When I run it I get the error message written below. However, the only way to solve the function is by adding vector[] model3 and not vector model3 as the program is suggesting to do, also it says that I should add an int value where I did not define prior any int, and all my values are real type, any idea why this?
I have also tried to change my parameters of the function as reals and change the vector type equations to reals as well but I still get the same error message.
Semantic error in ‘string’, line 40, column 25 to column 72:

Ill-typed arguments supplied to function ‘ode_bdf_tol’. Expected arguments:
(real, vector) => vector, vector, real, real[], real, real, int
Instead supplied arguments of incompatible type:
(real, vector, vector, vector, vector) => vector[], vector, real, real[], real, real, real

functions {
  vector[] model3(real t, vector y, vector pAB, 
  vector uAB, vector uASC) {
    vector[rows(y)] dAB_dt = pAB*y[2]-uAB*y[1];
    vector[rows(y)] dASC_dt = -uASC*y[2];
    vector[rows(y)] out[2];
    out = {dAB_dt, dASC_dt};
   return (out);
data {
  int <lower=1> nobs;
  real t0;
  vector[2] y0;
  array[nobs] real ts;
  int <lower=1> indivs;
  array[nobs] real antib;
  real <lower=1, upper=indivs> subj[nobs];
parameters {
  //real <lower=0> AB0;
  row_vector[1] pAB0;
  row_vector[1] uAB0;
  row_vector[1] uASC0;
  //real <lower=0> sigmaAB0;
  real <lower=0> sigma;
  vector[indivs] rpAB;
  vector[indivs] ruAB;
  vector[indivs] ruASC;
transformed parameters {
  real <lower=0> pAB;
  pAB = pAB0*rpAB;
  real <lower=0> uAB;
  uAB = uAB0*ruAB;
  real <lower=0> uASC;
  uASC = uASC0*ruASC;
  vector[nobs] yhat[2] = ode_bdf_tol(model3, y0, t0, ts, pAB, uAB, uASC);
model {
  rpAB ~ lognormal(-2, sqrt(4));
  ruAB ~ lognormal(-1, sqrt(2));
  ruASC ~ lognormal(-0.1, 0.44);
  //AB0 ~ lognormal(-2, 4);
  //sigmaAB0 ~ gamma(0.001, 0.001);
  sigma ~ normal(0, 1);
  //for (i in 1:nobs) {
    //antib[i] ~ lognormal(yhat[i,1], sigma); 
  antib ~ lognormal(log(yhat[ : , 2]), sigma);
generated quantities {
  array[nobs] real z_pred;
  for (j in 1:nobs) {
    z_pred[j] = lognormal_rng(log(yhat[j,2]), sigma); 


model3 should only be returning a vector but out is an array of vectors. The ODE is supposed to be 2D right? Why are the parameters declared as vectors? If I’m understanding correctly, it might make more sense to write the function like the guideline here:

vector[] model3(real t, vector y, real pAB, 
  real uAB, real uASC) {
    real dAB_dt = pAB*y[2]-uAB*y[1];
    real dASC_dt = -uASC*y[2];
    vector[rows(y)] out = [dAB_dt, dASC_dt]';

   return (out);

Thanks for the reply. I will try this code. However, the parameters were defined as vectors since later on I needed to transform them (see in transformed parameters). Hence, if I would define this in the function as reals it would not allow me to transform them later and call the transformed parameters into the ode solver?

Unfortunately this did not work; There is an error statement indicating that line 2 (vector [] model3), should be the same type as the return statement, indicating that out and model3 are not the same type.

Semantic error in ‘string’, line 2, column 2 to line 9, column 3:

Function bodies must contain a return statement of correct type in every branch.

And otherwise, if I keep the parameters as reals but I do change the response of the ODEs as vectors, I would get the following error:

Semantic error in ‘string’, line 5, column 4 to column 47:

Ill-typed arguments supplied to assignment operator =: lhs has type vector and rhs has type real