I’m trying to fit an IRT model for an assessment that measures 3 dimensions total, but each item measures only 1 dimension. The mean and variance of each dimension are fixed to 0 and 1 respectively. However, I would like to estimate the correlations between the three dimensions. Here is the current iteration of my Stan code:
data {
int<lower=0> I; // number of items
int<lower=0> J; // number of students
int<lower=0> D; // number of dimensions
int<lower=0> N; // number of observations
int<lower=0,upper=I> ii; // item for observation n
int<lower=0,upper=J> jj; // student for observation n
int<lower=0,upper=D> dd; // dimension for observation n
int<lower=0,upper=1> y; // score for observation n
}
transformed data {
vector[D] theta_mean;
vector[D] theta_scale;
for (d in 1:D) {
theta_mean[d] = 0;
theta_scale[d] = 1;
}
}
parameters {
matrix[J, D] theta; // student ability
corr_matrix[D] theta_corr; // theta correlation matrix
vector<lower=0>[I] alpha; // discriminations
vector[I] beta; // difficulty
}
model {
vector[N] eta;
// Priors
theta_corr ~ lkj_corr(1);
theta ~ multi_normal(theta_mean, quad_form_diag(theta_corr, theta_scale));
alpha ~ lognormal(0.5, 1);
beta ~ normal(0, 10);
// Likelihood
for (n in 1:N)
eta[n] = alpha[ii[n]] * (theta[jj[n], dd[n]] - beta[ii[n]]);
y ~ bernoulli_logit(eta);
}
However, I get this error when I try to run the model:
No matches for:
matrix ~ multi_normal(vector, matrix)
Available argument signatures for multi_normal:
vector ~ multi_normal(vector, matrix)
vector ~ multi_normal(row vector, matrix)
row vector ~ multi_normal(vector, matrix)
row vector ~ multi_normal(row vector, matrix)
vector ~ multi_normal(vector[], matrix)
vector ~ multi_normal(row vector[], matrix)
row vector ~ multi_normal(vector[], matrix)
row vector ~ multi_normal(row vector[], matrix)
vector[] ~ multi_normal(vector, matrix)
vector[] ~ multi_normal(row vector, matrix)
row vector[] ~ multi_normal(vector, matrix)
row vector[] ~ multi_normal(row vector, matrix)
vector[] ~ multi_normal(vector[], matrix)
vector[] ~ multi_normal(row vector[], matrix)
row vector[] ~ multi_normal(vector[], matrix)
row vector[] ~ multi_normal(row vector[], matrix)
require real scalar return type for probability function.
error in 'modelf1103aa62d17_mirt' at line 32, column 77
-------------------------------------------------
30: // Priors
31: theta_corr ~ lkj_corr(1);
32: theta ~ multi_normal(theta_mean, quad_form_diag(theta_corr, theta_scale));
^
33: alpha ~ lognormal(0.5, 1);
-------------------------------------------------
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'mirt' due to the above error.
So the issue is that theta
can’t be a matrix when defining the multi_normal
prior. However, I do need to be able to access specific elements of theta
in the likelihood (i.e., theta[jj[n], dd[n]]
). I tried following the example model in section 1.13 of the Stan manual, and defining theta
as:
parameters {
vector[D] theta[J];
...
}
This resolves the problem with the multi_normal
prior, but I am then unable to access specific elements of theta
(or at least I haven’t been able to figure it out).
Is there a way to estimate these correlations between dimensions, but also access the elements individually?