I am new in Stan and I’m starting my studies in Item Response Theory (IRT). My interest is to write IRT code, at the moment I am trying to adapt the “Generalized partial credit model”

P(Y_{j,i}=k|\theta_j)=\frac{exp\{\sum_{l=1}^{k}\alpha_i(\theta_j-\beta_{i,l})\}}{\sum_{m=1}^{K}exp\{\sum_{l=1}^{m}\alpha_i(\theta_j-\beta_{i,l})\}}

The code is inspired by a code of BUGS that is in the following journal (pages 10 and 11)

After several attempts I got this model below.

data{

int <lower=1> n; // number of people

int <lower=1> p; // number of items

int <lower=2,upper=5> K; //number of categories

int <lower=1,upper=K> Y[n,p]; // data base

}

parameters {

vector[n] teta;

vector <lower=0>[p] alfa;

ordered[K-1] beta[p]; //difficulty

real m_beta; //prior to the beta average

real <lower=0> s_beta; //priori of the standard deviation of beta

}

model{

alfa~cauchy(0,5);

teta~normal(0,1);

m_beta~normal(0,5);

s_beta~cauchy(0,5);

for (i in 1: p){

for (k in 1:(K-1)){

beta[i,k] ~ normal(m_beta,s_beta);

}}

for(j in 1:n){

for(i in 1:p){

for(k in 1:(K-1)){

real soma; //created variable

real exp_soma; //created variable

real exp_soma2;//created variable

soma=soma+(alfa[i]*(teta[j]-beta[i,k]));

exp_soma=exp(soma);

exp_soma2=exp_soma2+exp_soma;

Y[j,i]~ordered_logistic(exp_soma/exp_soma2,beta[i]);

}

}

}

}

I do not know if it makes sense or if it is very wrong, in the end it tells me that it has the following error.

Chain 1: Rejecting initial value:

Chain 1: Error evaluating the log probability at the initial value.

Chain 1: Exception: ordered_logistic: Location parameter is nan, but must be finite! (in ‘model1a787417cb86_GPCM2’ at line 36)

I know the error is in the estimation function but I do not know how to solve it.

Tks