# Problem setting initial values, Stan seems to do not respect them

I am working with an ODE model where I need to constraint the time series to be greater or equal than zero. To avoid crashes of possible negative values during initialization, I tried to feed Stan with a list of initial values for the four chains that I plan to run, using a function like this:

``````indent preformatted text by 4 spaces
``````
``````ini = function(){
list(mu1=abs(rnorm(1,0.5,0.2)),
mu2=abs(rnorm(1,0.5,0.2)),mu3=abs(rnorm(1,0.5,0.2)),mu4=abs(rnorm(1,0.5,0.2)),mu5=abs(rnorm(1,0.5,0.2)),
ks1=abs(rnorm(1,0.5,0.2)),ks2=abs(rnorm(1,0.5,0.2)),ks3=abs(rnorm(1,0.5,0.2)),ks4=abs(rnorm(1,0.5,0.2)),ks5=abs(rnorm(1,0.5,0.2)),
k1=abs(rnorm(1,0.5,0.2)),k2=abs(rnorm(1,0.5,0.2)),k3=abs(rnorm(1,0.5,0.2)),yc1=abs(rnorm(1,0.5,0.2)),yc2=abs(rnorm(1,0.5,0.2)),
yc3=abs(rnorm(1,0.5,0.2)),yc4=abs(rnorm(1,0.5,0.2)),yc5=abs(rnorm(1,0.5,0.2)),yc6=abs(rnorm(1,0.5,0.2)),yc7=abs(rnorm(1,0.5,0.2)),
yc8=abs(rnorm(1,0.5,0.2)),yc9=abs(rnorm(1,0.5,0.2)),yc10=abs(rnorm(1,0.5,0.2)),yc11=abs(rnorm(1,0.5,0.2)),sigma=abs(rnorm(1,0.5,0.2)),
x_hat=structure(abs(rnorm(T*length(x0),0.5,0.1)),.Dim=c(13,8)))
}
``````

From what I know, this is supposed to assign the same initial values to each of the chains. However, I always get the following kind of error (in Windows and Linux machines):

``````SAMPLING FOR MODEL 'm3' NOW (CHAIN 1).
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: validate transformed params: x_hat[k0__][k1__] is -0.000102274, but must be greater than or equal to 0  (in 'model34107e7ba11_m3' at line 74)

 "Error in sampler\$call_sampler(args_list[[i]]) : Initialization failed."
 "1: package 'rstan' was built under R version 3.4.4 "
 "2: package 'StanHeaders' was built under R version 3.4.4 "
 "error occurred during calling the sampler; sampling not done"
``````

So, even thought I am setting positive initial values, Stan seems to do not care, and assigns random values as I hadn’t specify any.

Does anyone has a clue of what is wrong?

PS. I get the same error even when specifying “0” at the `init` statement when calling Stan.

box2_m3.tt.R (2.6 KB)
m3.stan (3.2 KB)

The error message refers to `x_hat` in the `transformed parameters` block, which is not strictly non-negative at least not numerically.