如何解决通过R编程的STAN IRT,是否存在参数声明问题?
我正在跟带STAN tutorial的官方IRT一起关注。该模型的详细信息复制如下:
data {
int<lower=1> J; // number of students
int<lower=1> K; // number of questions
int<lower=1> N; // number of observations
int<lower=1,upper=J> jj[N]; // student for observation n
int<lower=1,upper=K> kk[N]; // question for observation n
int<lower=0,upper=1> y[N]; // correctness for observation n
}
parameters {
real delta; // mean student ability
real alpha[J]; // ability of student j - mean ability
real beta[K]; // difficulty of question k
}
model {
alpha ~ std_normal(); // informative true prior
beta ~ std_normal(); // informative true prior
delta ~ normal(0.75,1); // informative true prior
for (n in 1:N)
y[n] ~ bernoulli_logit(alpha[jj[n]] - beta[kk[n]] + delta);
}
我不确定哪些变量需要在R代码中声明。
toy_data <- list(
J= 5,K = 4,N =20,y= c(1,1,0)
)
fit <- stan(file = '1PL_stan.stan',data = toy_data)
但是,会触发以下错误。
Error in mod$fit_ptr() :
Exception: variable does not exist; processing stage=data initialization; variable name=jj; base type=int (in 'model920c4330dff_1PL_stan' at line 5)
In addition: Warning messages:
1: In readLines(file,warn = TRUE) :
incomplete final line found on 'C:\Users\jacob.moore\Downloads\1PL_stan.stan'
2: In system(paste(CXX,ARGS),ignore.stdout = TRUE,ignore.stderr = TRUE) :
'-E' not found
Failed to create the sampler; sampling not done
在过去的工作中,我几乎只使用python。因此,学习R一直是学习曲线。另外,我是STAN的新手,因此是玩具示例。
核心思想是有20个孩子/问题配对。 5个孩子和4个不同的问题。我不确定为什么我的代码会触发错误,以及应该如何纠正它。您能否阐明在不触发错误的情况下运行此代码需要进行哪些调整?
解决方法
数据块中列出的每个参数(J
,K
,N
,jj
,kk
和y
)都需要包含在变量toy_data
中。您已经省略了jj
和kk
。
您有5位学生(J=5
)分别回答4个问题(K=4
)。 jj
是学生ID,而kk
是问题ID,因此,假设您的回答是按学生排序的,然后是按问题排序的,则您会得到类似的信息
jj = c(1,1,2,3,4,5,5)
kk = c(1,4)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。