RDiBello <- nimbleCode({
# This below code makes sure that this code works for
# both context-BN and non-context BN.
if(is.null(C)){
C = matrix(1,N,K)
}
# Prior Specification
# Prior for student specific guessing parameter
for (i in 1:N){
for(j in 1:J){
g[i,j] ~ dbeta(mean = 0.5, sd = 0.25)
}
}
# Prior for item specific difficulty parameter
for (j in 1:J){
d[j] ~ dbeta(mean = 0.5, sd = 0.25)
}
# Prior for student's abilities
levels[1:2] <- rep(1,2)
lambda[1:2] ~ ddirch(levels[1:2])
for (i in 1:N){
for (k in 1:K){
A[i,k] ~ dcat(lambda[1:2])
}
}
for (i in 1:N){
for (j in 1:J){
# Q-Matrix specifies which skills are required by
# each item to answer them correctly
q_j[1:K] <- nimbleLogical(Q[j,1:K])
eff_ability[i,j] <- min(A[i,q_j[]])
# d is the item specific difficulty parameter
# g is the student specific guess parameter
# effective ability is the combined effect of skills
theta[i,j] <- eff_ability[i,j] + g[i,j] - d[j]
# z[i,j] is the combined effect of the contextual factors,
# effective ability and the difficulty of the item
z[i,j] <- min(c(theta[i,j], C[i,j]))
# taking the logistic inverse
pi[i,j] <- 1/(1+exp(-(1.7* (z[i,j]))))
# Likelihood
X[i,j] ~ dbern(pi[i,j])
}
}
})