"Expected non-array type after "array" declaration" error in ODE solver of Cmdstanr with missing data

I am trying to run a Measurement error model using CmdStan’s ode_rk45 solver. The data set has T rows and 3 columns, only the first column’s data is available. But the initial condition is available for all 3 columns (this is specified as the init vector in the data block). As I have done before with Bayesian Hierarchical Models while using rstan with missing data, I tried the same “tweaking” here as well—using the transformed parameters block.

But, while I am trying to do this, I am getting this error saying: “Expected non-array type after “array” declaration.”

   -------------------------------------------------
    51:  transformed parameters {
    52:    array[T] vector[3] y;
    53:    array[T] y[1] = C;
                    ^
    54:    array[T] y[2] = T_mis;
    55:    array[T] y[3] = I_mis;
   -------------------------------------------------

Expected non-array type after "array" declaration.

make: *** [/var/folders/p6/r39tc8jj7k1023t1rk9hgtpc0000gn/T/RtmpLgFoGl/model-99e3c24fcbf.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

Here is the code blocks pertaining to the error:

data {
  int<lower=1> T;
  array[T] vector[1] C;
  real t0;
  array[T] real<lower=1> ts;
  vector[3] init;
}

parameters {
  array[T] vector[1] T_mis;
  array[T] vector[1] I_mis;
  vector<lower=0>[3] sigma;
}

transformed parameters {
  array[T] vector[3] y;
  array[T] y[1] = C;
  array[T] y[2] = T_mis;
  array[T] y[3] = I_mis;
}

Any help on how to fix this error will be highly appreciated! Thank you all in advance!

You only have to include the type when you first declare an object, afterwards you just use the object name:

array[T] vector[3] y;
y[1] = C;
1 Like

Hello,

Thank you so much for taking your time to look into this. I actually already tried that too. Gives a different type of error. Here is that error message, when I incorporate your suggestion;

   -------------------------------------------------
    51:  transformed parameters {
    52:    array[T] vector[3] y;
    53:    y[1] = C;
           ^
    54:    y[2] = T_mis;
    55:    y[3] = I_mis;
   -------------------------------------------------

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

make: *** [/var/folders/p6/r39tc8jj7k1023t1rk9hgtpc0000gn/T/RtmpLgFoGl/model-99e6d4621eb.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

Any thoughts on this?

The error says:

lhs has type vector and rhs has type array[] vector

Which means that C is an array of vectors but y[1] is a single vector, so Stan doesn’t know how to assign

1 Like

Thank you so much! I made appropriate changes, and that above error is now fixed.

But, I am running into a strange error while sampling from the model. I will try to give the model and the error after doing some more research. Thank you so much again!