Error when setting initial values: dims declared=(1); dims found=()

I am using rstan with the initial values declared as follows:

list(list(lm0  = c(308,320.5,331.5,342,349.5),
          p0  = c(0.125,0.25,0.25,0.25,0.125),
          pd  = c(0.125,0.25,0.25,0.25,0.125),
          b0  = rep(0,k), bd = rep(0,k),
          r0  = rep(0,k-1), rd = rep(0,k-1),
          error = 1)) -> init

In the particular case when k = 2, parameters r0 and rd should be of length one, but instead Stan seems thinks to think they’re empty. It identifies the correct dimensions for any values above 1.

Not sure if the whole model is relevant, pasting data and parameters below:

data {
  int<lower=0> n;   // n# observaciones
  int<lower=2> k;  
  vector[n] I; 
  vector[n] v;      
  vector[n] d;     
  int pep[n];      
  vector[5] lm0; 
  vector[5] s0;   
parameters {
  ordered[5] lm;

  simplex[5] pf; 
  simplex[5] pu;
  simplex[5] pr[k-1]; 

  real b0[k]; 
  real bd[k]; 

  real r0[k-1]; 
  real rd[k-1]; 

  real<lower=0> error;
1 Like

For b0, etc. you would need to wrap them inside an as.array in the initial values, but you shouldn’t need to specify initial values.

1 Like

Also, the problem would be avoided if you used a vector rather than a one-dimensional real array (which has no benefit over a vector and cannot be used for matrix algebra).

1 Like

Understood. Thank you. Why do you advise against initial values on those parameters though? Is it because you (correctly) guessed they represent intercepts or is it a more general thing?

If initial values are necessary in Stan, then the model probably needs to be rescaled or recentered anyway to work efficiently.

1 Like