Hello Stan users

I am a very new user of Stan. Any comments would be absolutely helpful.

I tried to fit Rasch mixture item response theory model, for only one item for simplicity, with the help of “Finite Mixture Model” section on Stan reference 2.17.0. However, the following error is displayed

(Error in stanc(file = file, model_code = model_code, model_name = model_name, :

c++ exception (unknown reason))

I know there are errors somewhere in my Stan code but could not figure them out.

Here is my code:

data {

int<lower=1> K; // number of mixture components

int<lower=1> N; // number of examinees

int<lower=0,upper=1> y[N]; // observations for one item only

}

parameters {

simplex[K] pi; // mixing proportions

vector[N] theta ; // ability of each examinee i

}

model {

theta ~ normal(mu[k],1) ;

for (k in 1:K){

mu[1] ~ normal(0, 1) ;

mu[2] ~ normal(1, 1) ; // to avoid label switching problem

pi ~ Dirichlet(0.5,0.5) ;

}

real log_pi[k]=log(pi) ;

for (i in 1:N){

real p; //create a local variable within the loop

p= inv_logit(theta[i])); // with b=0 for the item

y ~ bernoulli( p ) ;

real lps[K]=log_pi;

for (k in 1:K) {

lps[k] += (y[i]*log( p )+(1-y[i])*log(1-p)) ;

target += log_sum_exp(lps);

}}

}

Fitting the model in R :

library(rstan)

K=2

N=10

y = c(1,1,1,0,0,1,1,0,0,0)

data=list(K,N,y)

fit = stan(file = ‘rasch.stan’ ,data=data, iter = 2, chains = 1)

print(fit)