Hi Dear stan users , The code as follows are my stan code for a MIRT model, and I could use this stan code to fit the mirt model where each item measures D dimension. but I want to amend the follow code to estimate a MIRT model where each item measures only one dimension.
I was wondering if I could set two dimensional alpha estimates in rstan code like the following which means I fixed some alpha value to zero using rstan code.
alpha
[,1] [,2]
[1,] 1.925 0.000
[2,] 1.914 0.000
[3,] 0.763 0.000
[4,] 1.273 0.000
[5,] 0.992 0.000
[6,] 2.069 0.000
[7,] 1.812 0.000
[8,] 1.064 0.000
[9,] 0.539 0.000
[10,] 0.955 0.000
[11,] 0.000 1.075
[12,] 0.000 0.511
[13,] 0.000 0.705
[14,] 0.000 1.526
[15,] 0.000 2.237
[16,] 0.000 0.691
[17,] 0.000 1.313
[18,] 0.000 0.707
[19,] 0.000 1.111
[20,] 0.000 0.633
Please give me some advice if you know something about MIRT model, I will appreciate it.
@ wjakethompson
@ p-gw
@ rjc10
// M3PL-parameter estimated with stan
data {
int<lower=1> n_stu; // the number of students
int<lower=1> n_itm; // the number of items
int<lower=0,upper=1> Y[n_stu, n_itm]; // the response score
int<lower=1> D; // the number of dimensions
}
transformed data {
row_vector [D] mu_theta = rep_row_vector(0, D);
cov_matrix [D] Sigma;
Sigma = rep_matrix(0, D, D);
for(i in 1:D){
Sigma[i,i] = 1;
}
}
parameters {
vector [D] theta [n_stu];
matrix<lower=0>[n_itm,D] alpha;
vector<lower=-3,upper=3>[n_itm] beta;
vector<lower=0,upper=0.5>[n_itm] gamma;
}
model {
for(i in 1:n_stu){
theta[i] ~ multi_normal(mu_theta, Sigma);
}
beta ~ normal(0,1);
to_vector(alpha) ~ lognormal(0, 0.5);
gamma ~ beta(2,5);
for(j in 1:n_itm){
for(i in 1:n_stu){
real p;
p = inv_logit(1.7*(row(alpha,j)*theta[i]+beta[j]));
Y[i,j] ~ bernoulli(gamma[j]+(1-gamma[j])*p);
}
}
}
generated quantities { // computate the modelbased log-likelihood for loo and WAIC
vector[n_itm] log_lik[n_stu];
vector[n_itm] pY[n_stu];
for(j in 1:n_itm){
for(i in 1:n_stu){
pY[i,j] = gamma[j]+(1-gamma[j])*inv_logit(1.7*(row(alpha,j)*theta[i]+beta[j]));
log_lik[i,j] = bernoulli_lpmf(Y[i,j] | pY[i,j]);
}
}
}