I have written an Item response model in R JAGS. It is basically a multilogit model with latent factors.
But I received the following error message:
Error in jags.model(model1.spec, data = list(Y = test, n = nrow(test), :
Error in node Y[1,1]
Node inconsistent with parents
Here are my model code:
model{
# Subject i
for (i in 1:n){
# Test j; test j has K[j] possible scores
for (j in 1:p){
Y[i,j]~dcat(prob[i,j,1:K[j]])
}
# Underlying patient ability
theta[i]~dnorm(0,1)
for (j in 1:p){
for (k in 1:(K[j]-1)){
eta[i,j,k]=d[j,k]-alpha[j]*theta[i]
exp.eta[i,j,k]=exp(eta[i,j,k])
# Probability for subject i to at most score K[k] in item j
P[i,j,k]=exp.eta[i,j,k]/(1+exp.eta[i,j,k])
}
P[i,j,K[j]]=1
}
for (j in 1:p){
prob[i,j,1]=P[i,j,1]
for (k in 2:K[j]){
# Probability of subject i to score K[k] for item j
prob[i,j,k]=P[i,j,k]-P[i,j,k-1]
}
}
}
for (j in 1:p){
alpha[j]=1
}
## The d parameters have to be increasing from lowest category to highest for each item
for (j in 1:p){
for (k in 1:(K[j]-1)){
d.star[j,k]~dnorm(0,0.0001)
}
d[j,1:(K[j]-1)]=sort(d.star[j,1:(K[j]-1)])
}
}
My data is like this with two tests per subject. Each test takes the score between 1 to 3.
> test
t1 t2
1 2 1
2 3 2
3 2 2
4 2 1
5 2 3
6 1 1
...
Thanks in advance!