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

**URL:** <https://discourse.mc-stan.org/t/problem-setting-initial-values-stan-seems-to-do-not-respect-them/4221>\
**Category:** Modeling\
**Created:** [May 16, 2018, 11:55pm UTC](https://discourse.mc-stan.org/t/problem-setting-initial-values-stan-seems-to-do-not-respect-them/4221 "2018-05-16T23:55:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmorenozam](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mmorenozam/32/480_2.png) [@mmorenozam](https://discourse.mc-stan.org/u/mmorenozam)\
**Post date:** [May 16, 2018, 11:55pm UTC](https://discourse.mc-stan.org/t/problem-setting-initial-values-stan-seems-to-do-not-respect-them/4221/1 "2018-05-16T23:55:47Z")

</div>

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

```

```stan
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):

```stan
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)

[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
[2] "In addition: Warning messages:"                                        
[3] "1: package 'rstan' was built under R version 3.4.4 "                   
[4] "2: package 'StanHeaders' was built under R version 3.4.4 "             
[1] "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](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/9/9e202f4977d3d828336f9502881b795158354fbb.R) (2.6 KB)  
[m3.stan](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/a/a611f04c5fd877cee734673d257d497775d4846c.stan) (3.2 KB)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 17, 2018, 12:38am UTC](https://discourse.mc-stan.org/t/problem-setting-initial-values-stan-seems-to-do-not-respect-them/4221/2 "2018-05-17T00:38:22Z")

</div>

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