Rstan 2.21.8 array error

I am using RStan 2.21.8 and am getting an error when using arrays. Some of the stan code is shown below:


When including Stan code in your post it really helps if you make it as readable as possible by using Stan code chunks (```stan) with clear spacing and indentation. For example, use

   vector f(vector y, vector theta, real[] x_r, int[] x_i){
    vector[1] bmd;
    real er;
    real bmr;
    real beta1;
    real beta2;
    real beta3;
    real tval;

    tval = y[1];
    bmr = 0.1;

    beta1 = theta[1];
    beta2 = theta[2];
    beta3 = theta[3];
    
    er = er3p(tval, beta1, beta2, beta3);

    bmd[1] = bmr - er;
    return bmd;
  }  
} 

transformed data {
   // Necessary for algebra_solver
   array[0] real x_r;
   array[0] int x_i;
   vector[1]  bmd_guess = [0.01]';

   real sdose[N_gps]; 
   
   for (i in 1:N_gps) sdose[i] = dose[i]/scaling_dose;
   
}

I am getting an error that says “Variable array does not exist” when I call array[0] real x_r;.

Any suggestions?

I think for that version you don’t use array syntax. See section 5.5 https://mc-stan.org/docs/2_21/reference-manual-2_21.pdf

Yeah @jd_c is right. This new-ish array syntax wasn’t introduced yet in version 2.21. If you update your rstan to the latest one on CRAN (2.26) then you should be to use this syntax, or if you want to keep using the older rstan you can use the older syntax described in the doc that @jd_c linked to, e.g.

would be

int x_i[0]; 

in the older syntax.

1 Like