I was just using the toy example from junpenglao’s response to the original question:
# data
K = 5 # number of items being ranked
J = 20 # number of raters
yreal = np.argsort(np.random.randn(K, 1), axis=0)
print(yreal)
y = np.argsort(yreal + np.random.randn(K, J), axis=0)
print(y)
# transformed data{
y_argsort = np.argsort(y, axis=0)
with pm.Model():
mu_hat = pm.Normal('mu_hat', 0, 1, shape=K-1)
# set first value to 0 to avoid unidentified model
mu = tt.concatenate([[0.], mu_hat])
#sd = pm.HalfCauchy('sigma', 1.)
latent = pm.Normal('latent',
mu=mu[y_argsort],
sd=1., # using sd does not work yet
transform=Ordered2D(),
shape=(K,J),
testval=np.repeat(np.arange(K)[:,None], J, axis=1))
# There are some problems with Ordered
# right now, you need to give a testval
trace = pm.sample()
I had never looked at the default ordered and assumed that junpenglao wrote a 2D version because it only works on 1D arrays. I switched the dimensions around to put the one that should be ordered last, and it does seem to work with the default ordered distribution, thanks! Not sure then why this 2D version was needed. Maybe things have changed since 2017
.