Hi,

I am trying to fit a type of nominal response IRT model, the details of the model is at this link

Here is a link for the screen shot of the actual model:

This is an extension of Bock’s original nominal response IRT model by including a guessing parameter. I did try my best to write the model syntax, but it seems not accurate. I keep getting error messages. Below is my try to fit this model.

```
data{
int<lower=1, upper=5> K;
int<lower=0> n_student;
int<lower=0> n_item;
int<lower=1,upper=K> Y[n_student,n_item];
}
parameters {
matrix[n_item,K] a2;
matrix[n_item,K] b2;
matrix[n_item,K] c2;
vector[n_student] theta;
}
transformed parameters {
matrix[n_item,K] a;
matrix[n_item,K] b;
matrix[n_item,K] c;
\\ here I am trying to put a constrain such that the a,b, and c are all equal to
\\ 0
\\ for the highest response category, this is how they did in the original paper
for (j in 1:n_item) {
for(k in 1:K){
a[j,k]=a2[j,k]-a2[j,5];
b[j,k]=b2[j,k]-b2[j,5];
c[j,k]=c2[j,k]-c2[j,5];
}
}
}
model{
real P[n_student,n_item,K];
real Pr[n_student,n_item,K];
theta ~ normal(0,1);
for (j in 1: n_item){
for(k in 1:K) {
a2[j,k] ~ uniform(.5,3);
b2[j,k] ~ uniform(-3,3);
c2[j,k] ~ uniform(0,.5);
}
}
for (i in 1:n_student){
for (j in 1:n_item){
for (k in 1:K) {
P[i,j,k] = ((1-c[j,k])*exp(a[j,k]*(theta[i]-b[j,k])))/(1+(c[j,k]*(exp(a[j,k]*(theta[i]-b[j,k])))));
}
for (k in 1:K) {
Pr[i,j,k] = P[i,j,k]/sum(P[i,j,]);
}
Y[i,j] ~ categorical(Pr[i,j,]);
}
}
}
```

Below is the error message:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

No matches for:

real ~ categorical(real[])

Available argument signatures for categorical_logit:

int ~ categorical(vector)

int[] ~ categorical(vector)

require real scalar return type for probability function.

ERROR at line 56

54: }

55:

56: Y[i,j] ~ categorical(Pr[i,j,]);

^

57: }

Error in stanc(file = file, model_code = model_code, model_name = model_name, :

failed to parse Stan model ‘190394253d80ccdcf6735089165b5cde’ due to the above error.

I am also aware that this is not probably the most efficient way as I use so many loops. I saw on other examples that you can vectorize things to reduce the number of loops, but it will take some time for me to understand the Stan language about how arrays work. I also appreciate any help to re-write this more efficiently. I attached a simulated dataset based on this model for your reference.

Thanks all for your time and help.

Cengiz