通过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个不同的问题。我不确定为什么我的代码会触发错误,以及应该如何纠正它。您能否阐明在不触发错误的情况下运行此代码需要进行哪些调整?

解决方法

数据块中列出的每个参数(JKNjjkky)都需要包含在变量toy_data中。您已经省略了jjkk

您有5位学生(J=5)分别回答4个问题(K=4)。 jj是学生ID,而kk是问题ID,因此,假设您的回答是按学生排序的,然后是按问题排序的,则您会得到类似的信息

jj = c(1,1,2,3,4,5,5)
kk = c(1,4)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...