# Poisson Distribution always return erros

**URL:** <https://discourse.mc-stan.org/t/poisson-distribution-always-return-erros/12727>\
**Category:** Modeling\
**Created:** [January 20, 2020, 10:08pm UTC](https://discourse.mc-stan.org/t/poisson-distribution-always-return-erros/12727 "2020-01-20T22:08:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hailstan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/hailstan/32/6913_2.png) [@hailstan](https://discourse.mc-stan.org/u/hailstan)\
**Post date:** [January 20, 2020, 10:08pm UTC](https://discourse.mc-stan.org/t/poisson-distribution-always-return-erros/12727/1 "2020-01-20T22:08:14Z")

</div>

my code in pystan

```no-highlight
vv=range(0,10)
my_code = """
data {
    int<lower=0> J; // number of datas
    vector[J] value; // observed values

}
parameters {
    //Arrival rate coefs
    real<lower=1,upper=10> th11;

    //jump dist params
    
    real<lower=1> sigma;
}

model {

    int ku[J];
    for (i in 1:J)
        ku[i] ~ poisson(th11);

    
    for (i in 1:J)
        value[i] ~ normal(ku[i], sigma);
}
"""

schools_dat = {'J': 10,
               'value':vv}

sm = pystan.StanModel(model_code=my_code)
fit = sm.sampling(data=schools_dat, iter=1000, chains=1)

```

this code always returns same error:

> Rejecting initial value:  
> Error evaluating the log probability at the initial value.  
> Exception: poisson\_lpmf: Random variable is -2147483648, but must be \>= 0! (in ‘unknown file name’ at line 22)
> 
> Initialization between (-2, 2) failed after 100 attempts.

how to avoid this?

---

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [January 20, 2020, 10:23pm UTC](https://discourse.mc-stan.org/t/poisson-distribution-always-return-erros/12727/2 "2020-01-20T22:23:13Z")

</div>

Hi! :)

> [@hailstan](#):
>
> int ku[J]; for (i in 1:J) ku[i] ~ poisson(th11);

This is not allowed in Stan. The tilde `~` doesn’t “sample” from a distribution, but rather adds the data/parameter on the left hand side to the target function with the log distribution function thats on the right hand side (with given parameters). Basically, it is `target += lpmf(ku[i], th11)`, and since `ku` doesn’t have a value, it throws an error.

Unfortunately, this is not the only problem with the model (at least for Stan): You can not have integer parameters in Stan (or any HMC or gradient based MCMC sample).

You’d have to marginalize over all the discreet parameters in your model, which can be a bit painful to do here… Sorry, for not being very helpful… :/
