Graded response model in Stan with varying item response categories

Please share your Stan program and accompanying data if possible.
My code is specified as below. Actually here the K(number of categories for each item) is varying, says item 1 and 2 are dichotomous with 2 categories, item 3 and 4 are polytomous with 4 categories. So my K in the input data actually is a vector, says c(2, 2, 4, 4); however, in the parameter block, where the line ordered[K-1] ka[n_item] reports an error says the K in the <> should be integer instead of vector. Is there any way to solve this problem? Additionally, is there any changes necessary for the model block? Thank you so much if you could share any thoughts!


data {
int <lower=0> n_person; // number of persons
int <lower=0> n_item; // number of items
int <lower=2> K; //number of categories for each item
int <lower=1,upper=K> Y[n_person,n_item]; // where number in the braket needs to be integer only!
}
parameters {
vector[n_person] kai ; // latent trait
real <lower=0> alpha [n_item] ; // slope
ordered[K-1] ka[n_item]; //item category intercept
}
model{
kai ~ normal(0,1);
alpha~ lognormal(0,1);
for (j in 1:n_item){
for (k in 1:(K-1)){
ka[j,k]~normal(0,1);
}
}
for (i in 1:n_person){
for (j in 1:n_item){
Y[i,j]~ordered_logistic(kai[i]*alpha[j],ka[j]);
}
}
}

To make a variable that contains multiple integers, you have to use the array syntax rather than the vector syntax:

int <lower=2> K[n_item] ;

Thank you for this suggestion, but when you try this syntax, then K has length more than 1, then you’ll see a error reminds you “expression denoting integer required”, which means the expression in <lower=1,upper=K > need to be integer only instead of vector or array.

You can just omit the constraints in that case:

 int Y[n_person,n_item];