这是一个混合IRT模型参数估计(MCMC估计)的程序,但是其中有误,求各位高手指点迷津。能够解围的,悬赏500论坛币。
# 2 student-level class (G) with prior
# 2 school-level class (K)with prior
# J: the number of students
# I: the number of items
# T: the number of schools
# g: group (i.e. student) membership at the student-level
# gg (k): group (i.e., school) membership at the school-level
# a: the SD of ability
# b: item difficulty
# eta: ability
# mutg: the mean of ability
model
{
for (j in 1:J) {
for (i in 1:I) {
r[j,i] <- resp[j,i]
}}
# G¼2
for (j in 1:J) {
for (i in 1:I) {
logit(p[j,i]) <- a[g[j], gg[group[j]]] *eta[j]
- b[i,g[j],gg[group[j]]]
r[j,i]*dbern(p[j,i])
}}
# Ability
for (j in 1:J) {
eta[j]*dnorm(mutg[g[j],gg[group[j]]], 1)
}
mutg[1,1] <- 0
mutg[2,1] * dnorm(0,1)
mutg[1,2] * dnorm(0,1)
mutg[2,2] * dnorm(0,1)
# SD of Ability
for (g in 1:G2) {
for (k in 1:K2){
a[g, k] * dnorm(0,1) I(0,)
}}
# Student Level
for (j in 1:N) {
g[j] * dcat(pi[gg[group[j]],1:G2])
}
for (k in 1:K2) {
for (g in 1:G2) {
pi[k,g] <- delta[k,g] /sum(delta[k,])
delta[k,g] * dgamma(alpha[g],1)
}
}
# School Level
for (t in 1:T){
gg[t] * dcat(pi1[1:K2])
}
for (k in 1:K2) {
pi1[k] <- delta1[k]/sum(delta1[1:K2])
delta1[k] * dgamma(alpha1[k],1)
}
# Item Difficulty
for (i in 1:T) {
for (g in 1:G2) {
for (k in 1:K2){
b[i,g,k]*dnorm(0,1)
}}}
# Log-Likelihood
for (j in 1:J) {
for (i in 1:I) {
l[j,i]<-log(p[j,i])*r[j,i]þlog(1-p[j,i])*(1-r[j,i])
}}
loglik <-sum(l[1:J,1:I])
AIC <- -2*(loglik - np)
BIC <- -2*loglik þ np*log(N)
}
# Initial Value of School-Level Group Membership
list(gg¼c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
. . .
1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2))
# Input Data
# 25 students
list(J¼8000, I¼40, T¼320, G2¼2, K2¼2, np¼169, alpha¼c(1,1),
alpha1¼c(1,1),
group¼c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3...),
resp¼structure(.Data¼c(
1.0,1.0,1.0,1.0,1.0,
. . .
1.0,0.0,0.0,0.0,0.0),.Dim ¼ c(8000,40)))