JAGS model with error “Node inconsistent with parents”

谁都会走 提交于 2019-12-25 09:28:08

问题


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!

来源:https://stackoverflow.com/questions/43216398/jags-model-with-error-node-inconsistent-with-parents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!