我在R JAGS中编写了一个Item响应模型。它基本上是一个具有潜在因素的多重记录模型。
但是我收到以下错误消息:
Error in jags.model(model1.spec, data = list(Y = test, n = nrow(test), :
Error in node Y[1,1]
Node inconsistent with parents
以下是我的型号代码:
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)])
}
}
我的数据是这样的,每个主题有两个测试。每项测试的得分都在1到3之间。
> test
t1 t2
1 2 1
2 3 2
3 2 2
4 2 1
5 2 3
6 1 1
...
提前致谢!