Model Comparison: How to constrain a model to positive mu-differences?

Yes

It wouldn’t as you dont have parameter related to each trial - this is essentially what IID data or repeat measurement means. Maybe it is clearer in code:

data1 = np.random.normal(loc=0., scale=1., size=10)
data2 = np.random.normal(loc=10., scale=5., size=10)
data_all = np.concatenate([data1, data2], axis=0)
sbj_idx = np.concatenate([np.zeros(10), np.ones(10)], axis=0).astype(int)

with pm.Model() as model1:
  mu = pm.Normal('mu', 0., 10., shape=2)
  sigma = pm.HalfNormal('sigma', 5., shape=2)
  obs = pm.Normal('obs', mu, sigma, observed=np.stack([data1, data2]).T)

with pm.Model() as model2:
  mu = pm.Normal('mu', 0., 10., shape=2)
  sigma = pm.HalfNormal('sigma', 5., shape=2)
  obs = pm.Normal('obs', mu[sbj_idx], sigma[sbj_idx], observed=data_all)

model1 and model2 are identical but model2 is much more flexible as it allows different length of data among subjects.

4 Likes