Hierarchical graded IRT

The problem is not ordered_logistic_xxx but rather that you are trying to multiple a real array with a vector. This is not allowed, because this can correspond to several different operations, so you need to be explicit. If you want element-wise multiplication, you need to use the .* operator. If you want the inner/outer product, you need to have a vector and row_vector as operators (you can either change the type in the signature or use to_vector / to_row_vector).

There are a couple things to learn from the fact that sum(theta) ~ normal(0, 0.0001); poses problems while mean(theta) ~ normal(0, 0.001); does not. Generally this form of soft sum-to-zero constraint can induce problematic posterior geometry as you have one more parameter than strictly needed and your posterior concentrates around a hyperplane in the full space. Such problems get more pronoucned the tighter the constraint is. The second constraint is much more permissive and hence probably avoids some of the pathologies, but it is also more likely the results actually violate the constraint substantially (easy to check, just look at the value of sum(theta) for each posterior sample). If you can live with this imprecision, then definitely no need to change your model.

If however the constraint is too permissible, then the best way would likely be to parametrize the model in a way that sum(theta) == 0, or at least sum(X * gamma) == 0 holds by cosntruction.

An outline of how one could construct such gamma and theta. Notably, sum(X * gamma) == 0 defines a K - 1 dimensional space (the kernel of sum(X * gamma), treated as a map from R^K to R), so for any given X you should be able to find a matrix B representing a suitable basis such that you can have:

transformed data {
   matrix[K, K - 1] B = //some linear algebra I am too lazy to figure out
}

parameters {
  vector[K - 1] gamma_raw;
  ...
}

transformed parameters {
  vector[K] gamma = B * gamma_raw;
}

and have sum(X * gamma) == 0 for any value of gamma_raw. Now we can have theta = X * gamma + theta_z where sum(theta_z) == 0 and you could likely gain some efficiency by constraining theta_z with the usually more efficient sum-to-zero constraint described at Test: Soft vs Hard sum-to-zero constrain + choosing the right prior for soft constrain - #31 by andre.pfeuffer .

Hope that clarifies more then confuses

1 Like