0

I have a list of observed data score and a list of indices ind. Every element of ind is either 0, 1, or 2. score and ind have the same length, and ind partitions score into three sets: if ind[i] is k, then score[i] is in set k.

I would like to fit three normal distributions to the data, one normal for set 0, one normal for set 1, and one normal for set 2. My PyMC3 code to set up the model is:

with pm.Model(): 
    mean = pm.Uniform('mean', 0, 1, shape=3) 
    sd = pm.Uniform('sd', 0, 1, shape=3)
    mean_i = pm.Deterministic('mean_i', mean[ind])
    sd_i = pm.Deterministic('sd_i', sd[ind])
    obs = pm.Normal('obs', mu=mean_i, sd=sd_i, observed=score)

But mean_i seems to have the wrong shape: the traceplots show it to have three elements, rather than just a single element as I expected. And the expression mean[ind] looks wrong: how does PyMC3 know that it should use ind in a way that aligns it with score?

How can I do this?

David Bridgeland
  • 525
  • 1
  • 9
  • 16

1 Answers1

1

You can do this.

with pm.Model(): 
    mean = pm.Uniform('mean', 0, 1, shape=3) 
    sd = pm.Uniform('sd', 0, 1, shape=3)
    obs = pm.Normal('obs', mu=mean[ind], sd=[ind], observed=score)

For future reference you can also ask questions here

aloctavodia
  • 2,040
  • 21
  • 28