# Hierachical Model Specification- Array Issue

**URL:** <https://discourse.mc-stan.org/t/hierachical-model-specification-array-issue/6146>\
**Category:** Modeling\
**Created:** [October 22, 2018, 6:00pm UTC](https://discourse.mc-stan.org/t/hierachical-model-specification-array-issue/6146 "2018-10-22T18:00:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwhittaker1000](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cwhittaker1000/32/13135_2.png) [@cwhittaker1000](https://discourse.mc-stan.org/u/cwhittaker1000)\
**Post date:** [October 22, 2018, 6:00pm UTC](https://discourse.mc-stan.org/t/hierachical-model-specification-array-issue/6146/1 "2018-10-22T18:00:43Z")

</div>

Hi!

I’m currently running into an issue with model specification as part of an ODE system I’m trying to solve- I’m doing the following:

```stan

transformed parameters {
   real params[nStudies, 9];
   real y0[nStudies, 3];
   for(i in 1:nStudies){
     params[i, 1] = epsilon; 
     params[i, 2] = muMF_0;
     params[i, 3] = muW;
     params[i, 4] = foi[i];
     params[i, 5] = muMF_1_max[i];
     params[i, 6] = rho[i];
     params[i, 7] = beta_1_max[i];
     params[i, 8] = lambda[i];
     params[i, 9] = treatment_time;
     y0[i, 1] = fertile_worms_equilibrium(foi[i], muW);
     y0[i, 2] = 0;
     y0[i, 3] = mf_equilibrium(epsilon, y0[1, i], muMF_0);
   }
}

model{
  real y_hat[nStudies, K, 3];
  for(i in 1:nStudies){
    y_hat[i] = integrate_ode_rk45(LoaModel, to_array_1d(y0[i]), t0, time, to_array_1d(params[i]), x_r, x_i);
  }
- some other code underneath-
}

```

And I’m getting this error message:

`stan second argument to integrate_ode_rk45 must have type real[] for intial system state; found type=real[,]. fifth argument to integrate_ode_rk45 must have type real[] for parameters; found type=real[,].`

Does anyone have any idea what’s going on? I was expecting `to_array_1d` to give me `real[]` but evidently not! Any and all help would be massively appreciated!

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [October 23, 2018, 12:57am UTC](https://discourse.mc-stan.org/t/hierachical-model-specification-array-issue/6146/2 "2018-10-23T00:57:21Z")

</div>

It helps if you include your whole program so we can test it.

I’m not sure how you’re getting that result, as the only output types of `to_array_1d` are indeed `real[]` (or `int[]`, but your `y` is `real`).

To solve the problem, you should be able to use just `y0[i]` instead of `to_array_1d` and same for `params[i]`. But it should work as written, which is why I’d like to see the whole program to determine if it’s a parser bug…

Also, you can simplify syntax with:

```
for (i in 1:nStudies) {
  params[i] = { epsilon, muMF_0, ..., treatment_time };
  y0[i] = { fertile_worms_equilibrium( ), 0, mf_equilibrium(...) };
}

```

You might want to just define `params` and `y0` as local variables in the model block—I can’t imagine you want to save `params` in that form.
