# Error evaluating the log probability at the initial value in Ordered Logistic Model

**URL:** <https://discourse.mc-stan.org/t/error-evaluating-the-log-probability-at-the-initial-value-in-ordered-logistic-model/9990>\
**Category:** Modeling\
**Tags:** fitting-issues\
**Created:** [July 31, 2019, 6:05am UTC](https://discourse.mc-stan.org/t/error-evaluating-the-log-probability-at-the-initial-value-in-ordered-logistic-model/9990 "2019-07-31T06:05:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry\_Sebastian\_Rangel\_Qu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/henry_sebastian_rangel_qu/32/5502_2.png) [@Henry\_Sebastian\_Rangel\_Qu](https://discourse.mc-stan.org/u/Henry_Sebastian_Rangel_Qu)\
**Post date:** [July 31, 2019, 6:05am UTC](https://discourse.mc-stan.org/t/error-evaluating-the-log-probability-at-the-initial-value-in-ordered-logistic-model/9990/1 "2019-07-31T06:05:12Z")

</div>

Good night dear Community

I need some help with this code that do not compile.

Problems

Chain 1: Rejecting initial value:  
Chain 1: Error evaluating the log probability at the initial value.  
Chain 1: Exception: ordered\_logistic: Random variable is 4, but must be in the interval [1, 3] (in ‘model104828d26380\_asime’ at line 57)

Chain 1:  
Chain 1: Initialization between (-2, 2) failed after 100 attempts.  
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.  
[1] “Error in sampler$call\_sampler(args\_list[[i]]) : Initialization failed.”  
[1] “error occurred during calling the sampler; sampling not done”

My data are:

List of 8  
famiempresas: int [1:3072] 1 2 3 4 5 6 7 8 9 10 …  
item : int [1:3072] 5 5 5 5 5 5 5 5 5 5 …  
y : int [1:3072] 1 1 1 1 1 1 1 1 1 1 …  
N : int 3072  
N\_fami : int 384  
N\_item : num 8  
N\_cat : num [1:3072] 2 2 3 3 3 3 4 5 2 2 …  
N\_ord\_cat : num [1:3072] 1 2 1 2 3 4 1 1 1 2 …

```stan

data{
  int<lower=1> N; // number of answers
  int<lower=10> N_fami; // number famiempresarios
  int<lower=2> N_item; // number items
  int<lower=2, upper=5>N_cat[N];// number of cut point by item
int<lower=1, upper=4>N_ord_cat[N];// order of cut point by item
  int<lower=1> y[N]; // answers ; y[N], N-th 
  int<lower=1,upper=N_fami> famiempresas[N];// entrepreneur´s answers [N]
  int<lower=1,upper=N_item> item[N]; // number of items [N]
}//end data

parameters{
  vector[N_fami] theta; // latent traits of microempresarios
  ordered[2] beta_1[2];// coefficients of predictors (cut p) for item 1, 2
  ordered[3] beta_2[4];// coefficients of predictors (cut p) for item 3,4,5,6
  ordered[4] beta_3;// coefficients of predictors (cut p) for item 7
  ordered[5] beta_4;// coefficients of predictors (cut p) for item 8
  real mu_beta; // mean of the beta-parameters: difficulty of the item
  real<lower=0> sigma_beta; //sd of the prior distributions of category difficulty
  vector<lower=0>[N_item] alpha;
}//end parameters

model{
  theta ~ skew_normal(0,1, pho_theta);// latent traits
  for(j in 1:N_item){
      alpha[j] ~ normal(0,1); // prior discriminación
  }
  for(j in 1:2){
 beta_1[j]~ normal(mu_beta,sigma_beta);// prior of the item dificultad
  }
  for(j in 1:4){
beta_2[j]~ normal(mu_beta,sigma_beta);// prior of the item dificultad
}

beta_3~ normal(mu_beta,sigma_beta);// prior of the item dificultad
beta_4~ normal(mu_beta,sigma_beta);// prior of the item dificultad
pho_theta ~ normal(0,1); // hyper prior for theta, parámetro de asimétria.
  mu_beta ~ normal(0,2); // hyper prior for mu_beta
  sigma_beta ~ cauchy(0,2); // hyper prior for sigma_beta
  //likelihood
  for(n in 1:N){
if (N_cat[n]==2){ 
   y[n] ~ ordered_logistic(alpha[item[n]]*theta[famiempresas[n]],beta_1[N_ord_cat[n]]);
  }
if (N_cat[n]==3){
   y[n] ~ ordered_logistic(alpha[item[n]]*theta[famiempresas[n]],beta_2[N_ord_cat[n]]);
  }
if (N_cat[n]==4){
   y[n] ~ ordered_logistic(alpha[item[n]]*theta[famiempresas[n]],beta_3);
  }
if (N_cat[n]==5){
   y[n] ~ ordered_logistic(alpha[item[n]]*theta[famiempresas[n]],beta_4);
  }

}
}//end model

```

* * *

The model

P[u\_{ij}=g|\theta\_j,\xi]=logit^{-1} (\eta\_{g-1})- logit^{-1} (\eta\_{g}) where, logit^{-1}(\eta\_{g-1})= (1+e^{-\eta\_{g-1}})^{-1}, \eta\_{g\_{-1}}=(\alpha\_i\*\theta\_j-\alpha\_i\*\beta\_{i,g-1}) and logit^{-1}{(\eta\_g)= (1+e^{-\eta\_g})^{-1}} \eta\_g=(\alpha\_i\*\theta\_j-\alpha\_i\*\beta\_{i,g}).  
 P[u\_{ij}=g|\theta\_j,\xi]= \left\{ \begin{array}{lcc} 1-(1+e^{-\eta\_{1}})^{-1} & si & g=1 \\ (1+e^{-\eta\_{g-1}})^{-1}-(1+e^{-\eta\_g})^{-1}& si & 1 \< g \< k \\ (1+e^{-\eta\_{k-1}})^{-1} & si & g = k-1 \end{array} \right.  
\theta\_j \sim SN(0, 1, \rho), \nonumber\\ \rho \sim N(0,1),\nonumber \\ \nonumber \alpha\_i \sim N(0,1),\\ \nonumber \beta\_{ig}\sim N(\mu\_{beta\_{ig}},\sigma\_{beta\_{ig}}),\\ \nonumber \mu\_{beta}\sim N (0,1),\\ \nonumber \sigma\_{beta}\sim Cauchy (0,2)

I will appreciate your help,

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [July 31, 2019, 7:29am UTC](https://discourse.mc-stan.org/t/error-evaluating-the-log-probability-at-the-initial-value-in-ordered-logistic-model/9990/2 "2019-07-31T07:29:56Z")

</div>

The first error to look at is this one:

> Chain 1: Exception: ordered\_logistic: Random variable is 4, but must be in the interval [1, 3] (in ‘model104828d26380\_asime’ at line 57)

This error message is saying that when `N_cat[n] == 2`, the corresponding `y[n]` can only be 1, 2, or 3 (i.e. two cutpoints implies three categories) but the `y[n]` being provided is a 4.

You should check your data to make sure that the right `N_cat` is associated with the right `y`

---

<div class="post-metadata">

**Author:** ![Henry\_Sebastian\_Rangel\_Qu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/henry_sebastian_rangel_qu/32/5502_2.png) [@Henry\_Sebastian\_Rangel\_Qu](https://discourse.mc-stan.org/u/Henry_Sebastian_Rangel_Qu)\
**Post date:** [July 31, 2019, 9:05pm UTC](https://discourse.mc-stan.org/t/error-evaluating-the-log-probability-at-the-initial-value-in-ordered-logistic-model/9990/3 "2019-07-31T21:05:55Z")

</div>

Thank you so much.
