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

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 …


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_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)

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

1 Like

Thank you so much.